http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56431



--- Comment #4 from H.J. Lu <hjl.tools at gmail dot com> 2013-02-27 19:36:07 
UTC ---

(In reply to comment #3)

> Object OBJ has a weak reference to SYM.

> 

> OBJ is linked against shared library S1.  S1 does not define SYM.

> 

> S1 happens to be linked against shared library S2.  S2 does define SYM.

> 

> That will work fine: at runtime OBJ will see that SYM is defined, because S1

> brings in S2.

> 



This isn't what happens.  Since gold doesn't check S2 at link-time, it

resolves SYM to 0:



[hjl@gnu-6 pr15149]$ cat foo.c 

#include <stdio.h>



extern int xxx () __attribute__((weak));



int

foo ()

{

  if (&xxx)

    return xxx ();

  return 1;

}



int

main ()

{

  printf ("xxx: %d\n", foo ());

  return 0;

}

[hjl@gnu-6 pr15149]$ cat xxx.c

int

xxx ()

{

  return 0;

}

[hjl@gnu-6 pr15149]$ cat yyy.c

/* Dummy */

[hjl@gnu-6 pr15149]$ make y

gcc -Wl,--no-copy-dt-needed-entries    -c -o foo.o foo.c

gcc -Wl,--no-copy-dt-needed-entries -shared -fPIC -o libxxx.so xxx.c

gcc -Wl,--no-copy-dt-needed-entries -shared -fPIC -o libyyy.so yyy.c libxxx.so

-Wl,-rpath,.

gcc -Wl,--no-copy-dt-needed-entries -fuse-ld=gold -B./ -Wl,--no-as-needed -o y

foo.o libyyy.so -Wl,-rpath,.

[hjl@gnu-6 pr15149]$ ./y

xxx: 1

[hjl@gnu-6 pr15149]$ 



38: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND xxx



If gold sees SYM defined in S2, it will create a R_X86_64_JUMP_SLO relocation,

set xxx value to the PLT entry and resolve xxx to the PLT entry.



000000401ad0  000700000007 R_X86_64_JUMP_SLO 0000000000400570 xxx + 0



7: 0000000000400570     0 FUNC    WEAK   DEFAULT  UND xxx



That is the difference between seeing SYM in S2 or not.

Reply via email to