This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Question about archive search behavior vs. --defsym
- From: Ian Lance Taylor <iant at google dot com>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: binutils at sourceware dot org
- Date: Wed, 08 Sep 2010 23:19:06 -0700
- Subject: Re: Question about archive search behavior vs. --defsym
- References: <4C88682B.5030306@codesourcery.com>
Mark Mitchell <mark@codesourcery.com> writes:
> 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?
It's a phase ordering problem. Objects are pulled in from archives
before symbol assignments are processed.
I think this has to be considered a bug.
Ian