This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PATCH] PR 878: fix -pie
- From: Gwenole Beauchesne <gbeauchesne at mandriva dot com>
- To: binutils at sources dot redhat dot com
- Cc: hongjiu dot lu at intel dot com
- Date: Fri, 6 May 2005 12:17:47 +0200 (CEST)
- Subject: [PATCH] PR 878: fix -pie
Hi,
This change:
2005-03-22 H.J. Lu <hongjiu.lu@intel.com>
* emultempl/elf32.em (gld${EMULATION_NAME}_provide_bound_symbols): New
(gld${EMULATION_NAME}_finish): Call
gld${EMULATION_NAME}_provide_bound_symbols to provide
__preinit_array_start, __preinit_array_end, __init_array_start,
__init_array_end, __fini_array_start and __fini_array_end.
* scripttempl/elf.sc: Don't provide __preinit_array_start,
__preinit_array_end, __init_array_start, __init_array_end,
__fini_array_start nor __fini_array_end.
causes -pie to fail on linux:
[gb@n2 vrac]$ echo 'int main(void){return 0;}' | gcc -xc -fPIE -pie -
/usr/lib/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
: undefined reference to `__init_array_end'
/usr/lib/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
: undefined reference to `__init_array_start'
/usr/lib/libc_nonshared.a(elf-init.oS): In function `__libc_csu_fini':
: undefined reference to `__fini_array_end'
/usr/lib/libc_nonshared.a(elf-init.oS): In function `__libc_csu_fini':
: undefined reference to `__fini_array_start'
collect2: ld returned 1 exit status
[gb@n2 vrac]$ ld --version
GNU ld version 2.16.90 20050506
The following patch makes sure the test for shared library doesn't cover
pie executables. WDYT?
2005-04-30 Gwenole Beauchesne <gbeauchesne@mandriva.com>
PR 878
* emultempl/elf32.em
(gld${EMULATION_NAME}_provide_init_fini_syms): Provide init/fini
symbols for -pie executables.
--- binutils-2.16.90.0.2/ld/emultempl/elf32.em.ld-pie-init-fini-syms 2005-04-29 19:50:30.000000000 +0200
+++ binutils-2.16.90.0.2/ld/emultempl/elf32.em 2005-04-30 07:58:17.739644900 +0200
@@ -1495,7 +1495,7 @@ gld${EMULATION_NAME}_provide_bound_symbo
static void
gld${EMULATION_NAME}_provide_init_fini_syms (void)
{
- if (!link_info.relocatable && !link_info.shared)
+ if (!link_info.relocatable && (!link_info.shared || link_info.pie))
{
gld${EMULATION_NAME}_provide_bound_symbols (".preinit_array",
"__preinit_array_start",