This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
position independent executable using shared libraries on arm
- From: "mathias palmqvist" <mathiaspalm at gmail dot com>
- To: binutils at sourceware dot org
- Date: Sat, 15 Dec 2007 17:26:26 +0100
- Subject: position independent executable using shared libraries on arm
Hey
When I compile simple test code with -fPIC and no pie link parameter
or shared libs I can see
prologue code similar to this in each function setting up R10 and adding PC.
.text:0000804C MOV R12, SP
.text:00008050 STMFD SP!, {R10-R12,LR,PC}
.text:00008054 SUB R11, R12, #4
.text:00008058 LDR R10, =0x3D8
.text:0000805C ADD R10, PC, R10
.text:00008060 LDR R3, =0xC
If I add -pie as a link parameter, or link the executable with a
shared library, the
ADD R10,PC,R10
instruction is replaced with a NOP, and the code looks like this:
.text:0000034C MOV R12, SP
.text:00000350 STMFD SP!, {R10-R12,LR,PC}
.text:00000354 SUB R11, R12, #4
.text:00000358 LDR R10, =_GLOBAL_OFFSET_TABLE_ ; PIC mode
.text:0000035C NOP
.text:00000360 LDR R3, =0xC
The object file generated by gcc is the same. Only link parameters change.
Am I missing something here? What should I do to get ld to position
GOT at a relative
offset instead of at the absolute address when linking with shared libs?
We are currently implementing dynamic linking support for elf and
simple so:s on our embedded
platform, so we have complete control of the loading, but want to use
gcc/ld for building.
Using: ld 2.16.1 with gcc 4.1.0. Building for armv5.
Thanks in advance
/Mathias