I am using the GCC options -mpic-data-is-text-relative and -fpic to generate position independent code. This works fine for my C code.
But I also have assembly code that needs to use PIC. The problem is I cannot find an example on how to achieve this. Are there some ARM GCC assembly keywords, do I need to set up my own GOT table or are there any neat tricks?
I'm trying to reach a variable from my code using PIC:
.section .data @HWA_SWI_HND_DATA, "w"
hwa_ext_reset_hnd:
.word 0x00000000
.section .text @HWA_SWI_HND_CODE, "x"
.code 32
.list
.global hwa_reset_cb_attach
hwa_reset_cb_attach:
ldr r1, =hwa_ext_reset_hnd
str r0, [r1]
bx lr
As seen above in the ldr r1, =hwa_ext_reset_hnd call I want this address fetch to be PIC.
gcc -Sto compile a test C code and see what the compiler does. - Jestermovw/movtpair, theldr=pseudo-op should assemble to a PC-relative load from the nearest literal pool, thus should be position-independent anyway. What does this look like once you assemble it and disassemble the result? - Notlikethatldr=itself is position-independent. - Notlikethat