* Position Independent Code for MMU-less MCUs with XIP
@ 2018-09-07 9:54 kirkolw kirkolw
0 siblings, 0 replies; only message in thread
From: kirkolw kirkolw @ 2018-09-07 9:54 UTC (permalink / raw)
To: gcc-help
Hello!
Currently I develop Dynamic loader for one Nuttx fork for ARM architecture.
What do I want?
Load ELF files at runtime.
Execute code from FLASH (XIP).
No relocations into text section. (for sharing .text section between apps)
What do I have?
1) .text section is placed into FLASH
2)Function calls are sent to plt:
(test_func tries to print "Hello World!")
0000028c <test_func>:
...
290: e59f300c ldr r3, [pc, #12] ; 2a4 <test_func+0x18> #
Get GOT-index of "Hello World!" string
294: e79a0003 ldr r0, [sl, r3] # "sl" - addr of GOT. Load
"Hello world!" pointer to r0 and pass it to puts()
298: ebfffff0 bl 260 <puts@plt>
...
All seems OK. Code is position independent.
GOT is placed into RAM and after load-time relocations has correct
addresses of all stuff.
Important thing:
298: ebfffff0(!!!) bl 260 <puts@plt>
Branch to puts@plt is relative. So, PLT must be placed into FLASH too.
With PLT into FLASH I have a problem: compiler generates pc-relative code!
00000260 <puts@plt>:
260: e28fc600 add ip, pc, #0, 12
264: e28cca00 add ip, ip, #0, 20
268: e5bcf0f0 ldr pc, [ip, #240]! ; 0xf0
With pc-relative code into PLT, GOT must be placed into particular address
into RAM, but MMU-less system can't provide such opportunity.
I have found example of code for PLT functions into presentation [
https://www.slideshare.net/linaroorg/sfo15406-arm-fdpic-toolset-kernel-libraries-for-cortexm-cortexr-mmuless-cores
]:
plt(foo): ldr ip, .L1 # foo's descriptor offset
add ip, ip, r9 # from caller's FDT
ldr r9, [ip, #4] # foo's data address
ldr pc, [ip] # foo's code address
L1. word foo(GOTOFFFUNCDESC)
Such code is exactly what I want.
It seems, they developed a number of patches, but they were not merged into
any compiler's upstream
I've tried:
- arm-none-eabi-gcc
- linaro
- clang
Used compiler keys:
-fpic -mpic-register=r10 -msingle-pic-base
-mno-pic-data-is-text-relative
How can I obtain PLT code mentiont above?
P.S. I desired something like -mno-plt flag to disable PLT and I will have
probably not too fast, but at least suitable for XIP code. But such flag is
implemented only for MIPS, as I can see. Is there similar flag for ARM?
Many thanks,
Dmitrii Rodionov
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-09-07 9:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-07 9:54 Position Independent Code for MMU-less MCUs with XIP kirkolw kirkolw
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).