-fpie problem on armeb

Lennert Buytenhek buytenh@wantstofly.org
Mon Mar 14 10:20:00 GMT 2005


(please CC, not on the list)

Hi all,

I was facing the problem that linking executables with -pie on an
ARM platform would complain about a number of undefined references to
__{init,fini}_array_{start,end} and fail.  It appeared that 'ld -pie'
was using the built-in link script for "--shared -z combreloc", which
does not PROVIDE the abovementioned symbols.  I "fixed" (ahem) this
by applying the patch below to binutils, and creating simple executables
with -pie now seems to work.

But now I'm facing a different problem, and that is -fpic/-fpie: using
these gcc options produces really bizarre results.

[root@enp2611 tmp]# cat x.c
#include <stdio.h>
#include <stdlib.h>

int a;
int b;

int main()
{
        printf("%p %p\n", &a, &b);
        a = 1;
        b = 2;

        return 0;
}
[root@enp2611 tmp]# gcc -fpic -c ./x.c
[root@enp2611 tmp]# gcc -pie -o x x.o
[root@enp2611 tmp]# ./x
0x2a000000 0x2a000000
Segmentation fault
[root@enp2611 tmp]#

Anyone got any ideas?  I'll get to the right solution on my own
eventually, but it'd be nice if someone could give me a gentle kick
into the right direction.


thanks,
Lennert


--- binutils-2.15.92.0.2/ld/emulparams/armelf_linux.sh.orig	2005-03-13 19:01:48.933265000 +0100
+++ binutils-2.15.92.0.2/ld/emulparams/armelf_linux.sh	2005-03-13 19:02:00.803290000 +0100
@@ -8,6 +8,7 @@
 TEMPLATE_NAME=elf32
 EXTRA_EM_FILE=armelf
 GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes

 DATA_START_SYMBOLS='__data_start = . ;';
 OTHER_TEXT_SECTIONS='*(.glue_7t) *(.glue_7)'




More information about the Binutils mailing list