Bug 18591 - Invalid R_X86_64_GOTPCREL -> R_X86_64_PC32 conversions
Summary: Invalid R_X86_64_GOTPCREL -> R_X86_64_PC32 conversions
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.26
: P2 normal
Target Milestone: 2.26
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-24 11:25 UTC by H.J. Lu
Modified: 2016-02-02 16:29 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2015-06-24 11:25:38 UTC
[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]$
Comment 1 Sourceware Commits 2015-06-24 17:23:40 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=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.
Comment 2 Rafael Ávila de Espíndola 2016-01-19 14:53:36 UTC
This bug is still present in gold
Comment 3 H.J. Lu 2016-01-19 14:58:38 UTC
(In reply to Rafael Ávila de Espíndola from comment #2)
> This bug is still present in gold

See PR 18609 and PR 18695.
Comment 4 Sourceware Commits 2016-02-02 14:37:59 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=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.
Comment 5 Sourceware Commits 2016-02-02 16:29:39 UTC
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.