[Bug ld/22471] New: libraries using version scripts can cause undefined reference to symbol '__bss_start'
https://sourceware.org/bugzilla/show_bug.cgi?id=22471 Bug ID: 22471 Summary: libraries using version scripts can cause undefined reference to symbol '__bss_start' Product: binutils Version: 2.30 (HEAD) Status: UNCONFIRMED Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: james410 at cowgill dot org.uk Target Milestone: --- Created attachment 10625 --> https://sourceware.org/bugzilla/attachment.cgi?id=10625=edit testcase tar.gz This bug arises when the following occurs: * An executable which references the __bss_start symbol (from the linker script) * links against a library using a version script so that __bss_start is not exported * in turn links against another "normal" library which does export __bss_start I this case ld will complain that the __bss_start symbol is undefined and that the "normal" library must be linked into the executable directly. I think this is incorrect and ld should be using the definition of the symbol from the linker script. Linking the "normal" library manually works around the bug, but this isn't nice because that library is an implementation detail that the executable shouldn't need to know about. The gold linker doesn't seem to be affected (for whatever reason). I've attached a testcase which illustrates the problem. It was first discovered while compiling mariadb (specifically mariabackup) on Debian MIPS. > $ ./build > + rm -f null.c > + touch null.c > + gcc -c -fPIC consume.c -o consume.o > + gcc -c -fPIC null.c -o null.o > + gcc -shared -Wl,--rpath=/user/jcowgill/workspace/binutils/test-bss-start > null.o -o libtest.so > + gcc -shared -Wl,--rpath=/user/jcowgill/workspace/binutils/test-bss-start > -Wl,--version-script=middle.ver null.o libtest.so -o libmiddle.so > + ld --rpath=/user/jcowgill/workspace/binutils/test-bss-start consume.o > libmiddle.so -o consume > ld: consume.o: undefined reference to symbol '__bss_start' > //user/jcowgill/workspace/binutils/test-bss-start/libtest.so: error adding > symbols: DSO missing from command line -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug gas/22127] New: as segfaults assembling invalid .reloc
https://sourceware.org/bugzilla/show_bug.cgi?id=22127 Bug ID: 22127 Summary: as segfaults assembling invalid .reloc Product: binutils Version: 2.30 (HEAD) Status: UNCONFIRMED Severity: normal Priority: P2 Component: gas Assignee: unassigned at sourceware dot org Reporter: james410 at cowgill dot org.uk Target Milestone: --- I just noticed that a source file containing an invalid .reloc involving local symbols causes as to segfault. This affects at least x86_64 and mips (but probably everything). This example was done for mips: $ cat test.s .reloc .La,R_MIPS_32,.Lb $ gdb --args ../build-mips/gas/as-new test.s [...] Reading symbols from ../build-mips/gas/as-new...done. (gdb) r Starting program: /srv/jcowgill-priv/workspace/binutils/build-mips/gas/as-new test.s test.s: Assembler messages: test.s:2: Error: invalid offset expression Program received signal SIGSEGV, Segmentation fault. 0x555fda4c in resolve_reloc_expr_symbols () at ../../binutils-gdb/gas/write.c:736 736 && (sec->use_rela_p (gdb) p sec $1 = (asection *) 0x0 (gdb) bt #0 0x555fda4c in resolve_reloc_expr_symbols () at ../../binutils-gdb/gas/write.c:736 #1 0x5560029b in write_object_file () at ../../binutils-gdb/gas/write.c:2034 #2 0x555cc61c in main (argc=2, argv=0x559f8560) at ../../binutils-gdb/gas/as.c:1314 -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/21900] New: [MIPS] linking shared library with -z defs --warn-unresolved-symbols emits null relocation
https://sourceware.org/bugzilla/show_bug.cgi?id=21900 Bug ID: 21900 Summary: [MIPS] linking shared library with -z defs --warn-unresolved-symbols emits null relocation Product: binutils Version: 2.29 Status: UNCONFIRMED Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: james410 at cowgill dot org.uk Target Milestone: --- Hi, On MIPS, using "-z defs" and "--warn-unresolved-symbols" while building a shared library with undefined symbols seems to cause all the relocations which use those symbols to be filled with null values. The executables then crash when executed because they load a garbage address into t9 and jump to it. Here is an example: > $ cat undef.c > int parent(void); > > int child(void) > { > return parent(); > } > > $ mips-linux-gnu-gcc -c -fPIC -O2 undef.c > $ ../build-mips/ld/ld-new -EB -shared -z defs --warn-unresolved-symbols > undef.o -o libundef.so > undef.o: In function `child': > undef.c:(.text+0xc): warning: undefined reference to `parent' > undef.c:(.text+0x10): warning: undefined reference to `parent' > $ mips-linux-gnu-objdump -dr libundef.so > > libundef.so: file format elf32-tradbigmips > > Disassembly of section .text: > > 0300 : > 300: 3c1c0002lui gp,0x2 > 304: 279c8030addiu gp,gp,-32720 > 308: 0399e021addugp,gp,t9 > 30c: 8f99lw t9,0(gp) > 310: 0328jr t9 > 314: nop > ... Note the line: > lwt9,0(gp) I would have expected a different offset than 0. If you remove the "-z defs" option to ld, a valid library is generated. This was observed while trying to debug a long standing issue where gnome-settings-daemon would immediately SIGBUS on startup. I have not personally tested old versions of binutils, but this bug suggests that it was broken on 2011 and a similar bug affects (or affected) ia64 as well: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=620874#40 Thanks, James -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug gas/21762] Use of STABS directives on MIPS causes label to be incorrectly marked as MIPS16
https://sourceware.org/bugzilla/show_bug.cgi?id=21762 --- Comment #1 from James Cowgill --- > Breakpoint 1, mips_compressed_mark_label (label=0x55a599e0) at > ../../binutils-gdb/gas/config/tc-mips.c:4389 > 4389gas_assert (HAVE_CODE_COMPRESSION); > (gdb) bt > #0 mips_compressed_mark_label (label=0x55a599e0) at > ../../binutils-gdb/gas/config/tc-mips.c:4389 > #1 0x55606353 in mips_compressed_mark_labels () at > ../../binutils-gdb/gas/config/tc-mips.c:4414 > #2 0x55601663 in mips_mark_labels () at > ../../binutils-gdb/gas/config/tc-mips.c:1944 > #3 0x556291e9 in s_mips_stab (type=100) at > ../../binutils-gdb/gas/config/tc-mips.c:17152 > #4 0x555eb667 in read_a_source_file (name=0x7fffe2e9 "test.s") > at ../../binutils-> gdb/gas/read.c:1146 > #5 0x555cc4ab in perform_an_assembly_pass (argc=0, > argv=0x559f6f08) at ../../binutils-> gdb/gas/as.c:1172 > #6 0x555cc75c in main (argc=2, argv=0x559f6f00) at > ../../binutils-gdb/gas/as.c:1297 > (gdb) p mips_opts.mips16 > $1 = -1 So the "if (mips_opts.mips16)" condition is true and the label gets marked as MIPS16. My guess is that one of the functions in the above call chain needs a call to "file_mips_check_options" adding to it. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug gas/21762] New: Use of STABS directives on MIPS causes label to be incorrectly marked as MIPS16
https://sourceware.org/bugzilla/show_bug.cgi?id=21762 Bug ID: 21762 Summary: Use of STABS directives on MIPS causes label to be incorrectly marked as MIPS16 Product: binutils Version: 2.28 Status: UNCONFIRMED Severity: normal Priority: P2 Component: gas Assignee: unassigned at sourceware dot org Reporter: james410 at cowgill dot org.uk Target Milestone: --- On MIPS, attempting to use a STABS directive (.stabs, .stabn or .stabd) before a .set directive has occured in the input file, causes any preceding labels to be marked as MIPS16. > $ cat test.s > main: > .stabd 0, 0, 0 > $ mips-linux-gnu-as test.s -o test.o > $ readelf --syms test.o | grep main > 4: 0 NOTYPE LOCAL DEFAULT [MIPS16] 1 main Passing -no-mips16 causes as to emit a micromips symbol instead: > $ mips-linux-gnu-as -no-mips16 test.s -o test.o > $ readelf --syms test.o | grep main > 4: 0 NOTYPE LOCAL DEFAULT [MICROMIPS] 1 main Using some noop .set directive before the .stabd works around the bug: > $ cat test.s > main: > .set mips0 > .stabd 0, 0, 0 > $ mips-linux-gnu-as test.s -o test.o > $ readelf --syms test.o | grep main > 4: 0 NOTYPE LOCAL DEFAULT1 main -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/21334] [MIPS] Undefined hidden symbols cause assertion failure bfd/elfxx-mips.c:3860
https://sourceware.org/bugzilla/show_bug.cgi?id=21334 James Cowgill changed: What|Removed |Added CC||ma...@linux-mips.org -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/21334] [MIPS] Undefined hidden symbols cause assertion failure bfd/elfxx-mips.c:3860
https://sourceware.org/bugzilla/show_bug.cgi?id=21334 James Cowgill changed: What|Removed |Added CC||hobbitalastair at yandex dot com -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/21334] [MIPS] Undefined hidden symbols cause assertion failure bfd/elfxx-mips.c:3860
https://sourceware.org/bugzilla/show_bug.cgi?id=21334 James Cowgill changed: What|Removed |Added Target||mips*-*-* -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/21334] New: [MIPS] Undefined hidden symbols cause assertion failure bfd/elfxx-mips.c:3860
https://sourceware.org/bugzilla/show_bug.cgi?id=21334 Bug ID: 21334 Summary: [MIPS] Undefined hidden symbols cause assertion failure bfd/elfxx-mips.c:3860 Product: binutils Version: 2.28 Status: UNCONFIRMED Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: james410 at cowgill dot org.uk Target Milestone: --- Originally from the Debian supermin package: https://buildd.debian.org/status/fetch.php?pkg=supermin=mipsel=5.1.17-7%2Bb1=1490538317=0 And possibly related to a bug mentioned in PR/21233 Attempting to link any object containing an undefined hidden symbol causes ld to give an assertion failure. $ cat test.c extern int a __attribute__((visibility("hidden"))); int x(void) { a = 1; } $ mipsel-linux-gnu-gcc -c test.c $ readelf --syms test.o Symbol table '.symtab' contains 14 entries: Num:Value Size TypeBind Vis Ndx Name 0: 0 NOTYPE LOCAL DEFAULT UND 1: 0 FILELOCAL DEFAULT ABS test.c 2: 0 SECTION LOCAL DEFAULT1 3: 0 SECTION LOCAL DEFAULT3 4: 0 SECTION LOCAL DEFAULT4 5: 0 SECTION LOCAL DEFAULT9 6: 0 SECTION LOCAL DEFAULT5 7: 0 SECTION LOCAL DEFAULT6 8: 0 SECTION LOCAL DEFAULT7 9: 0 SECTION LOCAL DEFAULT 10 10: 0 SECTION LOCAL DEFAULT 11 11: 60 FUNCGLOBAL DEFAULT1 x 12: 0 OBJECT GLOBAL DEFAULT UND _gp_disp 13: 0 NOTYPE GLOBAL HIDDEN UND a $ ../build-mips/ld/ld-new test.o ../build-mips/ld/ld-new: warning: cannot find entry symbol __start; defaulting to 004000f0 ../build-mips/ld/ld-new: BFD (GNU Binutils) 2.28.51.20170330 assertion fail ../../binutils-gdb/bfd/elfxx-mips.c:3860 test.o: In function `x': test.c:(.text+0x18): undefined reference to `a' The bug in supermin was actually caused by musl's use of this feature in __libc_start_main, so I suspect that nothing will be able to link against musl libc when using binutils 2.28. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug binutils/21233] Internal error, /usr/bin/ld: BFD (GNU Binutils for Debian) 2.28 assertion fail ../../bfd/elfxx-mips.c:3861
https://sourceware.org/bugzilla/show_bug.cgi?id=21233 --- Comment #7 from James Cowgill --- I think I see the problem, you need to pass -fPIE when building main.o to trigger the bug. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug binutils/21233] Internal error, /usr/bin/ld: BFD (GNU Binutils for Debian) 2.28 assertion fail ../../bfd/elfxx-mips.c:3861
https://sourceware.org/bugzilla/show_bug.cgi?id=21233 --- Comment #6 from James Cowgill --- I've attached the built objects. They were built with Debian's mips cross compiler: $ mipsel-linux-gnu-gcc -v Using built-in specs. COLLECT_GCC=mipsel-linux-gnu-gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/mipsel-linux-gnu/6/lto-wrapper Target: mipsel-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 6.3.0-8' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libsanitizer --disable-libquadmath --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-mipsel-cross/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-mipsel-cross --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-mipsel-cross --with-arch-directory=mips --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libgcj --enable-multiarch --enable-multilib --with-arch-32=mips32r2 --with-fp-32=xx --with-madd4=no --with-lxc1-sxc1=no --enable-targets=all --with-arch-64=mips64r2 --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=mipsel-linux-gnu --program-prefix=mipsel-linux-gnu- --includedir=/usr/mipsel-linux-gnu/include Thread model: posix gcc version 6.3.0 20170221 (Debian 6.3.0-8) -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug binutils/21233] Internal error, /usr/bin/ld: BFD (GNU Binutils for Debian) 2.28 assertion fail ../../bfd/elfxx-mips.c:3861
https://sourceware.org/bugzilla/show_bug.cgi?id=21233 --- Comment #5 from James Cowgill --- Created attachment 9923 --> https://sourceware.org/bugzilla/attachment.cgi?id=9923=edit alpha-lib.so built with GCC 6 -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug binutils/21233] Internal error, /usr/bin/ld: BFD (GNU Binutils for Debian) 2.28 assertion fail ../../bfd/elfxx-mips.c:3861
https://sourceware.org/bugzilla/show_bug.cgi?id=21233 --- Comment #4 from James Cowgill --- Created attachment 9922 --> https://sourceware.org/bugzilla/attachment.cgi?id=9922=edit main.o built with GCC 6 -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug binutils/21233] Internal error, /usr/bin/ld: BFD (GNU Binutils for Debian) 2.28 assertion fail ../../bfd/elfxx-mips.c:3861
https://sourceware.org/bugzilla/show_bug.cgi?id=21233 --- Comment #2 from James Cowgill --- This appears to be strongly related to PR/20828. I managed to reduce it down to this: $ cat alpha-lib.c void alpha(void) {} $ cat main.c void alpha(void); void beta(void) { alpha(); } $ gcc -shared alpha-lib.c -o alpha-lib.so $ gcc -c main.c $ ld -o broken --gc-sections main.o -u alpha alpha-lib.so Using an old binutils (2.27.90.20170124) without the fix for PR/20828 produces an invalid dyn-sym table: Symbol table '.dynsym' contains 10 entries: Num:Value Size TypeBind Vis Ndx Name 0: 0 NOTYPE LOCAL DEFAULT UND 1: 0001 0 SECTION GLOBAL DEFAULT ABS _DYNAMIC_LINKING 2: 000120010518 0 NOTYPE GLOBAL DEFAULT8 _edata 3: 0001200104f0 0 NOTYPE GLOBAL DEFAULT7 _fdata 4: 0001200104f0 0 OBJECT GLOBAL DEFAULT7 __RLD_MAP 5: 000120010518 0 NOTYPE GLOBAL DEFAULT8 _end 6: 000120010518 0 NOTYPE GLOBAL DEFAULT8 __bss_start 7: 000124db 0 NOTYPE GLOBAL DEFAULT6 _ftext 8: 000120010518 0 NOTYPE GLOBAL DEFAULT8 _fbss 9: 0 FUNCLOCAL DEFAULT UND alpha Using 2.28 crashes with the aforementioned assertion fail: ld: BFD (GNU Binutils for Debian) 2.28 assertion fail ../../bfd/elfxx-mips.c:3861 -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug binutils/21233] Internal error, /usr/bin/ld: BFD (GNU Binutils for Debian) 2.28 assertion fail ../../bfd/elfxx-mips.c:3861
https://sourceware.org/bugzilla/show_bug.cgi?id=21233 James Cowgill changed: What|Removed |Added CC||james410 at cowgill dot org.uk -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20828] GC-ed DSO symbols make corresponding symbols defined by a linker script local
https://sourceware.org/bugzilla/show_bug.cgi?id=20828 James Cowgill changed: What|Removed |Added Status|RESOLVED|REOPENED Resolution|FIXED |--- --- Comment #30 from James Cowgill --- Hi Maciej, Unfortunately this bug doesn't seem completely fixed. It still affects "symbol version" symbols (maybe they have a better name?). See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=844227#260 I can reproduce this if I compile both libstubs.so and liboutput.so from my original testcase with this version script: == test.ver === TEST { global: a; }; $ gcc -shared -Wl,--version-script=test.ver libstubs.c -o libstubs.so $ gcc -c stubs.c $ ld -shared --version-script=test.ver --gc-sections -o liboutput.so stubs.o libstubs.so == $ readelf --dyn-sym libstubs.so Symbol table '.dynsym' contains 18 entries: Num:Value Size TypeBind Vis Ndx Name 0: 0 NOTYPE LOCAL DEFAULT UND 1: 056c 0 SECTION LOCAL DEFAULT 12 2: 000107bc 0 NOTYPE GLOBAL DEFAULT 20 _edata 3: 0740 0 FUNCGLOBAL DEFAULT 14 _fini 4: 071036 FUNCGLOBAL DEFAULT 13 alpha 5: 00010780 0 NOTYPE GLOBAL DEFAULT 19 _fdata 6: 0 OBJECT GLOBAL DEFAULT ABS TEST 7: 000107d0 0 NOTYPE GLOBAL DEFAULT 21 _end 8: 000107bc 0 NOTYPE GLOBAL DEFAULT 21 __bss_start 9: 00018770 0 SECTION GLOBAL DEFAULT ABS _gp_disp 10: 05b0 0 NOTYPE GLOBAL DEFAULT 13 _ftext 11: 000107bc 0 NOTYPE GLOBAL DEFAULT 21 _fbss 12: 056c 0 FUNCGLOBAL DEFAULT 12 _init 13: 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable 14: 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses 15: 0 FUNCWEAK DEFAULT UND __gmon_start__ 16: 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab 17: 0 FUNCWEAK DEFAULT UND __cxa_finalize@GLIBC_2.2 (3) $ readelf --dyn-sym liboutput.so Symbol table '.dynsym' contains 11 entries: Num:Value Size TypeBind Vis Ndx Name 0: 0 NOTYPE LOCAL DEFAULT UND 1: 0340 0 SECTION LOCAL DEFAULT8 2: 00010390 0 NOTYPE GLOBAL DEFAULT9 _fdata 3: 034036 FUNCGLOBAL DEFAULT8 psi 4: 0 OBJECT LOCAL DEFAULT ABS TEST 5: 0340 0 NOTYPE GLOBAL DEFAULT8 _ftext 6: 00010398 0 NOTYPE GLOBAL DEFAULT9 __bss_start 7: 036436 FUNCGLOBAL DEFAULT8 omega 8: 00010398 0 NOTYPE GLOBAL DEFAULT9 _edata 9: 00010398 0 NOTYPE GLOBAL DEFAULT9 _end 10: 00010398 0 NOTYPE GLOBAL DEFAULT9 _fbss As you can see, there is a misplaced LOCAL symbol in liboutput.so. Thanks, James -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug gold/21054] [MIPS] Forced local symbol rearranging messes up GOT
https://sourceware.org/bugzilla/show_bug.cgi?id=21054 James Cowgill changed: What|Removed |Added Attachment #9754|0 |1 is obsolete|| --- Comment #1 from James Cowgill --- Created attachment 9757 --> https://sourceware.org/bugzilla/attachment.cgi?id=9757=edit testcase v2 Fix testcase to add missing section attribute. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug gold/21054] New: [MIPS] Forced local symbol rearranging messes up GOT
https://sourceware.org/bugzilla/show_bug.cgi?id=21054 Bug ID: 21054 Summary: [MIPS] Forced local symbol rearranging messes up GOT Product: binutils Version: 2.29 (HEAD) Status: UNCONFIRMED Severity: normal Priority: P2 Component: gold Assignee: ccoutant at gmail dot com Reporter: james410 at cowgill dot org.uk CC: ian at airs dot com Target Milestone: --- Created attachment 9754 --> https://sourceware.org/bugzilla/attachment.cgi?id=9754=edit gold-mips-forced-local.c Originally this systemd bug in Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=851412 The attached testcase immediately segfaults when run after being compiled by gold on mips. It works fine when the bfd linker is used. Compile with: gcc -Wl,-version-script=blank.ver -fuse-ld=gold gold-mips-forced-local.c With blank.ver hiding all symbols: { local: *; }; The segfault occurs in __start when it tries to call __libc_start_main. It instead calls a NULL pointer. Looking in GDB the GOT has definitely been initialized but the pointer to __libc_start_main occurs 8 bytes (2 words) before the GOT entry actually accessed in __start. In Debian, the bug manifested in any executable which loaded libsystemd.so by segfaulting on exit. The segfault occured in __do_global_dtors_aux when it tried to call __cxa_finalize but instead called some other random function from libsystemd. Aurélien Jarno bisected this bug to commit c4d5a76223f74930add9014f2a77339eb80b737c: Author: Cary Coutant <ccout...@gmail.com> Date: Thu Dec 22 14:06:24 2016 -0800 Fix placement of forced local symbols in the dynamic symbol table. Gold was not placing forced-local symbols (e.g., hidden visibility) at the front of the dynamic symbol table, or including them in the count of local symbols recorded in the .dynsym section's sh_info field. In my testcase I expect the __start_ASECTION and __stop_ASECTION symbols are forced local and were affected by this (also fits the GOT being offset by 2 words). On MIPS they will require GOT entries as they are used by num_ptrs, but presumably moving them around the dynamic symbol table screwed the GOT up on MIPS. I know that on MIPS, the dynamic symbol table is used as an index into the GOT but I don't have a lot of in depth knowledge on it. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20828] [MIPS] produces invalid dynamic symbol table when --gc-sections is used since PR ld/13177 fix
https://sourceware.org/bugzilla/show_bug.cgi?id=20828 --- Comment #16 from James Cowgill --- (In reply to Maciej W. Rozycki from comment #15) > NB while I'll implement the missing dynsym ordering case for the MIPS > backend so that it follows the ELF gABI even if weird output is somehow > produced by the generic BFD ELF linker I maintain that dropping symbols > that have been GC-ed (but not other forced local ones) is the right > solution. So you you think the second patch is wrong (since it drops all forced local symbols)? -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20828] [MIPS] produces invalid dynamic symbol table when --gc-sections is used since PR ld/13177 fix
https://sourceware.org/bugzilla/show_bug.cgi?id=20828 --- Comment #10 from James Cowgill --- (In reply to Maciej W. Rozycki from comment #8) > By the MIPS psABI's definition you shall not have external GGA_NONE > symbols as any GGA_NONE symbols will be assigned to the local GOT part, > whose entries are only relocated by the base address at the load time. > Symbols in the GGA_NONE class will normally not have dynsym entries, > except from selected section symbols. The psABI says: The dynamic symbol table, like all ELF symbol tables, is divided into local and global parts. The global part of the dynamic symbol table is further divided into two parts: symbols that do not have GOT entries associated with them and symbols that do have GOT entries associated with them. Surly this implies that it is legitimate for an external symbol to be GGA_NONE? The case illustrated here where a symbol is defined but not used within a shared library seems like a good use case for this. Since LOCAL symbols must be GGA_NONE, the local symbol handler in my patch could probably be simplified a little. [...] > I agree the presence of (non-section) local symbols in the dynsym table > is a generic issue, and given that `elf_gc_sweep_symbol' appears to be > the only place where they are created I think that rather than > adjusting this piece of code to assign these symbols to the GGA_NONE > class it will make sense to discard them altogether. Unless there is > an actual need for them, that is, which I yet need to be told about. > FAOD it is not incorrect to have them -- it is just useless. It breaks the ld-elf/provide-hidden testcase, but that can be adjusted to not look for local dynamic symbols. This patch implements what you suggest (dropping symbols defined in the linker script dynamic symbol table if they are definitely local) and on its own fixes this bug as well. --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -669,7 +669,8 @@ bfd_elf_record_link_assignment (bfd *output_bfd, || h->ref_dynamic || bfd_link_dll (info) || elf_hash_table (info)->is_relocatable_executable) - && h->dynindx == -1) + && h->dynindx == -1 + && h->forced_local == 0) { if (! bfd_elf_link_record_dynamic_symbol (info, h)) return FALSE; -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20828] [MIPS] produces invalid dynamic symbol table when --gc-sections is used since PR ld/13177 fix
https://sourceware.org/bugzilla/show_bug.cgi?id=20828 --- Comment #9 from James Cowgill --- I added some debug code ontop of my patch and it seems that at the time the dynamic symbol table indexes are allocated, all the symbols are GGA_NONE. debug: _fdata, LOCAL, GGA_NONE debug: _ftext, LOCAL, GGA_NONE debug: __bss_start, LOCAL, GGA_NONE debug: _edata, LOCAL, GGA_NONE debug: _end, LOCAL, GGA_NONE debug: _fbss, LOCAL, GGA_NONE debug: psi, GLOBAL, GGA_NONE debug: omega, GLOBAL, GGA_NONE Even when --gc-sections is removed all the symbols are GGA_NONE (although they are all now GLOBAL). Clearly at least psi and omega are external symbols. If I adjust stubs.c a bit, it seems a symbol is only ever GGA_NORMAL if it actually needs a GOT entry (eg if I call psi from omega, psi becomes GGA_NORMAL but omega remains GGA_NONE). -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20828] [MIPS] produces invalid dynamic symbol table when --gc-sections is used since PR ld/13177 fix
https://sourceware.org/bugzilla/show_bug.cgi?id=20828 --- Comment #7 from James Cowgill --- (In reply to Maciej W. Rozycki from comment #6) > Do we need to have these hidden symbols in the dynsym table at all in > the first place? It looks like unnecessary clutter to me, they won't > ever be used for anything as their references have been gc-ed. Or am > I missing anything -- can someone confirm my conclusion or contradict > it by providing a use case? Possibly not, although it looks like a generic issue - these symbols appear when the test is run on x86_64. > If we do need these symbols in the dynsym table, then I think we just > need to set GGA_NONE for them correctly as they're being hidden and the > existing dynsym index selection code will DTRT. I don't think doing this will ensure they always appear before the other GGA_NONE global symbols. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20828] [MIPS] produces invalid dynamic symbol table when --gc-sections is used since PR ld/13177 fix
https://sourceware.org/bugzilla/show_bug.cgi?id=20828 --- Comment #2 from James Cowgill --- Created attachment 9649 --> https://sourceware.org/bugzilla/attachment.cgi?id=9649=edit patch attempt 1 So I had a go at fixing this. The patch basically does an extra pass to assign indexes to all the forced_local symbols first and the original code handles the rest of the symbols. It fixes my testcase and the original mesa bug in Debian. As I'm not too familiar with the internals of binutils, I'm not totally sure this is right. Is checking forced_local enough? -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20828] New: [MIPS] produces invalid dynamic symbol table when --gc-sections is used since PR ld/13177 fix
https://sourceware.org/bugzilla/show_bug.cgi?id=20828 Bug ID: 20828 Summary: [MIPS] produces invalid dynamic symbol table when --gc-sections is used since PR ld/13177 fix Product: binutils Version: 2.27 Status: UNCONFIRMED Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: james410 at cowgill dot org.uk Target Milestone: --- Originally from Debian: https://bugs.debian.org/844357 Related: https://bugs.debian.org/844227 On MIPS, it is possible for ld to generate an invalid symbol table if --gc-sections is used when linking. This can be seen in all versions of Debian's libGL.so.1 since jessie. Steps to reproduce: $ cat libstubs.c void alpha(void) {} $ cat stubs.c void psi(void) {} void omega(void) {} $ gcc -shared libstubs.c -o libstubs.so $ gcc -c stubs.c $ ld -shared --gc-sections -o liboutput.so stubs.o libstubs.so After doing the above, the dynamic symbol table contains: $ readelf --dyn-sym liboutput.so Symbol table '.dynsym' contains 10 entries: Num:Value Size TypeBind Vis Ndx Name 0: 0 NOTYPE LOCAL DEFAULT UND 1: 0430 0 SECTION LOCAL DEFAULT6 2: 00010490 0 NOTYPE LOCAL DEFAULT7 _end 3: 00010490 0 NOTYPE LOCAL DEFAULT7 __bss_start 4: 0430 0 NOTYPE LOCAL DEFAULT6 _ftext 5: 00010490 0 NOTYPE LOCAL DEFAULT7 _edata 6: 045436 FUNCGLOBAL DEFAULT6 omega 7: 00010490 0 NOTYPE LOCAL DEFAULT7 _fbss 8: 043036 FUNCGLOBAL DEFAULT6 psi 9: 00010480 0 NOTYPE LOCAL DEFAULT7 _fdata This is clearly invalid because there are LOCAL symbols which appear after GLOBAL symbols. The bug only appears if --gc-sections is used - without this flag the "good" symbol table looks like this: Symbol table '.dynsym' contains 10 entries: Num:Value Size TypeBind Vis Ndx Name 0: 0 NOTYPE LOCAL DEFAULT UND 1: 0450 0 SECTION LOCAL DEFAULT7 2: 000104b0 0 NOTYPE GLOBAL DEFAULT8 _end 3: 000104b0 0 NOTYPE GLOBAL DEFAULT8 __bss_start 4: 0450 0 NOTYPE GLOBAL DEFAULT7 _ftext 5: 000104b0 0 NOTYPE GLOBAL DEFAULT8 _edata 6: 047436 FUNCGLOBAL DEFAULT7 omega 7: 000104b0 0 NOTYPE GLOBAL DEFAULT8 _fbss 8: 045036 FUNCGLOBAL DEFAULT7 psi 9: 000104a0 0 NOTYPE GLOBAL DEFAULT8 _fdata I have bisected this bug to the following commit. Binutils 2.22 in Debian wheezy was also OK because the commit was reverted in the binutils 2.22 branch. commit 1a766c6843ce0005fee23633b3b30c98e81a7b07 Author: H.J. Lu <hjl.to...@gmail.com> Date: Fri Sep 16 01:17:16 2011 + Also hide symbols without PLT nor GOT references. bfd/ 2011-09-15 H.J. Lu <hongjiu...@intel.com> PR ld/13177 * elflink.c (elf_gc_sweep_symbol): Also hide symbols without PLT nor GOT references. While this bug is quite old, it was only found very recently due to a change in the calculation of the .dynsym sh_info value in: commit 90ac242072dc68ad454228868b0f1c8e10f9 Author: Alan Modra <amo...@gmail.com> Date: Sat Aug 13 00:03:43 2016 +0930 Correct .dynsym sh_info The combination of this commit along with the above bug is causing lots of undefined references when linking to libGL in Debian (which is compiled using --gc-sections). -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug gas/20649] [MIPS] Can't find matching LO16 reloc
https://sourceware.org/bugzilla/show_bug.cgi?id=20649 --- Comment #4 from James Cowgill --- Maciej, is it OK for me to ask for your patch to be applied to the Debian binutils package? -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/17560] mips: assertion failure with --as-needed + weak + hidden main function
https://sourceware.org/bugzilla/show_bug.cgi?id=17560 James Cowgill changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #1 from James Cowgill --- This seems to be fixed now as a result of the ELF hidden symbols fix on MIPS. Specifically fixed by: 1f599d0e7b5039c814731293043e247304ec006b ("ELF/LD: Avoid producing hidden and internal dynamic symbols") -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug gas/20649] [MIPS] Can't find matching LO16 reloc
https://sourceware.org/bugzilla/show_bug.cgi?id=20649 --- Comment #3 from James Cowgill --- Thanks for the patch, it seems to work. I ran a full build of blender where the bug originally came from and it builds fine now. James -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug gas/20649] [MIPS] Can't find matching LO16 reloc
https://sourceware.org/bugzilla/show_bug.cgi?id=20649 --- Comment #1 from James Cowgill --- Created attachment 9541 --> https://sourceware.org/bugzilla/attachment.cgi?id=9541=edit src.s Assembly output from compiling the testcase with: mipsel-linux-gnu-g++-6 -O2 -fPIC -S src.cpp -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug gas/20649] New: [MIPS] Can't find matching LO16 reloc
https://sourceware.org/bugzilla/show_bug.cgi?id=20649 Bug ID: 20649 Summary: [MIPS] Can't find matching LO16 reloc Product: binutils Version: 2.27 Status: UNCONFIRMED Severity: normal Priority: P2 Component: gas Assignee: unassigned at sourceware dot org Reporter: james410 at cowgill dot org.uk Target Milestone: --- Created attachment 9540 --> https://sourceware.org/bugzilla/attachment.cgi?id=9540=edit src.cpp Debian bug: https://bugs.debian.org/834147 Moved from GCC: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77300 When compiling the attached testcase with: mipsel-linux-gnu-g++-6 -O2 -fPIC src.cpp I get: /usr/lib/gcc-cross/mipsel-linux-gnu/6/../../../../mipsel-linux-gnu/bin/ld: /tmp/ccqVuMV3.o: Can't find matching LO16 reloc against `_ZN1HIiE5m_fn4ERK1G.isra.1' for R_MIPS_GOT16 at 0xcc in section `.text._ZN1HIiE5m_fn5ERK1G[_ZN1HIiE5m_fn5ERK1G]' Originally I thought this was a bug in how GCC generates GOT16 relocations but it turns out it's probably a bug in GAS instead. See the GCC bug for more information. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/18076] New: mips: segfault in _bfd_elf_gc_mark_rsec
https://sourceware.org/bugzilla/show_bug.cgi?id=18076 Bug ID: 18076 Summary: mips: segfault in _bfd_elf_gc_mark_rsec Product: binutils Version: 2.25 Status: NEW Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: james410 at cowgill dot org.uk Created attachment 8162 -- https://sourceware.org/bugzilla/attachment.cgi?id=8162action=edit lj_vm.s In Debian, compiling trafficserver 5.2.0 causes ld to segfault in _bfd_elf_gc_mark_rsec. Debian log: https://buildd.debian.org/status/fetch.php?pkg=trafficserverarch=mipselver=5.2.0-3stamp=1425296797 I managed to reduce this down to one assembly file (attached) which causes ld to segfault in the same place when run like this: as -o lj_vm.o lj_vm.s ld -L/usr/lib/mipsel-linux-gnu -v lj_vm.o -lc (Replace the -L directory with wherever libc.so is located) Affects at least 2.25 and latest HEAD. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/18076] mips: segfault in _bfd_elf_gc_mark_rsec
https://sourceware.org/bugzilla/show_bug.cgi?id=18076 --- Comment #1 from James Cowgill james410 at cowgill dot org.uk --- Created attachment 8163 -- https://sourceware.org/bugzilla/attachment.cgi?id=8163action=edit backtrace -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/17560] New: mips: assertion failure with --as-needed + weak + hidden main function
https://sourceware.org/bugzilla/show_bug.cgi?id=17560 Bug ID: 17560 Summary: mips: assertion failure with --as-needed + weak + hidden main function Product: binutils Version: 2.26 (HEAD) Status: NEW Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: james410 at cowgill dot org.uk With the combination of: - MIPS - Linking with --as-needed - The main() function being declared hidden - Linking with a shared library which references main() declared as weak Causes this error: /home/jcowgill/binutils-gdb/ld/.libs/lt-ld-new: BFD (GNU Binutils) 2.25.51.20141105 assertion fail elf-strtab.c:254 /home/jcowgill/binutils-gdb/ld/.libs/lt-ld-new: BFD (GNU Binutils) 2.25.51.20141105 assertion fail elf-strtab.c:272 test-obj.c __attribute__((visibility (hidden))) int main(void) { return 42; } test-dso.c __attribute__((weak)) int main(void); int blob(void) { return main(); } compile with gcc -c test-obj.c gcc -shared -fPIC -o test-dso.so test-dso.c gcc -Wl,--as-needed test-obj.o test-dso.so debian bug: https://bugs.debian.org/767863 -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/15428] Linker crash on R_MIPS_GOT_PAGE relocations referring to absolute symbols
https://sourceware.org/bugzilla/show_bug.cgi?id=15428 --- Comment #3 from James Cowgill james410 at cowgill dot org.uk --- There might already be an (at least related) test for this. If I revert the commit I mentioned I get: ... Running /home/jcowgill/binutils-gdb/ld/testsuite/ld-mips-elf/mips-elf.exp ... FAIL: MIPS magic __ehdr_start symbol test 1 (n32) FAIL: MIPS magic __ehdr_start symbol test 1 (n64) ... But with current master I get: ... Running /home/jcowgill/binutils-gdb/ld/testsuite/ld-mips-elf/mips-elf.exp ... KPASS: MIPS magic __ehdr_start symbol test 2 (n32) (PRMS ld/15428) KPASS: MIPS magic __ehdr_start symbol test 2 (n64) (PRMS ld/15428) ... -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/15428] Linker crash on R_MIPS_GOT_PAGE relocations referring to absolute symbols
https://sourceware.org/bugzilla/show_bug.cgi?id=15428 James Cowgill james410 at cowgill dot org.uk changed: What|Removed |Added CC||james410 at cowgill dot org.uk --- Comment #1 from James Cowgill james410 at cowgill dot org.uk --- This seems to have been fixed in b75d42bce5609eff (Fix mips segfault on GOT access of absolute symbol) -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils