Bug 19827 - Wrong relocation with defined symbol in PIE
Summary: Wrong relocation with defined symbol in PIE
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.26
: P2 normal
Target Milestone: 2.27
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 19807
  Show dependency treegraph
 
Reported: 2016-03-15 15:19 UTC by H.J. Lu
Modified: 2016-04-05 04:04 UTC (History)
2 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 2016-03-15 15:19:22 UTC
[hjl@gnu-6 pr19807b]$ cat x.s
	.text
	.global _start
_start:
	.dc.a _bss
[hjl@gnu-6 pr19807b]$ cat x.t
_bss = .;
[hjl@gnu-6 pr19807b]$ make
as --32  -o x.o x.s
./ld.2.26 -pie -m elf_i386 -T x.t x.o -o x
./ld.2.26 -shared -Bsymbolic -m elf_i386 -T x.t x.o -o y
readelf -r --dyn-syms --wide x

Relocation section '.rel.dyn' at offset 0x1054 contains 1 entries:
 Offset     Info    Type                Sym. Value  Symbol's Name
00000000  00000101 R_386_32               00000000   _bss
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This should be R_386_RELATIVE, the same as -shared -Bsymbolic.

Symbol table '.dynsym' contains 2 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000     0 NOTYPE  GLOBAL DEFAULT    1 _bss
readelf -r --dyn-syms --wide y

Relocation section '.rel.dyn' at offset 0x105c contains 1 entries:
 Offset     Info    Type                Sym. Value  Symbol's Name
00000000  00000008 R_386_RELATIVE        

Symbol table '.dynsym' contains 3 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000     0 NOTYPE  GLOBAL DEFAULT    1 _bss
     2: 00000000     0 NOTYPE  GLOBAL DEFAULT    1 _start
[hjl@gnu-6 pr19807b]$
Comment 1 cvs-commit@gcc.gnu.org 2016-03-15 18:49:48 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=4e0c91e45402ebf4215066e4a61143896e831049

commit 4e0c91e45402ebf4215066e4a61143896e831049
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Mar 15 11:46:51 2016 -0700

    Bind defined symbol locally in PIE
    
    Symbols defined in PIE should be bound locally, the same as -shared
    -Bsymbolic.
    
    bfd/
    
    	PR ld/19827
    	* elf32-i386.c (elf_i386_check_relocs): Bind defined symbol
    	locally in PIE.
    	(elf_i386_relocate_section): Likewise.
    	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
    	(elf_x86_64_relocate_section): Likewise.
    
    ld/
    
    	PR ld/19827
    	* testsuite/ld-i386/i386.exp: Run PR ld/19827 tests.
    	* testsuite/ld-x86-64/x86-64.exp: Likewise.
    	* testsuite/ld-i386/pr19827.rd: New file.
    	* testsuite/ld-i386/pr19827a.S: Likewise.
    	* testsuite/ld-i386/pr19827b.S: Likewise.
    	* testsuite/ld-x86-64/pr19827.rd: Likewise.
    	* testsuite/ld-x86-64/pr19827a.S: Likewise.
    	* testsuite/ld-x86-64/pr19827b.S: Likewise.
Comment 2 H.J. Lu 2016-03-15 19:16:49 UTC
Fixed on master so far.
Comment 3 H.J. Lu 2016-03-17 18:05:25 UTC
Fixed on master and 2.26 branch.
Comment 4 cvs-commit@gcc.gnu.org 2016-03-17 18:05:25 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=d193fe3cdcba616062980eb72e06c9a280287b5b

commit d193fe3cdcba616062980eb72e06c9a280287b5b
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Mar 17 10:48:03 2016 -0700

    Bind defined symbol locally in PIE
    
    Symbols defined in PIE should be bound locally, the same as -shared
    -Bsymbolic.
    
    Backport from master
    
    bfd/
    
    	PR ld/19827
    	* elf32-i386.c (elf_i386_check_relocs): Bind defined symbol
    	locally in PIE.
    	(elf_i386_relocate_section): Likewise.
    	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
    	(elf_x86_64_relocate_section): Likewise.
    
    ld/
    
    	PR ld/19827
    	* testsuite/ld-i386/i386.exp: Run PR ld/19827 tests.
    	* testsuite/ld-x86-64/x86-64.exp: Likewise.
    	* testsuite/ld-i386/pr19827.rd: New file.
    	* testsuite/ld-i386/pr19827a.S: Likewise.
    	* testsuite/ld-i386/pr19827b.S: Likewise.
    	* testsuite/ld-x86-64/pr19827.rd: Likewise.
    	* testsuite/ld-x86-64/pr19827a.S: Likewise.
    	* testsuite/ld-x86-64/pr19827b.S: Likewise.
Comment 5 H.J. Lu 2016-03-17 18:05:43 UTC
Fixed.
Comment 6 cvs-commit@gcc.gnu.org 2016-04-05 03:52:20 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=5fdf38727b4381d074dc929fd4b027a8779108fe

commit 5fdf38727b4381d074dc929fd4b027a8779108fe
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Apr 4 20:50:19 2016 -0700

    Add missing pr19827-nacl.rd for i386/x86-64 NaCl
    
    	PR ld/19827
    	* testsuite/ld-i386/pr19827-nacl.rd: New file.
    	* testsuite/ld-x86-64/pr19827-nacl.rd: Likewise.
Comment 7 cvs-commit@gcc.gnu.org 2016-04-05 04:04:14 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=c3789ba84ab6df25a43ef533172202c32a98181d

commit c3789ba84ab6df25a43ef533172202c32a98181d
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Apr 4 20:50:19 2016 -0700

    Add missing pr19827-nacl.rd for i386/x86-64 NaCl
    
    Backport from master
    
    	PR ld/19827
    	* testsuite/ld-i386/pr19827-nacl.rd: New file.
    	* testsuite/ld-x86-64/pr19827-nacl.rd: Likewise.