Bug 24458 - Linker BFD 2.32 regression: __ehdr_start not useable in shared libraries: "relocation R_X86_64_PC32 against undefined symbol `__ehdr_start' can not be used when making a shared object; recompile with -fPIC"
Summary: Linker BFD 2.32 regression: __ehdr_start not useable in shared libraries: "re...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: 2.33
Assignee: H.J. Lu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-16 20:05 UTC by Arfrever Frehtes Taifersar Arahesis
Modified: 2019-04-24 19:36 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2019-04-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Arfrever Frehtes Taifersar Arahesis 2019-04-16 20:05:47 UTC
$ cat test.cpp
extern char __ehdr_start;
int main() {
  char x = __ehdr_start;
}


Linker BFD 2.31 prints some unrelated warnings, but works:

$ g++ -fuse-ld=bfd -o test test.cpp
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.bfd: /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/libgcc.a(_muldi3.o): unable to initialize decompress status for section .debug_info
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.bfd: /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/libgcc.a(_muldi3.o): unable to initialize decompress status for section .debug_info
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.bfd: /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/libgcc.a(_muldi3.o): unable to initialize decompress status for section .debug_info
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.bfd: /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/libgcc.a(_muldi3.o): unable to initialize decompress status for section .debug_info
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.bfd: /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/libgcc.a(_muldi3.o): unable to initialize decompress status for section .debug_info
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.bfd: /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/libgcc.a(_muldi3.o): unable to initialize decompress status for section .debug_info
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.bfd: /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/libgcc.a(_muldi3.o): unable to initialize decompress status for section .debug_info
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.bfd: /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/libgcc.a(_muldi3.o): unable to initialize decompress status for section .debug_info
$ echo $?
0
$ g++ -fuse-ld=bfd -shared -fPIC -o test.so test.cpp
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.bfd: /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/libgcc.a(_muldi3.o): unable to initialize decompress status for section .debug_info
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.bfd: /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/libgcc.a(_muldi3.o): unable to initialize decompress status for section .debug_info
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.bfd: /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/libgcc.a(_muldi3.o): unable to initialize decompress status for section .debug_info
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.bfd: /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/libgcc.a(_muldi3.o): unable to initialize decompress status for section .debug_info
$ echo $?
0


Linker GOLD 2.31 works:

$ g++ -fuse-ld=gold -o test test.cpp
$ echo $?
0
$ g++ -fuse-ld=gold -shared -fPIC -o test.so test.cpp
$ echo $?
0


Linker BFD 2.32 works for executables, but fails for shared libraries:

$ g++ -fuse-ld=bfd -o test test.cpp
$ echo $?
0
$ g++ -fuse-ld=bfd -shared -fPIC -o test.so test.cpp
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.bfd: /tmp/cc6cOEh1.o: relocation R_X86_64_PC32 against undefined symbol `__ehdr_start' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.bfd: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
$ echo $?
1


Linker GOLD 2.32 works:

$ g++ -fuse-ld=gold -o test test.cpp
$ echo $?
0
$ g++ -fuse-ld=gold -shared -fPIC -o test.so test.cpp
$ echo $?
0


Linker LLD 8.0.0 works:

$ clang++ -fuse-ld=lld -o test test.cpp
$ echo $?
0
$ clang++ -fuse-ld=lld -shared -fPIC -o test.so test.cpp
$ echo $?
0


(__ehdr_start symbol is defined in glibc's static library. glibc 2.29 is built with GCC 8.3.0 and linker BFD 2.32.)
Comment 1 cvs-commit@gcc.gnu.org 2019-04-17 16:14:06 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=4e84a8f8bbeab52fa7048873655e582ceb92534d

commit 4e84a8f8bbeab52fa7048873655e582ceb92534d
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Apr 17 09:08:46 2019 -0700

    x86: Also check x86 linker_def for non-shared definition
    
    Since elf_x86_linker_defined sets linker_def in elf_x86_link_hash_entry
    for linker defined symbols, SYMBOL_DEFINED_NON_SHARED_P should also check
    linker_def in elf_x86_link_hash_entry.
    
    bfd/
    
    	PR ld/24458
    	* elfxx-x86.h (SYMBOL_DEFINED_NON_SHARED_P): Also check x86
    	linker_def.
    
    ld/
    
    	PR ld/24458
    	* testsuite/ld-x86-64/x86-64.exp: Run PR ld/24458 tests.
    	* testsuite/ld-x86-64/pr24458.s: New file.
    	* testsuite/ld-x86-64/pr24458a-x32.d: Likewise.
    	* testsuite/ld-x86-64/pr24458a.d: Likewise.
    	* testsuite/ld-x86-64/pr24458b-x32.d: Likewise.
    	* testsuite/ld-x86-64/pr24458b.d: Likewise.
    	* testsuite/ld-x86-64/pr24458c-x32.d: Likewise.
    	* testsuite/ld-x86-64/pr24458c.d: Likewise.
Comment 2 cvs-commit@gcc.gnu.org 2019-04-17 16:20:20 UTC
The binutils-2_32-branch branch has been updated by H.J. Lu <hjl@sourceware.org>:

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

commit 49364d83d58d6357aa0fcd1b448b48218d244675
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Apr 17 09:08:46 2019 -0700

    x86: Also check x86 linker_def for non-shared definition
    
    Since elf_x86_linker_defined sets linker_def in elf_x86_link_hash_entry
    for linker defined symbols, SYMBOL_DEFINED_NON_SHARED_P should also check
    linker_def in elf_x86_link_hash_entry.
    
    bfd/
    
    	PR ld/24458
    	* elfxx-x86.h (SYMBOL_DEFINED_NON_SHARED_P): Also check x86
    	linker_def.
    
    ld/
    
    	PR ld/24458
    	* testsuite/ld-x86-64/x86-64.exp: Run PR ld/24458 tests.
    	* testsuite/ld-x86-64/pr24458.s: New file.
    	* testsuite/ld-x86-64/pr24458a-x32.d: Likewise.
    	* testsuite/ld-x86-64/pr24458a.d: Likewise.
    	* testsuite/ld-x86-64/pr24458b-x32.d: Likewise.
    	* testsuite/ld-x86-64/pr24458b.d: Likewise.
    	* testsuite/ld-x86-64/pr24458c-x32.d: Likewise.
    	* testsuite/ld-x86-64/pr24458c.d: Likewise.
    
    (cherry picked from commit 4e84a8f8bbeab52fa7048873655e582ceb92534d)
Comment 3 H.J. Lu 2019-04-17 16:20:48 UTC
Fixed for 2.33 and on 2.32 branch.
Comment 4 Arfrever Frehtes Taifersar Arahesis 2019-04-24 16:45:04 UTC
Original 2.31 release was not affected by this bug, but I have been notified that the regression has been backported to 2.31 branch:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=c83ac8021a7649c148cb344870d8ce711eecc3c6

If 2.31 branch is still maintained, please backport the fix to 2.31 branch.
Comment 5 cvs-commit@gcc.gnu.org 2019-04-24 19:26:38 UTC
The binutils-2_31-branch branch has been updated by H.J. Lu <hjl@sourceware.org>:

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

commit bca6a14c568bd63080c85a6b05c90996e2bd4a34
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Apr 17 09:08:46 2019 -0700

    x86: Also check x86 linker_def for non-shared definition
    
    Since elf_x86_linker_defined sets linker_def in elf_x86_link_hash_entry
    for linker defined symbols, SYMBOL_DEFINED_NON_SHARED_P should also check
    linker_def in elf_x86_link_hash_entry.
    
    bfd/
    
    	PR ld/24458
    	* elfxx-x86.h (SYMBOL_DEFINED_NON_SHARED_P): Also check x86
    	linker_def.
    
    ld/
    
    	PR ld/24458
    	* testsuite/ld-x86-64/x86-64.exp: Run PR ld/24458 tests.
    	* testsuite/ld-x86-64/pr24458.s: New file.
    	* testsuite/ld-x86-64/pr24458a-x32.d: Likewise.
    	* testsuite/ld-x86-64/pr24458a.d: Likewise.
    	* testsuite/ld-x86-64/pr24458b-x32.d: Likewise.
    	* testsuite/ld-x86-64/pr24458b.d: Likewise.
    	* testsuite/ld-x86-64/pr24458c-x32.d: Likewise.
    	* testsuite/ld-x86-64/pr24458c.d: Likewise.
    
    (cherry picked from commit 4e84a8f8bbeab52fa7048873655e582ceb92534d)
Comment 6 H.J. Lu 2019-04-24 19:36:06 UTC
Also fixed on 2.31 branch.