This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: ATTRIBUTE_WEAK



  In message <m10Fie3-000390C@ocean.lucon.org>you write:

  > Could you please show me how to use __attribute__ ((weak))? The code
  > below doesn't make "foo" weak. BTW,
  > 
[ ... ]
  > -- 
  > H.J. Lu (hjl@gnu.org)
  > ---
  > extern void foo () __attribute__ ((weak));
  > 
  > bar ()
  > {
  >   if (foo) foo ();
  > }
This is the right way to get a weak declaration.  It didn't work because  of
a trivial bug.  I've fixed that bug on the release branch (and will fix it
shortly in the mainline tree).

With the fix I get:

        .file   "foo.c"
        .version        "01.01"
gcc2_compiled.:
.text
        .align 4
.globl bar
        .type    bar,@function
bar:
        pushl %ebp
        movl %esp,%ebp
        movl $foo,%eax
        testl %eax,%eax
        je .L2
        call foo
.L2:
        movl %ebp,%esp
        popl %ebp
        ret
.Lfe1:
        .size    bar,.Lfe1-bar
        .weak   foo

Which is the same code I get if I use a #pragma instead.

jeff



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]