This is the mail archive of the binutils@sourceware.org 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]

Question about archive search behavior vs. --defsym


If you do something like this:

  int main () { f(); }

and don't define "f" anywhere, you can do:

  gcc main.c -Wl,--defsym=f=4

and your program will link, with the call being replaced with a call to 0x4.

But, I was surprised to find that if "f" is defined in an archive it is
still pulled in. Concretely:

f.c
===
void f() {}

main.c
======
int main () { f(); }

$ gcc -c f.c
$ ar cr libf.a f.o
$ gcc main.c -Wl,--defsym=f=4 -L. -lf

pulls in f.o from libf.a even though the symbol is already defined.

This behavior was surprising to me.  Is this a bug?

Thanks,

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713


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