Tag Archives: kernel

64-bit relocatable addresses

I’m trying to get this going:
http://ringzeroandlower.com/2017/08/08/x86-64-kernel-boot.html

The issue I’m running into is that nasm doesn’t seem to support 64-bit relocatable symbols in its elf-64 output, or at least I haven’t been able to figure it out. Basically after the kernel goes into 32-bit mode, it can start running code in virtual memory space, but that requires a 64-bit jump to go from the low 16/32 bit virtual addresses to the very large virtual memory address location. From what I can tell, x86-64 call instructions are actually always 64bit anyway, so it shouldn’t matter per se, but ld still requires that the relocation records explicitly be 64 bit.

nasm only seems to be able to write 32 bit relocation records:
RELOCATION RECORDS FOR [.boot_text]:
OFFSET TYPE VALUE
0000000000000010 R_X86_64_PC32 rust_main-0x0000000000000004

Though in the source code there does seem to be R_X86_64_PC64, it’s not obvious how to force it for a particular symbol. NASM’s docs seem pretty old, so it seems like the only thing to do is port my code to gcc.