GCC error unqualified-id before '(' - gcc

While i'm trying to build gcc itself. İ faced with this strange error.
error was on aarch64.h
and also, i edited header code a bit before compilation
original header code:
#define PROFILE_HOOK(LABEL) \
{ \
rtx fun, lr; \
lr = get_hard_reg_initial_val (Pmode, LR_REGNUM); \
fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_NAME); \
emit_library_call (fun, LCT_NORMAL, VOIDmode, 1, lr, Pmode); \
}
İ changed it to:
#define PROFILE_HOOK(LABEL) \
{ \
rtx fun, lr; \
if (!flag_fentry)
{ //error: expected unqualified-id before.. this line**************
lr = get_hard_reg_initial_val (Pmode, LR_REGNUM); \
fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_NAME); \
emit_library_call (fun, LCT_NORMAL, VOIDmode, 1, lr, Pmode); \
} //error: expected unqualified-id before.... this line*************
}
and also i dont know if it makes any difference(color change) but before editing code, whole code looks purple. after editing code, lines below if (!flag_fentry) turned to black
im struggling with it for two days with no success
i really appreciate it if anyone help me.
thanx
regards

Related

wait_event and lock interaction

I'm new to linux kernel development and wonder how wait_event/wait_event_interruptible interacts with other locking primitives in the kernel. I'm used to C++ std::condition_variable::wait and want to achieve something similar in the kernel.
I have a queue of receive buffers which are filled using DMA transfers. The list is protected using a spin lock. Finished buffers are added by the DMA finished soft IRQ. I created a character device which allows reading of the finished buffers. So far this works as expected but I want to support blocking reads.
I've read about wait_event which seems like what I want, but I'm really confused how wait_event does not take any lock/mutex parameter. How is evaluating the condition without holding a lock safe? I suppose I can add the necessary locking to my condition, but then I need to lock again once wait_event returns to extract the data. Is this already a case for prepare_to_wait/schedule/finish_wait?
Without digging to much into the source first I will say you should be using the wait_event library and you do not need mutex's or other such things the kernel is taking care of them. Personally I only have experience with wait_event_interruptible and wake_up_interruptible but I suspect they all are similar.
Now onto the source which I am pulling from https://elixir.bootlin.com/linux/latest/source/include/linux/wait.h#L302
#define ___wait_event(wq_head, condition, state, exclusive, ret, cmd) \
({ \
__label__ __out; \
struct wait_queue_entry __wq_entry; \
long __ret = ret; /* explicit shadow */ \
\
init_wait_entry(&__wq_entry, exclusive ? WQ_FLAG_EXCLUSIVE : 0); \
for (;;) { \
long __int = prepare_to_wait_event(&wq_head, &__wq_entry, state);\
\
if (condition) \
break; \
\
if (___wait_is_interruptible(state) && __int) { \
__ret = __int; \
goto __out; \
} \
\
cmd; \
} \
finish_wait(&wq_head, &__wq_entry); \
__out: __ret; \
})
long prepare_to_wait_event(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry, int state)
{
unsigned long flags;
long ret = 0;
spin_lock_irqsave(&wq_head->lock, flags);
....
spin_unlock_irqrestore(&wq_head->lock, flags);
return ret;
}
As can be seen the wait library is using spin_locks already which are similar to mutex's (although slightly different). The nice thing about using the wait library is that a lot of safety checks to keep the kernel happy and going are automatically performed for you but it still performs the necessary block on your data. If you need more of an example on using the wait_event_* and it's assosciated wake_up_* calls let me know and I can fetch one.

warning: format not a string literal and no format arguments just in some GCC

gcc -v:
gcc version 4.9.2 (Ubuntu 4.9.2-10ubuntu13)
#define d_write_log_evolved(old_fmt, args...) \
do \
{ char new_fmt[2048] = {0}; \
time_t timep; \
struct tm *p; \
timep = time(&timep); \
p = localtime(&timep); \
sprintf(new_fmt, "%d-%d-%d %d:%d:%d [process %d][thread %lu]: ", \
(int)(1900+p->tm_year), \
(int)(1+p->tm_mon), \
(int)(p->tm_mday), \
(int)(p->tm_hour), \
(int)(p->tm_min), \
(int)(p->tm_sec), \
getpid(), \
pthread_self()); \
strcat(new_fmt, old_fmt); \
FILE *logfp = fopen(CCDAEMON_LOG, "a"); \
fprintf(logfp, new_fmt, ##args); \
fclose(logfp); \
} \
while (0)
d_write_log_evolved("[err] compile %s failed, thread will exit.\n", file);//here no warning.
d_write_log_evolved("socket() error, thread exit.\n"); //here have the warning.
When I pass some args to d_write_log_evolved(), then there's no warning reported, but without args, there always warning:warning: format not a string literal and no format arguments [-Wformat-security]
This really trouble me although program can be running properly.
BTW, there's no such warning under Scientific Linux.
Could you tell me how to eliminate this warning? Thanks!
PS. below is preprocessing result.
without agrs:
do { char new_fmt[2048] = {0}; time_t timep; struct tm *p; timep = time(&timep); p = localtime(&timep); sprintf(new_fmt, "%d-%d-%d %d:%d:%d [process %d][thread %lu]: ", (int)(1900+p->tm_year), (int)(1+p->tm_mon), (int)(p->tm_mday), (int)(p->tm_hour), (int)(p->tm_min), (int)(p->tm_sec), getpid(), pthread_self()); strcat(new_fmt, "socket() error, thread exit.\n"); FILE *logfp = fopen("/tmp/ccdcc.log", "a"); fprintf(logfp, new_fmt); fclose(logfp); } while (0);
with args:
do { char new_fmt[2048] = {0}; time_t timep; struct tm *p; timep = time(&timep); p = localtime(&timep); sprintf(new_fmt, "%d-%d-%d %d:%d:%d [process %d][thread %lu]: ", (int)(1900+p->tm_year), (int)(1+p->tm_mon), (int)(p->tm_mday), (int)(p->tm_hour), (int)(p->tm_min), (int)(p->tm_sec), getpid(), pthread_self()); strcat(new_fmt, "[ERR] send msg to client %s failed.\n"); FILE *logfp = fopen("/tmp/ccdcc.log", "a"); fprintf(logfp, new_fmt, inet_ntoa(host.sin_addr)); fclose(logfp); } while (0);

Fortran #define macro definitions with multiple lines

I was under the impression C-style macro definitions work in gfortran?
#define ERROR_CHECKER(msg,stat) \
IF (stat.NE.0) THEN \
DO i = 1,BIG \
IF(msg(i).NE.C_NULL_CHAR)THEN \
ErrMsg(i:i) = msg(i) \
ELSE \
EXIT \
END IF \
END DO\
IF(stat.EQ.1) THEN \
ErrStat = ID_Warn \
ELSE \
ErrStat = ID_Fatal \
RETURN \
END IF \
END IF
But then this error ruins my day:
IF (stat.NE.0) THEN DO i = 1,BIG IF(message
1
Error: Cannot assign to a named constant at (1)
Any ideas what I am doing wrong here?
Secondary question: does intel fortran recognize c-style macros? If so, are compiler flags necessary?
Instead of using a macro, just convert the macro to a function. That way you don't have a massive dependency on the Fortran compiler having a macro facility
LOGICAL FUNCTION ERROR_CHECKER(msg,stat)
character*(*) msg(*)
integer stat
IF (stat.NE.0) THEN
DO i = 1,BIG
IF(msg(i).NE.C_NULL_CHAR)THEN
ErrMsg(i:i) = msg(i)
ELSE
EXIT
END IF
END DO
IF(stat.EQ.1) THEN
ErrStat = ID_Warn
ELSE
ErrStat = ID_Fatal
RETURN .FALSE.
END IF
END IF
RETURN .TRUE.
END FUNCTION
In your code
IF (ERROR_CHECKER(msg, stat)) RETURN
Edit: Some of the later versions of Fortran have statement separators (;) which can be used. Unfortunately, the line length is limited so your macro cannot be very long, nor can it contain more than one control structure.
Aside from the fact that such a macro approach is not good style, you are missing the necessary line breaks in the generated code. This can be fixed by putting a semicolon before each backslash in the macro definition (except the first line).

Multilined define directives in CLI

Im trying to use quite long define in my CLI program but i'm getting dosens of errors because of that.
This is my code.
#define OPERATION_MACRO(character) \
array<Byte>^ opRes = gcnew array<Byte>(args[0]->Length); \
for(int i=0;i<args[0]->Length;i++) \
{ \
double result=0; \
for(int k=0;k<args->Length;k++) \
{ \
result character##= args[k][i]; \
} \
graphicUtils::round(result); \
opRes[i] = result; \
} \
return opRes;
array<Byte>^ myInterpreter::mathOp(array< array<Byte>^ >^ args, Char opr)
{
switch(opr)
{
case '*':
OPERATION_MACRO(*)
case '/':
OPERATION_MACRO(/)
case '+':
OPERATION_MACRO(+)
case '-':
OPERATION_MACRO(-)
case '%':
OPERATION_MACRO(%)
case '^':
OPERATION_MACRO(^)
}
}
Is it because of different new line character in CLI compiler?

STRINGZ_TO_NPVARIANT in xcode problem

have folowing code:
NPVariant type;
STRINGZ_TO_NPVARIANT("click", type);
and the xcode returns
"error: expected expression before 'uint32_t'"
anyone can give me a hand with this?
I ran into this as well. Based on this bug i found in the npapi project, i solved the problem by not using the macro, and using what it expands to instead, then applying what the patch shows.
http://code.google.com/p/npapi-headers/issues/detail?id=3
- NPString str = { _val, uint32_t(strlen(_val)) };
+ NPString str = { _val, (uint32_t)(strlen(_val)) };
Basically, wrap uint32_t in parenthesis, then gcc will compile it.
So the full replacement for the macro is
NPVariant type;
type.type = NPVariantType_String;
NPString str = { "click", (uint32_t)(strlen("click")) };
type.value.stringValue = str;
If you check what this macro resolves into you get:
NPVariant type;
type.type = NPVariantType_String;
NPString str = { "click", uint32_t(strlen("click")) };
type.value.stringValue = str;
At least this way one can understand what the error message refers to. I'm still not sure what the reason for the error is however - maybe your Xcode or gcc version is outdated. According to the documentation you need at least Xcode 2.5 and gcc 4.2.
in your npruntime.h find these two MACRO
#define STRINGZ_TO_NPVARIANT(_val, _v) \
NP_BEGIN_MACRO \
(_v).type = NPVariantType_String; \
NPString str = { _val, **(uint32_t)** strlen(_val) }; \
(_v).value.stringValue = str; \
NP_END_MACRO
#define STRINGN_TO_NPVARIANT(_val, _len, _v) \
NP_BEGIN_MACRO \
(_v).type = NPVariantType_String; \
NPString str = { _val, **(uint32_t)**_len }; \
(_v).value.stringValue = str; \
NP_END_MACRO
    
add (uint32_t) cast before strlen(_val) and _len

Resources