lkml.org 
[lkml]   [2009]   [Mar]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH 08/16] tracing: have event_trace_printk use static tracer
Date
> > > +#define event_trace_printk(ip, fmt, args...)				\
> > > +do { \
> > > + __trace_printk_check_format(fmt, ##args); \
> > > + tracing_record_cmdline(current); \
> > > + if (__builtin_constant_p(fmt)) { \
> > > + static const char *trace_printk_fmt \
> > > + __attribute__((section("__trace_printk_fmt"))) = \
> > > + __builtin_constant_p(fmt) ? fmt : NULL; \
> >
> > Why __builtin_constant_p(fmt) evaluate twice?
>
> It's explained in another patch. But this was a real PITA. We first tried
> this with just the "if (__builtin_return_p(fmt))" but the way gcc works,
> it handles the global data assignments before optimizing out condition
> logic. Thus we ended up getting errors about can not initialize static
> variable with a non constant.
>
> But the ? : operation of the assignment is optimized before the assignment
> is made. Thus, if fmt is not constant, then we avoid this warning. Then
> during the conditional optimization, gcc will remove that part of the code
> altogether.
>
> Thus the double __builtin_constant_p(fmt) is needed twice. Try taking out
> one of them and see what happens with:
>
> myfunc(const char *fmt) {
>
> event_trace_printk(fmt);
>
> }
>
> Of course the way this is made, we may not call it that way, but I wanted
> to be safe.

Thanks for kindful explain.
So, I guess many developer feel it's strange.
adding comment is better?




\
 
 \ /
  Last update: 2009-03-13 04:33    [from the cache]
©2003-2011 Jasper Spaans