[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.
Created attachment 6615 [details] A patch
I confirm that patch resolves the issue.
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
Fixed.
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.
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.