Bug 19553 - linking against libs that require pthreads breaks due to symbol changes
Summary: linking against libs that require pthreads breaks due to symbol changes
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.26
: P2 normal
Target Milestone: 2.27
Assignee: H.J. Lu
URL:
Keywords:
Depends on: 18720
Blocks:
  Show dependency treegraph
 
Reported: 2016-02-01 21:08 UTC by Mike Frysinger
Modified: 2016-02-26 13:32 UTC (History)
0 users

See Also:
Host:
Target: x86_64-linux-gnu
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Frysinger 2016-02-01 21:08:52 UTC
after the change for bug 18720 landed, trying to use libs that use pthreads under glibc fails when the main app itself doesn't use pthreads.

example:
$ echo 'main() { fork(); }' > test.c
$ gcc test.c -fsanitize=address
ld: /usr/lib/gcc/x86_64-pc-linux-gnu/5.3.0/libasan.so: undefined reference to symbol 'fork@GLIBC_2.2.5'
/lib64/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

this is a regression wrt binutils 2.25.
Comment 1 H.J. Lu 2016-02-01 21:50:57 UTC
[hjl@gnu-6 pr19553]$ cat pr19553a.c
extern void foo (void);

int
main (void)
{
  foo ();
  return 0;
}
[hjl@gnu-6 pr19553]$ cat pr19553b.c
#include <stdio.h>

__attribute__ ((weak))
void
foo (void)
{
  printf ("pr19553b\n");
}
[hjl@gnu-6 pr19553]$ cat pr19553c.c
#include <stdio.h>

void
foo (void)
{
  printf ("pr19553c\n");
}

asm (".symver foo,foo@FOO");
[hjl@gnu-6 pr19553]$ cat pr19553d.c
#include <stdio.h>

__attribute__ ((weak))
void
foo (void)
{
  printf ("pr19553d\n");
}
[hjl@gnu-6 pr19553]$ cat pr19553.map
FOO
{
global:
  foo;
};
[hjl@gnu-6 pr19553]$ make
gcc -B./ -O2 -O2 -c -o pr19553a.o pr19553a.c
gcc -B./ -O2 -fPIC -c -o pr19553d.o pr19553d.c
gcc -B./ -O2 -fPIC -c -o pr19553c.o pr19553c.c
gcc -B./ -shared -o libpr19553c.so pr19553c.o -Wl,--version-script=pr19553.map
gcc -B./ -shared -o libpr19553d.so pr19553d.o  libpr19553c.so
gcc -B./ -O2 -fPIC -c -o pr19553b.o pr19553b.c
gcc -B./ -shared -o libpr19553b.so pr19553b.o -Wl,--version-script=pr19553.map
gcc -B./ -o x pr19553a.o libpr19553d.so libpr19553b.so -Wl,-R.
./ld: libpr19553d.so: undefined reference to symbol 'foo@FOO'
./libpr19553c.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Makefile:23: recipe for target 'x' failed
make: *** [x] Error 1
[hjl@gnu-6 pr19553]$
Comment 2 H.J. Lu 2016-02-01 23:14:13 UTC
A patch is posted at

https://sourceware.org/ml/binutils/2016-02/msg00035.html
Comment 3 cvs-commit@gcc.gnu.org 2016-02-01 23:50:32 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=aef28989904e92e391fee905e51abc6bb2fd4de0

commit aef28989904e92e391fee905e51abc6bb2fd4de0
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Feb 1 15:49:52 2016 -0800

    Don't add DT_NEEDED for unmatched symbol
    
    Don't add DT_NEEDED if a symbol from a library loaded via DT_NEEDED
    doesn't match the symbol referenced by regular object.
    
    bfd/
    
    	PR ld/19553
    	* elflink.c (elf_link_add_object_symbols): Don't add DT_NEEDED
    	if a symbol from a library loaded via DT_NEEDED doesn't match
    	the symbol referenced by regular object.
    
    ld/testsuite/
    
    	PR ld/19553
    	* testsuite/ld-elf/indirect.exp: Run tests for PR ld/19553.
    	* testsuite/ld-elf/pr19553.map: New file.
    	* testsuite/ld-elf/pr19553.map: Likewise.
    	* testsuite/ld-elf/pr19553a.c: Likewise.
    	* testsuite/ld-elf/pr19553b.c: Likewise.
    	* testsuite/ld-elf/pr19553b.out: Likewise.
    	* testsuite/ld-elf/pr19553c.c: Likewise.
    	* testsuite/ld-elf/pr19553c.out: Likewise.
    	* testsuite/ld-elf/pr19553d.c: Likewise.
    	* testsuite/ld-elf/pr19553d.out: Likewise.
Comment 4 H.J. Lu 2016-02-01 23:51:15 UTC
Fixed for 2.27 so far.
Comment 5 cvs-commit@gcc.gnu.org 2016-02-26 13:31:16 UTC
The binutils-2_26-branch branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f558a73bafecee6d3cd45031e44e6e40f80fb241

commit f558a73bafecee6d3cd45031e44e6e40f80fb241
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Feb 1 15:49:52 2016 -0800

    Don't add DT_NEEDED for unmatched symbol
    
    Don't add DT_NEEDED if a symbol from a library loaded via DT_NEEDED
    doesn't match the symbol referenced by regular object.
    
    Backport from master
    
    bfd/
    
    	PR ld/19553
    	* elflink.c (elf_link_add_object_symbols): Don't add DT_NEEDED
    	if a symbol from a library loaded via DT_NEEDED doesn't match
    	the symbol referenced by regular object.
    
    ld/testsuite/
    
    	PR ld/19553
    	* testsuite/ld-elf/indirect.exp: Run tests for PR ld/19553.
    	* testsuite/ld-elf/pr19553.map: New file.
    	* testsuite/ld-elf/pr19553.map: Likewise.
    	* testsuite/ld-elf/pr19553a.c: Likewise.
    	* testsuite/ld-elf/pr19553b.c: Likewise.
    	* testsuite/ld-elf/pr19553b.out: Likewise.
    	* testsuite/ld-elf/pr19553c.c: Likewise.
    	* testsuite/ld-elf/pr19553c.out: Likewise.
    	* testsuite/ld-elf/pr19553d.c: Likewise.
    	* testsuite/ld-elf/pr19553d.out: Likewise.
Comment 6 H.J. Lu 2016-02-26 13:32:08 UTC
Fixed.