I'm relatively new to assembly and am working with a powerpc chip. I'm using a gcc crosscompiler and working with a buildroot environment (just for background).
I am adding code to the .head section of some code that will create a .elf object (lets call it target.elf for arguments sake) which gets brought into a larger binary all via buildroot. target.elf is defined as starting at address 0x0 in the code and the local linker but will get moved to a different address location later. I wish to reference a global variable, that is being shared between the assembly code and a c-file, from the assembly code. When I do so using location independent means I run into problems. When I do use using the GOT as reference (symbol@got@h for instance) I am able to reference the symbol correctly.
This is a problem because I wish to create a interrupt handler that does not depend on having a valid pointer to the stack or TOC upon entering, and I need the TOC to use the GOT.
Is there a way of doing this without the TOC?
Here is some example code:
Incorrect result (%r3 does not contain what "symbol" contains):
.global symbol
symbol:
.long 0
.global irq_handler
irq_handler:
addi %r3, 0, 0
ori %r3, %r3, symbol@l
ld %r3, 0(%r3)
b .
In global area of C-file:
extern uint64_t symbol;
I have also attempted defining the symbol in the c-file (so without extern but still as a global) and omitting the definition in the asm file. This also has failed.
I am also taking a shortcut and only loading the @l portion of the address because the top 32 bits are 0x0.
Correct result (%r3 does contain what "symbol" contains):
.global irq_handler
irq_handler:
ld %r3, symbol@got(%r2)
ld %r3, 0(%r3)
b .
Note that in the correct example the TOC is available in %r2.
Thank you in advance.