Bug 21782 - Fail to create static PIE with undefined weak symbols
Summary: Fail to create static PIE with undefined weak symbols
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.30
: P2 normal
Target Milestone: 2.29
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-17 18:11 UTC by H.J. Lu
Modified: 2017-08-25 17:03 UTC (History)
0 users

See Also:
Host:
Target: x86-64
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 2017-07-17 18:11:20 UTC
[hjl@gnu-6 ld]$ cat x.s
	.text
	.global _start
	.weak foo
_start:
	movl	foo(%rip), %eax
[hjl@gnu-6 ld]$ gcc -c x.s
[hjl@gnu-6 ld]$ ld -pie x.o
ld: x.o: relocation R_X86_64_PC32 against undefined symbol `foo' can not be used when making a shared object; recompile with -fPIC
ld: final link failed: Bad value
[hjl@gnu-6 ld]$
Comment 1 cvs-commit@gcc.gnu.org 2017-07-17 19:19:06 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=c5bb8910e80c6cd80c63541f86471c18375c8198

commit c5bb8910e80c6cd80c63541f86471c18375c8198
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Jul 17 12:17:59 2017 -0700

    x86-64: Limit PIC check to shared library build
    
    When building an executable, undefined symbols are error and undefined
    weak symbols are resolved to zero.  We only need to check PIC for
    building a shared library.
    
    bfd/
    
    	PR ld/21782
    	* elf64-x86-64.c (elf_x86_64_relocate_section): Limit PIC check
    	to shared library.
    
    ld/
    
    	PR ld/21782
    	* testsuite/ld-x86-64/pie3-nacl.d: New file.
    	* testsuite/ld-x86-64/pie3.d: Likewise.
    	* testsuite/ld-x86-64/pie3.s: Likewise.
    	* testsuite/ld-x86-64/x86-64.exp: Run pie3 and pie3-nacl.
Comment 2 cvs-commit@gcc.gnu.org 2017-07-17 19:41:39 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=8e85f840e1870b17dce6a5bdb330c5bcd85a022a

commit 8e85f840e1870b17dce6a5bdb330c5bcd85a022a
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Jul 17 12:40:57 2017 -0700

    Add missing ChangeLog entries for PR ld/21782 fix
Comment 3 cvs-commit@gcc.gnu.org 2017-07-17 19:54:54 UTC
The binutils-2_29-branch branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=89f512d3eca31aae9498430d3cdad6be8cf44c9a

commit 89f512d3eca31aae9498430d3cdad6be8cf44c9a
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Jul 17 12:17:59 2017 -0700

    x86-64: Limit PIC check to shared library build
    
    When building an executable, undefined symbols are error and undefined
    weak symbols are resolved to zero.  We only need to check PIC for
    building a shared library.
    
    bfd/
    
    	PR ld/21782
    	* elf64-x86-64.c (elf_x86_64_relocate_section): Limit PIC check
    	to shared library.
    
    ld/
    
    	PR ld/21782
    	* testsuite/ld-x86-64/pie3-nacl.d: New file.
    	* testsuite/ld-x86-64/pie3.d: Likewise.
    	* testsuite/ld-x86-64/pie3.s: Likewise.
    	* testsuite/ld-x86-64/x86-64.exp: Run pie3 and pie3-nacl.
    
    (cherry picked from commit c5bb8910e80c6cd80c63541f86471c18375c8198)
Comment 4 H.J. Lu 2017-07-17 19:58:32 UTC
Fixed for 2.29.
Comment 5 H.J. Lu 2017-08-25 17:03:28 UTC
Fixed.