* ARM position-independent code in Gas
@ 2014-02-26 20:02 Alex Matveev
2014-02-27 3:45 ` Matt Thomas
0 siblings, 1 reply; 2+ messages in thread
From: Alex Matveev @ 2014-02-26 20:02 UTC (permalink / raw)
To: binutils
Hello all,
I'm working on a project which is part C and part assembler (ARM, GCC
4.8.2, binutils 2.23.1), and final binary should be
position-independent.
I compile stuff with -fpie and link with -pie -fpie. This works out
fine on the C side - I get R_ARM_RELATIVE and R_ARM_ABS32 relocations,
fix'em up on startup, all good. But the problem is, there are no relocs
from assembler objects, thus the result is not PIC. Trying to trick Gas
into producing relocs, I've found couple of
not-very-extensively-documented directives - '.reloc' and ARM-specific
'.word foo(RELOC)', but I haven't had any success with them either.
Can GAS in principle produce PIC? Or am I missing something obvious?
And a side question: I'm somewhat puzzled by the presence of
R_ARM_ABS32 relocations in the final output - aren't they static
(AAELF says so)?
Thanks.
--
Alex Matveev
Samsung R&D Institute Rus.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: ARM position-independent code in Gas
2014-02-26 20:02 ARM position-independent code in Gas Alex Matveev
@ 2014-02-27 3:45 ` Matt Thomas
0 siblings, 0 replies; 2+ messages in thread
From: Matt Thomas @ 2014-02-27 3:45 UTC (permalink / raw)
To: Alex Matveev; +Cc: binutils
On Feb 26, 2014, at 12:02 PM, Alex Matveev <alex.matveev@samsung.com> wrote:
> Hello all,
>
> I'm working on a project which is part C and part assembler (ARM, GCC
> 4.8.2, binutils 2.23.1), and final binary should be
> position-independent.
>
> I compile stuff with -fpie and link with -pie -fpie. This works out
> fine on the C side - I get R_ARM_RELATIVE and R_ARM_ABS32 relocations,
> fix'em up on startup, all good. But the problem is, there are no relocs
> from assembler objects, thus the result is not PIC. Trying to trick Gas
> into producing relocs, I've found couple of
> not-very-extensively-documented directives - '.reloc' and ARM-specific
> '.word foo(RELOC)', but I haven't had any success with them either.
>
> Can GAS in principle produce PIC? Or am I missing something obvious?
gas doesn't know PIC. The arm assembly has to be PIC to start.
> And a side question: I'm somewhat puzzled by the presence of
> R_ARM_ABS32 relocations in the final output - aren't they static
> (AAELF says so)?
They are static.
Not sure which processor you are using but you can do PIC like:
movw r0, #:lower16:foo-.LPIC0
movt r0, #:upper16:foo-.LPIC0
add r0, r0, pc
nop @ at this point r0 points at foo and you can replace foo
@ by another instruction the same size as the add.
.LPIC0:
You can also do symbol relative:
bar: @ function entry
adr ip, bar
movw r0, #:lower16:foo-bar
movt r0, #:upper16:foo-bar
add r0, r0, ip
If you are dealing with shared libraries and global data:
ldr r3, .Lgot
add r3, r3, pc
ldr r0, .Lfoo @ load got slot offset
.LPIC0: ldr r0, [r0, r3]
...
.Lgot:
.long _GLOBAL_OFFSET_TABLE_-.LPIC0
.Lfoo:
.word foo(GOT) @ reserves a slot in the GOT for foo
using -S -c -fPIC on c source and looking at the assembly produced
can prove to be instructive.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-02-27 3:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-26 20:02 ARM position-independent code in Gas Alex Matveev
2014-02-27 3:45 ` Matt Thomas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).