Bug 19615 - [2.26 Regression] We can't no longer export a symbol in PIE with local binding
Summary: [2.26 Regression] We can't no longer export a symbol in PIE with local binding
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:
: 19538 19616 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-02-11 15:47 UTC by H.J. Lu
Modified: 2016-02-12 02:19 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-02-11 15:47:39 UTC
[hjl@gnu-6 export-1]$ cat x.s
	.text
	.globl _start
_start:
	ret

	.globl xyzzy	/* This symbol should be exported */
xyzzy:
	ret
	
	.section ".xyzzy_ptr","a"
xyzzy_ptr:
	.dc.a xyzzy
[hjl@gnu-6 export-1]$ make LD=ld
as --32 -o x.o x.s
ld -pie -Bsymbolic -E -m elf_i386 -o x x.o
nm -Dn x
0000019c T _start
0000019d T xyzzy <<<<<<<<<<< Must export it.
0000122c D __bss_start
0000122c D _edata
0000122c D _end
readelf -r x

Relocation section '.rel.dyn' at offset 0x194 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
0000019e  00000201 R_386_32          0000019d   xyzzy
                   ^^^^^^^^^^ Not bond locally.

[hjl@gnu-6 export-1]$ make LD=./ld-2.25
as --32 -o x.o x.s
./ld-2.25 -pie -Bsymbolic -E -m elf_i386 -o x x.o
nm -Dn x
0000019c T _start
0000019d T xyzzy
0000122c D __bss_start
0000122c D _edata
0000122c D _end
readelf -r x

Relocation section '.rel.dyn' at offset 0x194 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
0000019e  00000008 R_386_RELATIVE   
[hjl@gnu-6 export-1]$ 

Before binutils 2.26, "-pie -Bsymbolic -E" can be used to export
a symbol in PIE with local binding.  Linker manual says

'-Bsymbolic'
     When creating a shared library, bind references to global symbols
     to the definition within the shared library, if any.  Normally, it
     is possible for a program linked against a shared library to
     override the definition within the shared library.  This option is
     only meaningful on ELF platforms which support shared libraries.

"shared library" should be replaced with shared library or position
independent executable.
Comment 1 H.J. Lu 2016-02-11 23:21:55 UTC
*** Bug 19616 has been marked as a duplicate of this bug. ***
Comment 2 cvs-commit@gcc.gnu.org 2016-02-11 23:23:11 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=e20365c5d03f0f5eb341e04aafa88f30715e502e

commit e20365c5d03f0f5eb341e04aafa88f30715e502e
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Feb 11 10:28:33 2016 -0800

    Enable -Bsymbolic and -Bsymbolic-functions to PIE
    
    Before binutils 2.26, -Bsymbolic and -Bsymbolic-functions were also
    applied to PIE so that "ld -pie -Bsymbolic -E" can be used to export
    symbols in PIE with local binding.  This patch re-enables -Bsymbolic
    and -Bsymbolic-functions for PIE.
    
    	PR ld/19615
    	* ld.texinfo: Document -Bsymbolic and -Bsymbolic-functions for
    	PIE.
    	* lexsup.c (parse_args): Enable -Bsymbolic and
    	-Bsymbolic-functions for PIE.
    	* testsuite/ld-i386/i386.exp: Run pr19175.
    	* testsuite/ld-i386/pr19615.d: New file.
    	* testsuite/ld-i386/pr19615.s: Likewise.
    	* testsuite/ld-x86-64/pr19615.d: Likewise.
    	* testsuite/ld-x86-64/pr19615.s: Likewise.
Comment 3 cvs-commit@gcc.gnu.org 2016-02-11 23:25:35 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=21a90cf1dd5ddd22c2237b68fb58b8f532467a8c

commit 21a90cf1dd5ddd22c2237b68fb58b8f532467a8c
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Feb 11 15:24:33 2016 -0800

    Add ChangeLog for PR ld/19615 fix
Comment 4 H.J. Lu 2016-02-11 23:27:15 UTC
*** Bug 19538 has been marked as a duplicate of this bug. ***
Comment 5 cvs-commit@gcc.gnu.org 2016-02-12 02:19:08 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=1dab972d797c060e17229c2e10da01852ba82629

commit 1dab972d797c060e17229c2e10da01852ba82629
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Feb 11 15:31:15 2016 -0800

    Enable -Bsymbolic and -Bsymbolic-functions to PIE
    
    Before binutils 2.26, -Bsymbolic and -Bsymbolic-functions were also
    applied to PIE so that "ld -pie -Bsymbolic -E" can be used to export
    symbols in PIE with local binding.  This patch re-enables -Bsymbolic
    and -Bsymbolic-functions for PIE.
    
    Backport from master
    
    	PR ld/19615
    	* ld.texinfo: Document -Bsymbolic and -Bsymbolic-functions for
    	PIE.
    	* lexsup.c (parse_args): Enable -Bsymbolic and
    	-Bsymbolic-functions for PIE.
    	* testsuite/ld-i386/i386.exp: Run pr19615.
    	* testsuite/ld-i386/pr19615.d: New file.
    	* testsuite/ld-i386/pr19615.s: Likewise.
    	* testsuite/ld-x86-64/pr19615.d: Likewise.
    	* testsuite/ld-x86-64/pr19615.s: Likewise.
Comment 6 H.J. Lu 2016-02-12 02:19:47 UTC
Fixed for master and 2.26 branch.