This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Thanks for the swift reply!
It is a combination of ld and ld.so. Weak symbols are treated as strong when DSO is involved. If you want a DSO to override a symbol in an archive, you have to make sure that the .o file which contains the symbol can ONLY be used to resolve that symbol. In your case, bar.o defines both foo and bar. Linker sees foo when it tries to resolve bar.
*** modified/bar.c 2005-04-27 22:24:44.000000000 +0100 --- mod-2/bar.c 2005-04-27 22:25:02.000000000 +0100 *************** *** 1,14 **** --- 1,20 ---- #include <stdio.h>
+ #ifdef FOO void foo (); + #endif
+ #ifdef BAR #pragma weak foo = bar + #endif
+ #ifdef BAR #define foo bar + #endif
void foo ()
[gwh@snowball first-solution]$ make gcc -B./ -O -g -c -o main.o main.c gcc -B./ -O -g -fPIC -c foo.c -o shared.o gcc -B./ -shared -o libshared1.so shared.o gcc -B./ -O -g -DFOO -fPIC -c bar.c -o foobar.o ar rv libfoo.a foobar.o ar: creating libfoo.a a - foobar.o gcc -B./ -O -g -DBAR -fPIC -c bar.c -o barbar.o ar rv libfoo.a barbar.o a - barbar.o gcc -B./ -o main1 main.o libshared1.so libfoo.a -Wl,-rpath,. gcc -B./ -o main2 main.o libfoo.a gcc -B./ -shared -o libshared3.so shared.o libfoo.a gcc -B./ -o main3 main.o libshared3.so libfoo.a -Wl,-rpath,. ./main1 Shared library Real bar ./main2 Real foo ./main3 Shared library Real bar
Attachment:
bug.tar.gz
Description: GNU Zip compressed data
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |