On Mon, Dec 26, 2011 at 5:20 PM, Angus Salkeld <asalkeld(a)redhat.com> wrote:
----- Original Message -----
> From: "Yunkai Zhang" <qiushu.zyk(a)taobao.com>
> To: "lib quarterback" <quarterback-devel(a)lists.fedorahosted.org>
> Sent: Monday, 26 December, 2011 8:06:16 PM
> Subject: Re: [libqb] How does ld linker work?
>
> Well, thank you.
>
> On Mon, Dec 26, 2011 at 5:04 PM, Angus Salkeld <asalkeld(a)redhat.com>
> wrote:
> > ----- Original Message -----
> >> From: "Yunkai Zhang" <qiushu.zyk(a)taobao.com>
> >> To: "Angus Salkeld" <asalkeld(a)redhat.com>
> >> Cc: "lib quarterback"
<quarterback-devel(a)lists.fedorahosted.org>
> >> Sent: Friday, 23 December, 2011 8:27:50 PM
> >> Subject: How does ld linker work?
> >>
> >> Hi Angus:
> >>
> >> I'm confused by these code in qblog.h:
> >>
> >> 240 /* will be assigned by ld linker magic */
> >> 241 #ifdef QB_HAVE_ATTRIBUTE_SECTION
> >> 242 extern struct qb_log_callsite __start___verbose[];
> >> 243 extern struct qb_log_callsite __stop___verbose[];
> >>
> >> I can't understand how ld linker work:
> >> What is the naming rule when we use callsite?
> >> __start___<section_name>?
So we create a section like:
#ifdef QB_HAVE_ATTRIBUTE_SECTION
#define qb_logt(priority, tags, fmt, args...) do { \
static struct qb_log_callsite descriptor \
__attribute__((section("__verbose"), aligned(8))) = \
{ __func__, __FILE__, fmt, priority, __LINE__, 0, tags }; \
qb_log_real_(&descriptor, ##args); \
} while(0)
so this global gets put into an "array" starting from
"__start__verbose"
and ending at "__stop__verbose".
How do you known that? I just want to find the specification which
describing this naming rule :)
Then when we get a log we just pass the pointer to it into the logging system.
In the filtering code I iterate over all the callsite as follows:
for (cs = __start__verbose; cs < __stop__verbose; cs++) {
// do something with cs
}
Hope that is more helpful.
-Angus
> >> Can you give me some references about ld linker's magic?
> >
> > Hi
> >
> >
http://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Variable-Attributes.html
> >
> > Look at the paragraph: section ("section-name")
> >
> > -Angus
> >
> >>
> >> Thanks a lot.
> >>
> >> --
> >> Yunkai Zhang
> >> Work at Taobao
> >>
> > _______________________________________________
> > quarterback-devel mailing list
> > quarterback-devel(a)lists.fedorahosted.org
> >
https://fedorahosted.org/mailman/listinfo/quarterback-devel
>
>
>
> --
> Yunkai Zhang
> Work at Taobao
> _______________________________________________
> quarterback-devel mailing list
> quarterback-devel(a)lists.fedorahosted.org
>
https://fedorahosted.org/mailman/listinfo/quarterback-devel
>
_______________________________________________
quarterback-devel mailing list
quarterback-devel(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/quarterback-devel
--
Yunkai Zhang
Work at Taobao