This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Confusing behaviour from gcc and ld with --as-needed
On Mon, 2005-04-04 at 14:24 -0400, Daniel Jacobowitz wrote:
> Try adding -v to those command lines to see what's going on?
Well, that shows what I expected:
/usr/libexec/gcc/i386-redhat-linux/3.4.2/collect2 --eh-frame-hdr -m
elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o vfolder-
magic /usr/lib/gcc/i386-redhat-
linux/3.4.2/../../../crt1.o /usr/lib/gcc/i386-redhat-
linux/3.4.2/../../../crti.o /usr/lib/gcc/i386-redhat-
linux/3.4.2/crtbegin.o -L/usr/lib -L/usr/lib/gcc/i386-redhat-linux/3.4.2
-L/usr/lib/gcc/i386-redhat-linux/3.4.2 -L/usr/lib/gcc/i386-redhat-
linux/3.4.2/../../.. --as-needed -lxml -lz vfolder-magic.o -lgcc --as-
needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-
needed /usr/lib/gcc/i386-redhat-linux/3.4.2/crtend.o /usr/lib/gcc/i386-
redhat-linux/3.4.2/../../../crtn.o
I think I see now why it doesn't work: --as-needed must make the
decision based on what source files it's seen so far as it parses it. So
it sees "-lxml" and says "nothing used that so far, so we'll drop it".
Then the object file is linked into the file binary, and we end up with
unresolved references because the DT_NEEDED entry was dropped too early.
If so I can see why this happens, and am not sure it's a bug. But the
behaviour is definitely unexpected.
thanks -mike