Bug 14525 - __executable_start isn't defined for PIE
Summary: __executable_start isn't defined for PIE
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.24
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-28 13:33 UTC by H.J. Lu
Modified: 2017-02-03 09:38 UTC (History)
1 user (show)

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


Attachments
A patch (317 bytes, patch)
2012-08-28 14:01 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2012-08-28 13:33:52 UTC
[hjl@gnu-6 foo]$ cat x.c
#include <stdio.h>
extern void *__executable_start;
 
int main() {
  printf("%p\n",__executable_start);
  return 0;
}
[hjl@gnu-6 foo]$ make
gcc -B./ -pie -fPIE   -c -o x.o x.c
gcc -B./ -pie -fPIE -o x x.o
x.o: In function `main':
x.c:(.text+0x7): undefined reference to `__executable_start'
collect2: error: ld returned 1 exit status
make: *** [x] Error 1
[hjl@gnu-6 foo]$ 

It works with gold.
Comment 1 H.J. Lu 2012-08-28 14:01:14 UTC
Created attachment 6615 [details]
A patch
Comment 2 Pavel Chupin 2012-08-29 14:35:44 UTC
I confirm that patch resolves the issue.
Comment 3 Sourceware Commits 2012-08-31 02:52:18 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2012-08-31 02:52:14

Modified files:
	ld             : ChangeLog 
	ld/scripttempl : elf.sc 
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-elf: elf.exp 
Added files:
	ld/testsuite/ld-elf: pr14525.c pr14525.out 

Log message:
	Provide __executable_start for PIE
	
	ld/
	
	PR ld/14525
	* scripttempl/elf.sc: Also provide __executable_start for PIE.
	
	ld/testsuite/
	
	PR ld/14525
	* ld-elf/elf.exp: Run pr14525.
	
	* ld-elf/pr14525.c: New.
	* ld-elf/pr14525.out: Likewise.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&r1=1.2484&r2=1.2485
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/scripttempl/elf.sc.diff?cvsroot=src&r1=1.114&r2=1.115
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1598&r2=1.1599
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr14525.c.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr14525.out.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/elf.exp.diff?cvsroot=src&r1=1.37&r2=1.38
Comment 4 H.J. Lu 2012-08-31 14:24:19 UTC
Fixed.
Comment 5 Sourceware Commits 2017-01-02 13:36:16 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit 595e0a47f57b414843261303b8aa5036fd1fa1e3
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Jan 2 22:31:27 2017 +1030

    Don't make symbols dynamic other than undef weak
    
    Fixes: tmpdir/pr14525: symbol lookup error: tmpdir/pr14525: undefined
    symbol: __executable_start
    FAIL: PIE PR ld/14525
    
    	* elf32-hppa.c (ensure_undef_weak_dynamic): New function.
    	(allocate_plt_static, allocate_dynrelocs): Use it.
Comment 6 Sourceware Commits 2017-02-03 09:38:47 UTC
The binutils-2_28-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit 24054c37eeb80231fd4dc9367267e35a0f008028
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Feb 3 16:49:29 2017 +1030

    Don't make symbols dynamic other than undef weak
    
    Fixes: tmpdir/pr14525: symbol lookup error: tmpdir/pr14525: undefined
    symbol: __executable_start
    FAIL: PIE PR ld/14525
    
    	* elf32-hppa.c (ensure_undef_weak_dynamic): New function.
    	(allocate_plt_static, allocate_dynrelocs): Use it.