Bug 17847 - Confusing linker error message
Summary: Confusing linker error message
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-01-15 17:14 UTC by H.J. Lu
Modified: 2015-01-15 19:12 UTC (History)
0 users

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-01-15 17:14:09 UTC
[hjl@gnu-6 pie-6]$ cat x.S
	.text
	.global _start
_start:
	movl	foo(%rip), %eax
[hjl@gnu-6 pie-6]$ make
gcc -B./    -c -o x.o x.S
./ld -o x -pie x.o
x.o: In function `_start':
(.text+0x2): undefined reference to `foo'
./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
make: *** [x] Error 1
[hjl@gnu-6 pie-6]$ 

Since foo is undefined, the second error message is confusing.
Comment 1 Sourceware Commits 2015-01-15 19:09:50 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=6333bc0dd6e92dd5a76ba0a6890e08db2a6f7a29

commit 6333bc0dd6e92dd5a76ba0a6890e08db2a6f7a29
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Jan 15 11:06:33 2015 -0800

    Don't complain about -fPIC for undefined symbol
    
    When building executable, undefined symbol is a fatal error.  We don't
    complain about -fPIC if the symbol is undefined.
    
    bfd/
    
    	PR ld/17847
    	* elf64-x86-64.c (elf_x86_64_relocate_section): Don't complain
    	about -fPIC if the symbol is undefined when building executable.
    
    ld/testsuite/
    
    	PR ld/17847
    	* ld-x86-64/pie1.d: New file.
    	* ld-x86-64/pie1.s: Likwise.
    	* ld-x86-64/x86-64.exp: Run pie1.
Comment 2 H.J. Lu 2015-01-15 19:12:30 UTC
Fixed.