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]

Re: test failures in the libstdc++ and glibc testsuites with ld --as-needed from binutils trunk


On Sat, Aug 31, 2013 at 01:51:34PM +0200, Matthias Klose wrote:
> $ readelf -a 42819.o | grep 'WEAK.*pthread'
>    479: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __pthread_key_create
>    480: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND pthread_mutex_unlock
>    481: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND pthread_mutex_lock
>    482: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND pthread_once
> $ readelf -a libtestc++.a | grep 'WEAK.*pthread'
>    220: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __pthread_key_create
>     90: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __pthread_key_create
>     65: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __pthread_key_create
> 
> Relinking the test case with the --as-needed removed, or surrounding -lpthread
> with --no-as-needed/--as-needed adds the NEEDED entry on libpthread again and
> lets the test case succeed again.
> 
> Looking at the --as-needed documentation, this behaviour seems to be unexpected.
>  Shouldn't this handling for weak symbols only be done when linking a shared
> library, and not an executable?

Why should there be a difference?

Note that besides making --as-needed behave just like archives with
respect to weak symbols, there is another good reason to not link
--as-needed -lpthread on a weak symbol ref, related to libstdc++
reference counting.  For example, basic_string refcounts must use
atomic ops when multi-threaded, but can use the cheaper (sometimes
much cheaper) non-atomic ops when single-threaded.  libstdc++ detects
whether a process is multi-threaded by looking to see whether
__pthread_key_create is defined.  See libgcc/gthr-posix.h
__gthread_active_p.  You do not want to link -lpthread to satisfy just
that particular weak symbol reference.

The real question is why are all the other references from libstdc++
to pthread symbols weak?  How can that possibly work with static
archives?

-- 
Alan Modra
Australia Development Lab, IBM


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