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? --- src/pmem.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/pmem.c') diff --git a/src/pmem.c b/src/pmem.c index bed10a4..47bb319 100644 --- a/src/pmem.c +++ b/src/pmem.c @@ -612,6 +612,11 @@ retry: return 0; } +/** Actual kernel size in bytes. Populated by `_start`, as I don't think we + * have enough control from C to get both LLVM and GCC to output correct code + * if this was just a virtual symbol defined in a linker file. */ +size_t kernel_size = 0; + void init_pmem(void *fdt, uintptr_t load_addr) { /** @todo should I keep the info outputs? I suppose it's nice to see @@ -650,13 +655,11 @@ void init_pmem(void *fdt, uintptr_t load_addr) size_t probe_size = probe_pmap(0, ram_size, 0); info("pmem map probe size returned %lu\n", probe_size); - /* linker magicry */ - extern char *__kernel_size; /* avoidance regions, note that stack and so on is included in the * kernel. Addresses can be outside RAM, in which case they are just * ignored. */ struct avoid_region avoid[64] = { - {(pm_t)__va(load_addr), (pm_t)&__kernel_size}, + {(pm_t)__va(load_addr), kernel_size}, {(pm_t)__va(initrd_base), initrd_size}, {(pm_t)__va(fdt_base), fdt_size} }; -- cgit v1.3