[hjl@gnu-tools-1 lea]$ cat x.S .data .space 0x100000000 .hidden foo .globl foo .type foo, @object foo: .long 20 .size foo, .-foo .text .globl _start .type _start, @function _start: movq foo@GOTPCREL(%rip), %rax .size _start, .-_start [hjl@gnu-tools-1 lea]$ make gcc -B./ -c -o x.o x.S ./ld -shared -o x.so x.o x.o: In function `_start': (.text+0x3): relocation truncated to fit: R_X86_64_PC32 against symbol `foo' defined in .data section in x.o Makefile:26: recipe for target 'x.so' failed make: *** [x.so] Error 1 [hjl@gnu-tools-1 lea]$
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=59cab532835904f368b0aa99267afba5fda5ded2 commit 59cab532835904f368b0aa99267afba5fda5ded2 Author: H.J. Lu <hjl.tools@gmail.com> Date: Wed Jun 24 10:13:55 2015 -0700 Don't convert R_X86_64_GOTPCREL if it will overflow When converting "mov foo@GOTPCREL(%rip), %reg" to "lea foo(%rip), %reg" with R_X86_64_PC32 relocation, it may overflow if the target section is more than 2GB away. This patch estimates distance between mov instruction and the target section. We convert R_X86_64_GOTPCREL to R_X86_64_PC32 only if their distance is less than 2GB. PR ld/18591 * elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Don't convert R_X86_64_GOTPCREL to R_X86_64_PC32 if it will cause relocation overflow.
This bug is still present in gold
(In reply to Rafael Ávila de Espíndola from comment #2) > This bug is still present in gold See PR 18609 and PR 18695.
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6ba2af251c40aea2483b3c9666667af364e68495 commit 6ba2af251c40aea2483b3c9666667af364e68495 Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Feb 2 06:36:52 2016 -0800 Add a testcase for PR ld/18591 PR ld/18591 * testsuite/ld-x86-64/pr18591.d: New file. * testsuite/ld-x86-64/pr18591.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run pr18591.
The binutils-2_26-branch branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=48953bf4f8b2f9e257903efbc89cb927b43f5317 commit 48953bf4f8b2f9e257903efbc89cb927b43f5317 Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Feb 2 06:36:52 2016 -0800 Add a testcase for PR ld/18591 Backport from master PR ld/18591 * testsuite/ld-x86-64/pr18591.d: New file. * testsuite/ld-x86-64/pr18591.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run pr18591.