I have a multiboot2-compliant ELF file for x86_64, where the start-symbol is defined in start.asm
, a NASM assembly file. The multiboot2 header contains the relocatable
tag.
Because GRUB doesn't support multiboot2 + a relocatable ELF (at least in July 2021 [3]), I want to resolve some relocations by myself to work around this and just load a static ELF.
For this I need to get the offset during runtime in my very first entry-symbol (specified in ELF header) in order to resolve relocations manually. With offset I mean the difference where GRUB located the binary in memory compared to the static address of the symbol in the ELF file.
In my entry symbol I'm in 64-bit long mode. It is not possible to directly access rip
in NASM syntax, therefore I need some kind of workaround.
Solutions like [1] [2] do not work, because the rip
keyword/register is not usable in NASM. Therefore I can't use
lea rax,[rip+0x1020304]
; rax contains offset
sub rax,0x1020304
How can I solve this?