Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lld can't be used with GCC 7 #28788

Closed
hjl-tools opened this issue Jul 4, 2016 · 32 comments
Closed

lld can't be used with GCC 7 #28788

hjl-tools opened this issue Jul 4, 2016 · 32 comments
Labels
bugzilla Issues migrated from bugzilla lld:ELF

Comments

@hjl-tools
Copy link
Contributor

Bugzilla Link 28414
Resolution FIXED
Resolved on Jul 19, 2017 09:49
Version unspecified
OS Linux
Blocks #23588
CC @compnerd,@emaste,@silvasean

Extended Description

On Linux/x86-64, when GCC 7 configured with

/export/gnu/import/git/sources/gcc/configure --enable-languages=c,c++,fortran --disable-bootstrap --enable-libmpx --with-ld=/export/build/gnu/llvm-clang/release/opt/llvm/master/bin/lld --with-plugin-ld=/export/build/gnu/llvm-clang/release/opt/llvm/master/bin/lld --prefix=/usr/gcc-7.0.0 --with-local-prefix=/usr/local --enable-gnu-indirect-function --with-fpmath=sse

I got

mkdir -p -- 32
/export/build/gnu/gcc-test/build-x86_64-linux/./gcc/xgcc -B/export/build/gnu/gcc-test/build-x86_64-linux/./gcc/ -B/usr/gcc-7.0.0/x86_64-pc-linux-gnu/bin/ -B/usr/gcc-7.0.0/x86_64-pc-linux-gnu/lib/ -isystem /usr/gcc-7.0.0/x86_64-pc-linux-gnu/include -isystem /usr/gcc-7.0.0/x86_64-pc-linux-gnu/sys-include -O2 -O2 -g -DIN_GCC -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fpic -mlong-double-80 -DUSE_ELF_SYMVER -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -shared -nodefaultlibs -Wl,--soname=libgcc_s.so.1 -Wl,--version-script=libgcc.map -o 32/libgcc_s.so.1.tmp -O2 -g -m32 -B./ _muldi3_s.o _negdi2_s.o _lshrdi3_s.o _ashldi3_s.o _ashrdi3_s.o _cmpdi2_s.o _ucmpdi2_s.o _clear_cache_s.o _trampoline_s.o __main_s.o _absvsi2_s.o _absvdi2_s.o _addvsi3_s.o _addvdi3_s.o _subvsi3_s.o _subvdi3_s.o _mulvsi3_s.o _mulvdi3_s.o _negvsi2_s.o _negvdi2_s.o _ctors_s.o _ffssi2_s.o _ffsdi2_s.o _clz_s.o _clzsi2_s.o _clzdi2_s.o _ctzsi2_s.o _ctzdi2_s.o _popcount_tab_s.o _popcountsi2_s.o _popcountdi2_s.o _paritysi2_s.o _paritydi2_s.o _powisf2_s.o _powidf2_s.o _powixf2_s.o _powitf2_s.o _mulsc3_s.o _muldc3_s.o _mulxc3_s.o _multc3_s.o _divsc3_s.o _divdc3_s.o _divxc3_s.o _divtc3_s.o _bswapsi2_s.o _bswapdi2_s.o _clrsbsi2_s.o _clrsbdi2_s.o _fixunssfsi_s.o _fixunsdfsi_s.o _fixunsxfsi_s.o _fixsfdi_s.o _fixdfdi_s.o _fixxfdi_s.o _fixunssfdi_s.o _fixunsdfdi_s.o _fixunsxfdi_s.o _floatdisf_s.o _floatdidf_s.o _floatdixf_s.o _floatundisf_s.o _floatundidf_s.o _floatundixf_s.o _divdi3_s.o _moddi3_s.o _udivdi3_s.o _umoddi3_s.o _udiv_w_sdiv_s.o _udivmoddi4_s.o cpuinfo_s.o tf-signs_s.o sfp-exceptions_s.o addtf3_s.o divtf3_s.o eqtf2_s.o getf2_s.o letf2_s.o multf3_s.o negtf2_s.o subtf3_s.o unordtf2_s.o fixtfsi_s.o fixunstfsi_s.o floatsitf_s.o floatunsitf_s.o fixtfdi_s.o fixunstfdi_s.o floatditf_s.o floatunditf_s.o extendsftf2_s.o extenddftf2_s.o extendxftf2_s.o trunctfsf2_s.o trunctfdf2_s.o trunctfxf2_s.o enable-execute-stack_s.o unwind-dw2_s.o unwind-dw2-fde-dip_s.o unwind-sjlj_s.o unwind-c_s.o emutls_s.o libgcc.a -lc && rm -f 32/libgcc_s.so && if [ -f 32/libgcc_s.so.1 ]; then mv -f 32/libgcc_s.so.1 32/libgcc_s.so.1.backup; else true; fi && mv 32/libgcc_s.so.1.tmp 32/libgcc_s.so.1 && (echo "/* GNU ld script"; echo " Use the shared library, but some functions are only in"; echo " the static library. */"; echo "GROUP ( libgcc_s.so.1 -lgcc )" ) > 32/libgcc_s.so
-flavor option is missing. Available flavors are gnu, darwin or link.
collect2: error: ld returned 1 exit status
Makefile:945: recipe for target 'libgcc_s.so' failed
make[5]: *** [libgcc_s.so] Error 1
make[5]: Leaving directory '/export/build/gnu/gcc-test/build-x86_64-linux/x86_64-pc-linux-gnu/32/libgcc'

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 4, 2016

You might want to try ld.lld instead. ld is the universal driver so you need to specify -flavor.

@hjl-tools
Copy link
Contributor Author

A little bit better. Now I got

/export/build/gnu/gcc-test/build-x86_64-linux/./gcc/xgcc -B/export/build/gnu/gcc-test/build-x86_64-linux/./gcc/ -B/usr/gcc-7.0.0/x86_64-pc-linux-gnu/bin/ -B/usr/gcc-7.0.0/x86_64-pc-linux-gnu/lib/ -isystem /usr/gcc-7.0.0/x86_64-pc-linux-gnu/include -isystem /usr/gcc-7.0.0/x86_64-pc-linux-gnu/sys-include -O2 -O2 -g -DIN_GCC -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fpic -mlong-double-80 -DUSE_ELF_SYMVER -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -shared -nodefaultlibs -Wl,--soname=libgcc_s.so.1 -Wl,--version-script=libgcc.map -o 32/libgcc_s.so.1.tmp -O2 -g -m32 -B./ _muldi3_s.o _negdi2_s.o _lshrdi3_s.o _ashldi3_s.o _ashrdi3_s.o _cmpdi2_s.o _ucmpdi2_s.o _clear_cache_s.o _trampoline_s.o __main_s.o _absvsi2_s.o _absvdi2_s.o _addvsi3_s.o _addvdi3_s.o _subvsi3_s.o _subvdi3_s.o _mulvsi3_s.o _mulvdi3_s.o _negvsi2_s.o _negvdi2_s.o _ctors_s.o _ffssi2_s.o _ffsdi2_s.o _clz_s.o _clzsi2_s.o _clzdi2_s.o _ctzsi2_s.o _ctzdi2_s.o _popcount_tab_s.o _popcountsi2_s.o _popcountdi2_s.o _paritysi2_s.o _paritydi2_s.o _powisf2_s.o _powidf2_s.o _powixf2_s.o _powitf2_s.o _mulsc3_s.o _muldc3_s.o _mulxc3_s.o _multc3_s.o _divsc3_s.o _divdc3_s.o _divxc3_s.o _divtc3_s.o _bswapsi2_s.o _bswapdi2_s.o _clrsbsi2_s.o _clrsbdi2_s.o _fixunssfsi_s.o _fixunsdfsi_s.o _fixunsxfsi_s.o _fixsfdi_s.o _fixdfdi_s.o _fixxfdi_s.o _fixunssfdi_s.o _fixunsdfdi_s.o _fixunsxfdi_s.o _floatdisf_s.o _floatdidf_s.o _floatdixf_s.o _floatundisf_s.o _floatundidf_s.o _floatundixf_s.o _divdi3_s.o _moddi3_s.o _udivdi3_s.o _umoddi3_s.o _udiv_w_sdiv_s.o _udivmoddi4_s.o cpuinfo_s.o tf-signs_s.o sfp-exceptions_s.o addtf3_s.o divtf3_s.o eqtf2_s.o getf2_s.o letf2_s.o multf3_s.o negtf2_s.o subtf3_s.o unordtf2_s.o fixtfsi_s.o fixunstfsi_s.o floatsitf_s.o floatunsitf_s.o fixtfdi_s.o fixunstfdi_s.o floatditf_s.o floatunditf_s.o extendsftf2_s.o extenddftf2_s.o extendxftf2_s.o trunctfsf2_s.o trunctfdf2_s.o trunctfxf2_s.o enable-execute-stack_s.o unwind-dw2_s.o unwind-dw2-fde-dip_s.o unwind-sjlj_s.o unwind-c_s.o emutls_s.o libgcc.a -lc && rm -f 32/libgcc_s.so && if [ -f 32/libgcc_s.so.1 ]; then mv -f 32/libgcc_s.so.1 32/libgcc_s.so.1.backup; else true; fi && mv 32/libgcc_s.so.1.tmp 32/libgcc_s.so.1 && (echo "/* GNU ld script"; echo " Use the shared library, but some functions are only in"; echo " the static library. */"; echo "GROUP ( libgcc_s.so.1 -lgcc )" ) > 32/libgcc_s.so
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
collect2: error: ld returned 1 exit status
Makefile:945: recipe for target 'libgcc_s.so' failed
make[5]: *** [libgcc_s.so] Error 1
make[5]: Leaving directory '/export/build/gnu/gcc-test/build-x86_64-linux/x86_64-pc-linux-gnu/32/libgcc'
Makefile:1161: recipe for target 'multi-do' failed
make[4]: *** [multi-do] Error 1
make[4]: Leaving directory '/export/build/gnu/gcc-test/build-x86_64-linux/x86_64-pc-linux-gnu/libgcc'
Makefile:118: recipe for target 'all-multi' failed
make[3]: *** [all-multi] Error 2
make[3]: Leaving directory '/export/build/gnu/gcc-test/build-x86_64-linux/x86_64-pc-linux-gnu/libgcc'
Makefile:13648: recipe for target 'all-target-libgcc' failed
make[2]: *** [all-target-libgcc] Error 2
make[2]: Leaving directory '/export/build/gnu/gcc-test/build-x86_64-linux'
Makefile:910: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/export/build/gnu/gcc-test/build-x86_64-linux'
1497.20user 87.24system 4:02.25elapsed 654%CPU (0avgtext+0avgdata 949100maxresident)k
136inputs+5002168outputs (5major+28630193minor)pagefaults 0swaps
Makefile:299: recipe for target 'all' failed
make: *** [all] Error 2

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 4, 2016

This seems to be a bug :)

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 4, 2016

A little bit better. Now I got

/export/build/gnu/gcc-test/build-x86_64-linux/./gcc/xgcc
-B/export/build/gnu/gcc-test/build-x86_64-linux/./gcc/
-B/usr/gcc-7.0.0/x86_64-pc-linux-gnu/bin/
-B/usr/gcc-7.0.0/x86_64-pc-linux-gnu/lib/ -isystem
/usr/gcc-7.0.0/x86_64-pc-linux-gnu/include -isystem
/usr/gcc-7.0.0/x86_64-pc-linux-gnu/sys-include -O2 -O2 -g -DIN_GCC -W
-Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes
-Wmissing-prototypes -Wold-style-definition -isystem ./include -fpic
-mlong-double-80 -DUSE_ELF_SYMVER -g -DIN_LIBGCC2 -fbuilding-libgcc
-fno-stack-protector -shared -nodefaultlibs -Wl,--soname=libgcc_s.so.1
-Wl,--version-script=libgcc.map -o 32/libgcc_s.so.1.tmp -O2 -g -m32 -B./
_muldi3_s.o _negdi2_s.o _lshrdi3_s.o _ashldi3_s.o _ashrdi3_s.o _cmpdi2_s.o
_ucmpdi2_s.o _clear_cache_s.o _trampoline_s.o __main_s.o _absvsi2_s.o
_absvdi2_s.o _addvsi3_s.o _addvdi3_s.o _subvsi3_s.o _subvdi3_s.o
_mulvsi3_s.o _mulvdi3_s.o _negvsi2_s.o _negvdi2_s.o _ctors_s.o _ffssi2_s.o
_ffsdi2_s.o _clz_s.o _clzsi2_s.o _clzdi2_s.o _ctzsi2_s.o _ctzdi2_s.o
_popcount_tab_s.o _popcountsi2_s.o _popcountdi2_s.o _paritysi2_s.o
_paritydi2_s.o _powisf2_s.o _powidf2_s.o _powixf2_s.o _powitf2_s.o
_mulsc3_s.o _muldc3_s.o _mulxc3_s.o _multc3_s.o _divsc3_s.o _divdc3_s.o
_divxc3_s.o _divtc3_s.o _bswapsi2_s.o _bswapdi2_s.o _clrsbsi2_s.o
_clrsbdi2_s.o _fixunssfsi_s.o _fixunsdfsi_s.o _fixunsxfsi_s.o _fixsfdi_s.o
_fixdfdi_s.o _fixxfdi_s.o _fixunssfdi_s.o _fixunsdfdi_s.o _fixunsxfdi_s.o
_floatdisf_s.o _floatdidf_s.o _floatdixf_s.o _floatundisf_s.o
_floatundidf_s.o _floatundixf_s.o _divdi3_s.o _moddi3_s.o _udivdi3_s.o
_umoddi3_s.o _udiv_w_sdiv_s.o _udivmoddi4_s.o cpuinfo_s.o tf-signs_s.o
sfp-exceptions_s.o addtf3_s.o divtf3_s.o eqtf2_s.o getf2_s.o letf2_s.o
multf3_s.o negtf2_s.o subtf3_s.o unordtf2_s.o fixtfsi_s.o fixunstfsi_s.o
floatsitf_s.o floatunsitf_s.o fixtfdi_s.o fixunstfdi_s.o floatditf_s.o
floatunditf_s.o extendsftf2_s.o extenddftf2_s.o extendxftf2_s.o
trunctfsf2_s.o trunctfdf2_s.o trunctfxf2_s.o enable-execute-stack_s.o
unwind-dw2_s.o unwind-dw2-fde-dip_s.o unwind-sjlj_s.o unwind-c_s.o
emutls_s.o libgcc.a -lc && rm -f 32/libgcc_s.so && if [ -f 32/libgcc_s.so.1
]; then mv -f 32/libgcc_s.so.1 32/libgcc_s.so.1.backup; else true; fi && mv
32/libgcc_s.so.1.tmp 32/libgcc_s.so.1 && (echo "/* GNU ld script"; echo "
Use the shared library, but some functions are only in"; echo " the static
library. */"; echo "GROUP ( libgcc_s.so.1 -lgcc )" ) > 32/libgcc_s.so
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
collect2: error: ld returned 1 exit status
Makefile:945: recipe for target 'libgcc_s.so' failed
make[5]: *** [libgcc_s.so] Error 1
make[5]: Leaving directory
'/export/build/gnu/gcc-test/build-x86_64-linux/x86_64-pc-linux-gnu/32/libgcc'
Makefile:1161: recipe for target 'multi-do' failed
make[4]: *** [multi-do] Error 1
make[4]: Leaving directory
'/export/build/gnu/gcc-test/build-x86_64-linux/x86_64-pc-linux-gnu/libgcc'
Makefile:118: recipe for target 'all-multi' failed
make[3]: *** [all-multi] Error 2
make[3]: Leaving directory
'/export/build/gnu/gcc-test/build-x86_64-linux/x86_64-pc-linux-gnu/libgcc'
Makefile:13648: recipe for target 'all-target-libgcc' failed
make[2]: *** [all-target-libgcc] Error 2
make[2]: Leaving directory '/export/build/gnu/gcc-test/build-x86_64-linux'
Makefile:910: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/export/build/gnu/gcc-test/build-x86_64-linux'
1497.20user 87.24system 4:02.25elapsed 654%CPU (0avgtext+0avgdata
949100maxresident)k
136inputs+5002168outputs (5major+28630193minor)pagefaults 0swaps
Makefile:299: recipe for target 'all' failed
make: *** [all] Error 2

Would you mind passing "--reproduce foo" and attaching foo.cpio to this bug?

@hjl-tools
Copy link
Contributor Author

Would you mind passing "--reproduce foo" and attaching foo.cpio to this bug?

File size is 5MB which is too big to upload.

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 4, 2016

We generally recommend to upload on any ftp/fileserver or using something like google drive/dropbox if the attachment exceeds bugzilla limit. Can you please do that if it's not too much hassle?

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 4, 2016

Would you mind passing "--reproduce foo" and attaching foo.cpio to this bug?

File size is 5MB which is too big to upload.

xz or bzip2 might put it under the limit. If you don't have a public place to put it, could you just email me the file?

@hjl-tools
Copy link
Contributor Author

A testcase
[hjl@gnu-tools-1 pr28414]$ make
./ld -m elf_i386 -shared -o x.so x.o
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
Makefile:29: recipe for target 'x.so' failed
make: *** [x.so] Error 1
[hjl@gnu-tools-1 pr28414]$

@hjl-tools
Copy link
Contributor Author

Created attachment 16690 [details]
A testcase

[hjl@gnu-tools-1 pr28414]$ make
./ld -m elf_i386 -shared -o x.so x.o
can't create dynamic relocation R_386_GOT32X against readonly segment
...
[hjl@gnu-tools-1 pr28414]$

[hjl@gnu-tools-1 pr28414]$ make LD=ld x.so
ld -m elf_i386 -shared -o x.so x.o
ld: x.o: direct GOT relocation R_386_GOT32X against `bar' without base register can not be used when making a shared object
ld: failed to set dynamic section sizes: File format not recognized
Makefile:28: recipe for target 'x.so' failed
make: *** [x.so] Error 1
[hjl@gnu-tools-1 pr28414]$

@hjl-tools
Copy link
Contributor Author

Another testcase
[hjl@gnu-tools-1 pr28414]$ make LD=ld z.so
gcc -B./ -m32 -fno-lto -c -o z.o z.S
ld -m elf_i386 -shared -o z.so z.o
[hjl@gnu-tools-1 pr28414]$ objdump -dw z.so

z.so: file format elf32-i386

Disassembly of section .text:

00000170 <_start>:
170: 8d 81 0c 00 00 00 lea 0xc(%ecx),%eax
176: 13 81 f8 ff ff ff adc -0x8(%ecx),%eax
17c: 03 99 f8 ff ff ff add -0x8(%ecx),%ebx
182: 23 89 f8 ff ff ff and -0x8(%ecx),%ecx
188: 3b 91 f8 ff ff ff cmp -0x8(%ecx),%edx
18e: 0b b9 f8 ff ff ff or -0x8(%ecx),%edi
194: 1b b1 f8 ff ff ff sbb -0x8(%ecx),%esi
19a: 2b a9 f8 ff ff ff sub -0x8(%ecx),%ebp
1a0: 33 a1 f8 ff ff ff xor -0x8(%ecx),%esp
1a6: 85 89 f8 ff ff ff test %ecx,-0x8(%ecx)
1ac: 8b 81 fc ff ff ff mov -0x4(%ecx),%eax
1b2: 13 81 fc ff ff ff adc -0x4(%ecx),%eax
1b8: 03 99 fc ff ff ff add -0x4(%ecx),%ebx
1be: 23 89 fc ff ff ff and -0x4(%ecx),%ecx
1c4: 3b 91 fc ff ff ff cmp -0x4(%ecx),%edx
1ca: 0b b9 fc ff ff ff or -0x4(%ecx),%edi
1d0: 1b b1 fc ff ff ff sbb -0x4(%ecx),%esi
1d6: 2b a9 fc ff ff ff sub -0x4(%ecx),%ebp
1dc: 33 a1 fc ff ff ff xor -0x4(%ecx),%esp
1e2: 85 89 fc ff ff ff test %ecx,-0x4(%ecx)
[hjl@gnu-tools-1 pr28414]$ rm -f z.so
[hjl@gnu-tools-1 pr28414]$ make z.so
./ld -m elf_i386 -shared -o z.so z.o
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
can't create dynamic relocation R_386_GOT32X against readonly segment
Makefile:31: recipe for target 'z.so' failed
make: *** [z.so] Error 1
[hjl@gnu-tools-1 pr28414]$

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 6, 2016

At least the reduced test case passes with r274690.

Can you give gcc another try?

@hjl-tools
Copy link
Contributor Author

r275003 gave me:

/export/build/gnu/gcc-lld/build-x86_64-linux/./gcc/xgcc -B/export/build/gnu/gcc-lld/build-x86_64-linux/./gcc/ -B/usr/gcc-7.0.0/x86_64-pc-linux-gnu/bin/ -B/usr/gcc-7.0.0/x86_64-pc-linux-gnu/lib/ -isystem /usr/gcc-7.0.0/x86_64-pc-linux-gnu/include -isystem /usr/gcc-7.0.0/x86_64-pc-linux-gnu/sys-include -O2 -g -O2 -DIN_GCC -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-format -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fpic -mlong-double-80 -DUSE_ELF_SYMVER -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -shared -nodefaultlibs -Wl,--soname=libgcc_s.so.1 -Wl,--version-script=libgcc.map -o ./libgcc_s.so.1.tmp -g -O2 -B./ _muldi3_s.o _negdi2_s.o _lshrdi3_s.o _ashldi3_s.o _ashrdi3_s.o _cmpdi2_s.o _ucmpdi2_s.o _clear_cache_s.o _trampoline_s.o __main_s.o _absvsi2_s.o _absvdi2_s.o _addvsi3_s.o _addvdi3_s.o _subvsi3_s.o _subvdi3_s.o _mulvsi3_s.o _mulvdi3_s.o _negvsi2_s.o _negvdi2_s.o _ctors_s.o _ffssi2_s.o _ffsdi2_s.o _clz_s.o _clzsi2_s.o _clzdi2_s.o _ctzsi2_s.o _ctzdi2_s.o _popcount_tab_s.o _popcountsi2_s.o _popcountdi2_s.o _paritysi2_s.o _paritydi2_s.o _powisf2_s.o _powidf2_s.o _powixf2_s.o _mulsc3_s.o _muldc3_s.o _mulxc3_s.o _divsc3_s.o _divdc3_s.o _divxc3_s.o _bswapsi2_s.o _bswapdi2_s.o _clrsbsi2_s.o _clrsbdi2_s.o _fixunssfsi_s.o _fixunsdfsi_s.o _fixunsxfsi_s.o _fixsfdi_s.o _fixdfdi_s.o _fixxfdi_s.o _fixunssfdi_s.o _fixunsdfdi_s.o _fixunsxfdi_s.o _floatdisf_s.o _floatdidf_s.o _floatdixf_s.o _floatundisf_s.o _floatundidf_s.o _floatundixf_s.o _divdi3_s.o _moddi3_s.o _udivdi3_s.o _umoddi3_s.o _udiv_w_sdiv_s.o _udivmoddi4_s.o cpuinfo_s.o sfp-exceptions_s.o addtf3_s.o divtf3_s.o multf3_s.o negtf2_s.o subtf3_s.o unordtf2_s.o fixtfsi_s.o fixunstfsi_s.o floatsitf_s.o floatunsitf_s.o fixtfdi_s.o fixunstfdi_s.o floatditf_s.o floatunditf_s.o fixtfti_s.o fixunstfti_s.o floattitf_s.o floatuntitf_s.o extendsftf2_s.o extenddftf2_s.o extendxftf2_s.o trunctfsf2_s.o trunctfdf2_s.o trunctfxf2_s.o getf2_s.o letf2_s.o eqtf2_s.o _divtc3_s.o _multc3_s.o _powitf2_s.o enable-execute-stack_s.o unwind-dw2_s.o unwind-dw2-fde-dip_s.o unwind-sjlj_s.o unwind-c_s.o emutls_s.o libgcc.a -lc && rm -f ./libgcc_s.so && if [ -f ./libgcc_s.so.1 ]; then mv -f ./libgcc_s.so.1 ./libgcc_s.so.1.backup; else true; fi && mv ./libgcc_s.so.1.tmp ./libgcc_s.so.1 && (echo "/* GNU ld script"; echo " Use the shared library, but some functions are only in"; echo " the static library. */"; echo "GROUP ( libgcc_s.so.1 -lgcc )" ) > ./libgcc_s.so
duplicate symbol: __letf2 in letf2_s.o and libgcc.a(letf2.o)
duplicate symbol: __eqtf2 in eqtf2_s.o and libgcc.a(eqtf2.o)

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 11, 2016

enable-execute-stack_s.o unwind-dw2_s.o unwind-dw2-fde-dip_s.o
unwind-sjlj_s.o unwind-c_s.o emutls_s.o libgcc.a -lc && rm -f ./libgcc_s.so
&& if [ -f ./libgcc_s.so.1 ]; then mv -f ./libgcc_s.so.1
./libgcc_s.so.1.backup; else true; fi && mv ./libgcc_s.so.1.tmp
./libgcc_s.so.1 && (echo "/* GNU ld script"; echo " Use the shared
library, but some functions are only in"; echo " the static library. */";
echo "GROUP ( libgcc_s.so.1 -lgcc )" ) > ./libgcc_s.so
duplicate symbol: __letf2 in letf2_s.o and libgcc.a(letf2.o)
duplicate symbol: __eqtf2 in eqtf2_s.o and libgcc.a(eqtf2.o)

Interesting. I fist thought it would be the archive member lookup logic, but the only reference to libgcc is clearly after the .o files.

Can you put the cpio created by "--reproduce foo" somewhere?

@hjl-tools
Copy link
Contributor Author

A testcase
[hjl@gnu-18 pr28414]$ make
./ld -shared -o x.so x.o y.o libfoo.a --version-script=libfoo.map
duplicate symbol: x in x.o and libfoo.a(foo.o)
Makefile:9: recipe for target 'x.so' failed
make: *** [x.so] Error 1

@silvasean
Copy link
Contributor

Further reduced (as lit test case)
Further reduced.

repro.tar is here: https://reviews.llvm.org/F3117406
(though the .s files in the attached patch are probably good enough to look at)

It seems that LLD does not recognize that %t.o defines foo.

test/ELF/Inputs/pr28414.s

.global foo
jmp foo

test/ELF/pr28414.s

// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/pr28414.s -o %t2.o
// RUN: echo "SOME_VERSION { global: *; };" > %t.map
// RUN: ld.lld %t.o %t2.o --version-script %t.map -o %t

.global _start
_start:
.symver _start, foo@@SOME_VERSION

@silvasean
Copy link
Contributor

Further reduced:

test/ELF/pr28414.s

// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
// RUN: echo "SOME_VERSION { global: *; };" > %t.map
// RUN: ld.lld %t.o --version-script %t.map -o %t

.global _start
.global bar
.symver _start, bar@@SOME_VERSION
_start:
jmp bar

@llvmbot
Copy link
Collaborator

llvmbot commented May 30, 2017

Patch: https://reviews.llvm.org/D33680

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 30, 2017

Further reduced:

test/ELF/pr28414.s

// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
// RUN: echo "SOME_VERSION { global: *; };" > %t.map
// RUN: ld.lld %t.o --version-script %t.map -o %t

.global _start
.global bar
.symver _start, bar@@SOME_VERSION
_start:
jmp bar

This case was fixed in r306813, not sure if it is enough to close whole PR.

@hjl-tools
Copy link
Contributor Author

Further reduced:

test/ELF/pr28414.s

// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
// RUN: echo "SOME_VERSION { global: *; };" > %t.map
// RUN: ld.lld %t.o --version-script %t.map -o %t

.global _start
.global bar
.symver _start, bar@@SOME_VERSION
_start:
jmp bar

This case was fixed in r306813, not sure if it is enough to close whole PR.

lld r306813 still fails.

@hjl-tools
Copy link
Contributor Author

A testcase
[hjl@gnu-skl-1 pr28414]$ make
cc -fpic -g -c -o x.o x.c
cc -fpic -g -c -o y.o y.c
cc -fpic -g -c -o foo.o foo.c
ar rv libfoo.a foo.o
ar: creating libfoo.a
a - foo.o
./ld -shared -o x.so x.o y.o libfoo.a --version-script=libfoo.map
./ld: error: duplicate symbol: x

defined at x.c:3
x.o:(x)
defined at foo.c:3
foo.o:(.text+0x0) in archive libfoo.a
Makefile:9: recipe for target 'x.so' failed
make: *** [x.so] Error 1
rm foo.o
[hjl@gnu-skl-1 pr28414]$

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 6, 2017

Created attachment 18735 [details]
A testcase

[hjl@gnu-skl-1 pr28414]$ make
cc -fpic -g -c -o x.o x.c
cc -fpic -g -c -o y.o y.c
cc -fpic -g -c -o foo.o foo.c
ar rv libfoo.a foo.o
ar: creating libfoo.a
a - foo.o
./ld -shared -o x.so x.o y.o libfoo.a --version-script=libfoo.map
./ld: error: duplicate symbol: x

defined at x.c:3
x.o:(x)
defined at foo.c:3
foo.o:(.text+0x0) in archive libfoo.a
Makefile:9: recipe for target 'x.so' failed
make: *** [x.so] Error 1
rm foo.o
[hjl@gnu-skl-1 pr28414]$

Thanks for sample ! Possible patch posted here: https://reviews.llvm.org/D35059

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 7, 2017

Created attachment 18735 [details]
A testcase

[hjl@gnu-skl-1 pr28414]$ make
cc -fpic -g -c -o x.o x.c
cc -fpic -g -c -o y.o y.c
cc -fpic -g -c -o foo.o foo.c
ar rv libfoo.a foo.o
ar: creating libfoo.a
a - foo.o
./ld -shared -o x.so x.o y.o libfoo.a --version-script=libfoo.map
./ld: error: duplicate symbol: x

defined at x.c:3
x.o:(x)
defined at foo.c:3
foo.o:(.text+0x0) in archive libfoo.a
Makefile:9: recipe for target 'x.so' failed
make: *** [x.so] Error 1
rm foo.o
[hjl@gnu-skl-1 pr28414]$

Thanks for sample ! Possible patch posted here:
https://reviews.llvm.org/D35059

Committed, r307364.

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 7, 2017

Created attachment 18735 [details]
A testcase

[hjl@gnu-skl-1 pr28414]$ make
cc -fpic -g -c -o x.o x.c
cc -fpic -g -c -o y.o y.c
cc -fpic -g -c -o foo.o foo.c
ar rv libfoo.a foo.o
ar: creating libfoo.a
a - foo.o
./ld -shared -o x.so x.o y.o libfoo.a --version-script=libfoo.map
./ld: error: duplicate symbol: x

defined at x.c:3
x.o:(x)
defined at foo.c:3
foo.o:(.text+0x0) in archive libfoo.a
Makefile:9: recipe for target 'x.so' failed
make: *** [x.so] Error 1
rm foo.o
[hjl@gnu-skl-1 pr28414]$

Thanks for sample ! Possible patch posted here:
https://reviews.llvm.org/D35059

Committed, r307364.

Is this fixed then?

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 7, 2017

Created attachment 18735 [details]
A testcase

[hjl@gnu-skl-1 pr28414]$ make
cc -fpic -g -c -o x.o x.c
cc -fpic -g -c -o y.o y.c
cc -fpic -g -c -o foo.o foo.c
ar rv libfoo.a foo.o
ar: creating libfoo.a
a - foo.o
./ld -shared -o x.so x.o y.o libfoo.a --version-script=libfoo.map
./ld: error: duplicate symbol: x

defined at x.c:3
x.o:(x)
defined at foo.c:3
foo.o:(.text+0x0) in archive libfoo.a
Makefile:9: recipe for target 'x.so' failed
make: *** [x.so] Error 1
rm foo.o
[hjl@gnu-skl-1 pr28414]$

Thanks for sample ! Possible patch posted here:
https://reviews.llvm.org/D35059

Committed, r307364.

Is this fixed then?

Initial issue is about 1 year old, honestly I am a bit lost what we are fixing here.
There were errors about "can not create dynamic relocation", "direct GOT relocation R_386_GOT32X against `bar' without base register can not be used when making a shared object" and recent errors about symbol versioning which were fixed.
May be worth to close this one and create separate PRs for each single issue if any exist still.

@hjl-tools
Copy link
Contributor Author

Is this fixed then?

Version info is wrong:

[hjl@gnu-skl-1 pr28414b]$ cat x.c
void
__netf2_shared (void)
{
}

asm (".globl __netf2_compat");
asm ("__netf2_compat = __netf2_shared");

asm (".symver __netf2_compat,__netf2@GCC_3.0");
asm (".symver __netf2_shared,__netf2@@GCC_4.3.0");
[hjl@gnu-skl-1 pr28414b]$ cat y.c
extern void __netf2 (void);

void
y (void)
{
__netf2 ();
}
[hjl@gnu-skl-1 pr28414b]$ cat libfoo.map
GCC_3.0
{
global:
__netf2;
local:
*;
};
GCC_4.3.0
{
global:
__netf2;
} GCC_3.0;
[hjl@gnu-skl-1 pr28414b]$ make
cc -fpic -g -c -o y.o y.c
cc -fpic -g -c -o x.o x.c
cc -fpic -g -c -o foo.o foo.c
ar rv libfoo.a foo.o
ar: creating libfoo.a
a - foo.o
./ld --version-script=libfoo.map -shared -o x.so y.o x.o libfoo.a
./ld: warning: duplicate symbol '__netf2' in version script
readelf -V x.so

Version symbols section '.gnu.version' contains 3 entries:
Addr: 0000000000000210 Offset: 0x000210 Link: 1 (.dynsym)
000: 0 (local) 3 (GCC_4.3.0) 2h(GCC_3.0)

Version definition section '.gnu.version_d' contains 3 entries:
Addr: 0x0000000000000218 Offset: 0x000218 Link: 5 (.dynstr)
000000: Rev: 1 Flags: BASE Index: 1 Cnt: 1 Name: x.so
0x001c: Rev: 1 Flags: none Index: 2 Cnt: 1 Name: GCC_3.0
0x0038: Rev: 1 Flags: none Index: 3 Cnt: 1 Name: GCC_4.3.0
rm foo.o
[hjl@gnu-skl-1 pr28414b]$

[hjl@gnu-skl-1 pr28414b]$ make LD=ld
cc -fpic -g -c -o y.o y.c
cc -fpic -g -c -o x.o x.c
cc -fpic -g -c -o foo.o foo.c
ar rv libfoo.a foo.o
ar: creating libfoo.a
a - foo.o
ld --version-script=libfoo.map -shared -o x.so y.o x.o libfoo.a
readelf -V x.so

Version symbols section '.gnu.version' contains 5 entries:
Addr: 0000000000000218 Offset: 0x000218 Link: 2 (.dynsym)
000: 0 (local) 2 (GCC_3.0) 3 (GCC_4.3.0) 3 (GCC_4.3.0)
004: 2h(GCC_3.0)

Version definition section '.gnu.version_d' contains 3 entries:
Addr: 0x0000000000000228 Offset: 0x000228 Link: 3 (.dynstr)
000000: Rev: 1 Flags: BASE Index: 1 Cnt: 1 Name: x.so
0x001c: Rev: 1 Flags: none Index: 2 Cnt: 1 Name: GCC_3.0
0x0038: Rev: 1 Flags: none Index: 3 Cnt: 2 Name: GCC_4.3.0
0x0054: Parent 1: GCC_3.0 <<<<<<<<<< This is missing from lld.
rm foo.o
[hjl@gnu-skl-1 pr28414b]$

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 7, 2017

Is this fixed then?

Version info is wrong:

0x0054: Parent 1: GCC_3.0 <<<<<<<<<< This is missing from lld.

So this is issue you are talking about and nothing else wrong here, right ? If so - that is probably not an issue, because we removed support of
version hierarchies intentionally. We implemented it at first in r273423 and then removed in r274345 (https://reviews.llvm.org/D21888), as them are not important.

@hjl-tools
Copy link
Contributor Author

Is this fixed then?

Version info is wrong:

0x0054: Parent 1: GCC_3.0 <<<<<<<<<< This is missing from lld.

So this is issue you are talking about and nothing else wrong here, right ?
If so - that is probably not an issue, because we removed support of
version hierarchies intentionally. We implemented it at first in r273423 and
then removed in r274345 (https://reviews.llvm.org/D21888), as them are not
important.

Is lld designed to be compatible with ld in term of symbol versioning?
If not, this bug can be closed and lld can't be a replacement of ld.
If yes, this bug should remain open.

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 10, 2017

Version info is wrong:

0x0054: Parent 1: GCC_3.0 <<<<<<<<<< This is missing from lld.

So this is issue you are talking about and nothing else wrong here, right ?
If so - that is probably not an issue, because we removed support of
version hierarchies intentionally. We implemented it at first in r273423 and
then removed in r274345 (https://reviews.llvm.org/D21888), as them are not
important.

Is lld designed to be compatible with ld in term of symbol versioning?
If not, this bug can be closed and lld can't be a replacement of ld.
If yes, this bug should remain open.

It should be mostly compatible, so we need a bit more information to decide.

According to https://www.akkadia.org/drepper/dsohowto.pdf

"The fourth point, the VERS 1.0 version being referred to in the VERS 2.0 definition, is not really important in symbol versioning. It marks the predecessor relationship of the two versions and it is done to maintain the similar- ities with Solaris’ internal versioning. It does not cause any problem it might in fact be useful to a human reader so predecessors should always be mentioned."

If that is still the case, then we will probably keep the difference from BFD. If something changed (or that paragraph was wrong to begin with), then we can change lld.

@hjl-tools
Copy link
Contributor Author

O tried removing parent version info in glibc by hand and it doesn't seem to
change run-time behavior for glibc tests. However,

Version definitions:
1 0x01 0x0865f4e6 libc.so.6
2 0x00 0x09691a75 GLIBC_2.2.5
3 0x00 0x09691a76 GLIBC_2.2.6
GLIBC_2.2.5
4 0x00 0x0d696913 GLIBC_2.3
GLIBC_2.2.6
5 0x00 0x09691972 GLIBC_2.3.2
GLIBC_2.3
6 0x00 0x09691973 GLIBC_2.3.3
GLIBC_2.3.2
7 0x00 0x09691974 GLIBC_2.3.4
GLIBC_2.3.3
8 0x00 0x0d696914 GLIBC_2.4
GLIBC_2.3.4
9 0x00 0x0d696915 GLIBC_2.5
GLIBC_2.4
10 0x00 0x0d696916 GLIBC_2.6
GLIBC_2.5
11 0x00 0x0d696917 GLIBC_2.7
GLIBC_2.6
12 0x00 0x0d696918 GLIBC_2.8
GLIBC_2.7
13 0x00 0x0d696919 GLIBC_2.9
GLIBC_2.8
14 0x00 0x06969190 GLIBC_2.10
GLIBC_2.9
15 0x00 0x06969191 GLIBC_2.11
GLIBC_2.10
16 0x00 0x06969192 GLIBC_2.12
GLIBC_2.11
17 0x00 0x06969193 GLIBC_2.13
GLIBC_2.12
18 0x00 0x06969194 GLIBC_2.14
GLIBC_2.13
19 0x00 0x06969195 GLIBC_2.15
GLIBC_2.14
20 0x00 0x06969196 GLIBC_2.16
GLIBC_2.15
21 0x00 0x06969197 GLIBC_2.17
GLIBC_2.16
22 0x00 0x06969198 GLIBC_2.18
GLIBC_2.17
23 0x00 0x06969182 GLIBC_2.22
GLIBC_2.18
24 0x00 0x06969183 GLIBC_2.23
GLIBC_2.22
25 0x00 0x06969184 GLIBC_2.24
GLIBC_2.23
26 0x00 0x0963cf85 GLIBC_PRIVATE
GLIBC_2.24

includes useful info for ABI versions. It shows that no versions are skipped.

@hjl-tools
Copy link
Contributor Author

BTW, I am OK to close this bug. But it is probably means that there will be
no -fuse-ld=lld support in GCC.

@emaste
Copy link
Member

emaste commented Jul 16, 2017

r307364 claims it fixes the last testcase from this PR, but that change breaks linking FreeBSD/arm64.

See details in https://reviews.llvm.org/rL307364

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 19, 2017

As of r308492 every issue listed here other than version references has been fixed.

Since dropping support for version references was an explicit decision, I am closing this for now.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla lld:ELF
Projects
None yet
Development

No branches or pull requests

4 participants