Summary: | mips/ld: non-dynamic relocations refer to dynamic symbol | ||
---|---|---|---|
Product: | binutils | Reporter: | Aurelien Jarno <aurelien> |
Component: | ld | Assignee: | Maciej W. Rozycki <macro> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | bug-binutils, doko, rixed, rmansfield, rsandifo, tg |
Priority: | P2 | ||
Version: | 2.20 | ||
Target Milestone: | --- | ||
Host: | mips-unknown-linux-gnu | Target: | mips-unknown-linux-gnu |
Build: | mips-unknown-linux-gnu | Last reconfirmed: | |
Bug Depends on: | |||
Bug Blocks: | 26080 | ||
Attachments: |
testcase
New minimal testcase Testcase #3 (with .c .s .o/.so) Testcase with C code and makefile |
Description
Aurelien Jarno
2009-05-11 13:59:32 UTC
Created attachment 3931 [details]
testcase
The problem is that the .debug_info section in thr-objc_gc.o references thread_cancel. How did you compile that file? Created attachment 4488 [details]
New minimal testcase
New more minimal testcase. I used an external function to make sure
gcc doesn’t optimise the store to __progname away. I didn’t use any
header files for simplicity, but do assume your libc has __progname.
user@debian-mipsel:~ $ gcc -O2 -g -Wall tc.c
/usr/bin/ld: non-dynamic relocations refer to dynamic symbol
__progname@@GLIBC_2.0
/usr/bin/ld: failed to set dynamic section sizes: Bad value
collect2: ld returned 1 exit status
1|user@debian-mipsel:~ $ gcc -O2 -g -Wall tc.c -DUSE_EXTERN
user@debian-mipsel:~ $
This is Debian sid (a-g d-u’d from aurel32’s qemu image):
• binutils 2.20-4
• gcc 4:4.4.2-2
From working on the autossh package, this bug did not occur
with the versions in Debian lenny.
Hope this helps.
Works for me with FSF versions of GCC and binutils, and the version of GLIBC I have to hand. Please post a self-contained testcase that just needs a binutils build to run. Please also post the .s files. Created attachment 4550 [details] Testcase #3 (with .c .s .o/.so) (In reply to comment #4) > Works for me with FSF versions of GCC and binutils, and the version > of GLIBC I have to hand. Please post a self-contained testcase that > just needs a binutils build to run. Please also post the .s files. Okay: root@debian-mipsel:~ # gcc -O2 -g -S ya.c root@debian-mipsel:~ # gcc -O2 -g -c ya.s root@debian-mipsel:~ # gcc -O2 -g -S -fPIC yb.c root@debian-mipsel:~ # gcc -O2 -g -fPIC -shared -o libb.so yb.s root@debian-mipsel:~ # gcc -O2 -g -o y ya.o -L. -lb; echo =\> $? /usr/bin/ld: non-dynamic relocations refer to dynamic symbol xxprogname /usr/bin/ld: failed to set dynamic section sizes: Bad value collect2: ld returned 1 exit status => 1 Took me a while though. The “-g” is important. root@debian-mipsel:~ # gcc -v Using built-in specs. Target: mipsel-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.2-9' --with- bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable- languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable- multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib -- without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/ include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu -- enable-libstdcxx-debug --disable-libssp --enable-targets=all --enable- checking=release --build=mipsel-linux-gnu --host=mipsel-linux-gnu -- target=mipsel-linux-gnu Thread model: posix gcc version 4.4.3 20100108 (prerelease) (Debian 4.4.2-9) root@debian-mipsel:~ # ld -v GNU ld (GNU Binutils for Debian) 2.20 binutils 2.20-5 gcc-4.4 4.4.2-9 I believe this issue should be resolved by: http://gcc.gnu.org/ml/gcc-patches/2009-09/msg02070.html This is indeed a gcc issue, marking the bug on ld as invalid. I am reopening the bug as it appeared that the issue is not fixed in GCC 4.5 as I wrongly said here. It's just that our gcc was configured to default to -mplt which, in some cases, workaround the issue. To summarize the issue: - The issue is reproducible with any gcc version (tested 4.1, 4.3, 4.4, 4.5), provided that you use a binutils from after 2008-08-09. binutils from before 2008-08-08 works find with the same versions of gcc. - The issue can always be workarounded by not using -g - The issue can sometimes be workarounded by using -mplt - The issue is not fixed in HEAD as of 2010-09-14. Created attachment 4981 [details]
Testcase with C code and makefile
This new testcase doesn't obsolete the previous ones, but it's probably more
handy as it contains the C code and a Makefile
Aurelien, Coincidentally, I've been working on this problem for the last couple of days. I believe I have a fix ready that I plan to submit once it's gone through testing; probably even tonight. BTW, it's enough to pass "-z nocopyreloc" to LD to make this problem happen, regardless of GCC or GAS options used. Maciej Thanks for working on that. I have also spend some time trying to understand the problem. I have also written a patch by analysing the difference with other architecture, so I am not really sure it is correct: --- a/elfxx-mips.c +++ b/elfxx-mips.c @@ -8341,6 +8339,11 @@ _bfd_mips_elf_adjust_dynamic_symbol (str if (h->def_regular) return TRUE; + /* If there are no references to this symbol that do not use the + GOT, we don't need to generate a copy reloc. */ + if (!h->non_got_ref) + return TRUE; + /* There's also nothing more to do if we'll convert all relocations against this symbol into dynamic relocations. */ if (!hmips->has_static_relocs) At least it fixes the issue. Aurelien, I have posted my proposal now, including LD testsuite cases: http://sourceware.org/ml/binutils/2010-09/msg00216.html Maciej Thanks a lot for your work. I'll test it tomorrow on a few of the cases we have and keep you updated. I have built binutils including the patch linked in the previous comment. I confirm it fixes all the problem we currently have wrt this issue. Thanks. The fix for this issue will be included in the upcoming 2.21 release. CVSROOT: /cvs/src Module name: src Changes by: macro@sourceware.org 2011-11-29 12:42:10 Modified files: ld/testsuite : ChangeLog ld/testsuite/lib: ld-lib.exp Added files: ld/testsuite/ld-elf: comm-data.exp comm-data1.s comm-data1.sd comm-data2.rd comm-data2.s comm-data2.sd comm-data2.xd ld/testsuite/ld-mips-elf: comm-data.exp Log message: PR ld/10144 * lib/ld-lib.exp (run_ld_link_tests): Handle sources from other directories. (run_ld_link_exec_tests): Likewise. (run_cc_link_tests): Likewise. * ld-elf/comm-data1.sd: New test. * ld-elf/comm-data1.s: Source for the new test. * ld-elf/comm-data2.sd: New test. * ld-elf/comm-data2.rd: Likewise. * ld-elf/comm-data2.xd: Likewise. * ld-elf/comm-data2.s: Source for the new tests. * ld-elf/comm-data.exp: New file. * ld-mips-elf/comm-data.exp: Likewise. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1477&r2=1.1478 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/comm-data.exp.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/comm-data1.s.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/comm-data1.sd.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/comm-data2.rd.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/comm-data2.s.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/comm-data2.sd.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/comm-data2.xd.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-mips-elf/comm-data.exp.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/lib/ld-lib.exp.diff?cvsroot=src&r1=1.87&r2=1.88 |