This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Weak references, --as-needed, and pthreads
>> (5) Gold does not record symbol version information gleaned from an
>> "as-needed" library that isn't needed. (BFD ld apparently does, or
>> else it picks up the version information from the same symbols in
>> libc.)
>
> ld.bfd takes a snapshot of the symbol table before attempting to add
> an as-needed library, and restores the symbol table if the library
> wasn't needed. That will result in picking up the libc symbol version
> for these pthread symbols.
>
> When gold sees duplicate weak symbols defined in shared libraries, I
> think gold will set sym->object from the first definition seen. (I
> haven't checked but that seems likely.) Where we first see a
> definition in an as-needed library that isn't needed, sym->object
> remains as that library (libpthread in this case), even when a later
> definition (libc in this case) is the actual symbol used. sym->object
> really ought to be set to actual defining library, and the version
> taken from there. My 2013 gold patch wasn't correct.
I've considered letting a definition from a shared library override an
earlier definition from an "unneeded" shared library. The complicating
factor is that we currently don't decide whether a library is needed
or not until we've seen *all* symbols -- i.e., unlike an archive
library, a strong reference from a regular object that follows the
shared library in the link order can make it "needed". It sounds like
ld.bfd doesn't worry about that, so I'll proceed with a patch along
those lines.
I still feel that GCC's use of weak references for pthreads APIs is
not compatible with --as-needed, and that GCC is wrong in not placing
--no-as-needed in front of -lpthread. I was hoping I'd get some
encouragement here to take that up with GCC.
-cary