From e134202611a50b358c147c92bfb8a7f443030b8b Mon Sep 17 00:00:00 2001 From: Kimplul Date: Mon, 8 Jul 2024 17:43:59 +0300 Subject: fix LLVM + Anything extern is right out as LLVM doesn't produce correct code for them. Maybe if I added some extra attributes but I'm skeptical. Replaced with static variables and getters/setters. + Inline ASM is apparently a bit buggy, so use an assembly stub when jumping to init. + Minimize work done in main() to minimize chance of LLVM doing something silly. Still not 100% certain that I shouldn't just write the main() as an assembly stub in arch/riscv64 to be absolutely sure everything works as intended. + Make .kernel.start section SHF_ALLOC, otherwise lld complains about pc-relative addressing Probably some other stuff as well that I'm forgetting right now. But at least with LLVM14 LTO seems to work, which is pretty cool? --- arch/riscv64/conf/kernel-link.S | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'arch/riscv64/conf/kernel-link.S') diff --git a/arch/riscv64/conf/kernel-link.S b/arch/riscv64/conf/kernel-link.S index 88f2e75..e395e4a 100644 --- a/arch/riscv64/conf/kernel-link.S +++ b/arch/riscv64/conf/kernel-link.S @@ -5,12 +5,6 @@ OUTPUT_ARCH(riscv) ENTRY(main) SECTIONS { - /* This is apparently necessary. I *think* it is to tell the linker that - * the kernel should be able to run in the bottom half of the address - * space, but I don't know for sure and this feels like a fairly major - * hack. - * @todo look into this further. - */ . = ABSOLUTE(VM_KERNEL); __kernel_start = .; .text ALIGN(4K) : AT(0) { @@ -18,6 +12,14 @@ SECTIONS { *(.text*); } + /* place bss in between different load sections to force objcopy to + * output zeroes for it */ + .bss : { + *(.sbss*) + *(.bss*) + *(COMMON) + } + .rodata : { *(.rodata*) } @@ -27,12 +29,7 @@ SECTIONS { *(.sdata*) } - .bss : { - *(.sbss*) *(.bss*) *(COMMON) - } - __kernel_end = .; - __kernel_size = __kernel_end - __kernel_start; .garbage : { *(.note*) -- cgit v1.3