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? --- scripts/makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'scripts/makefile') diff --git a/scripts/makefile b/scripts/makefile index 26b33ad..aa0bcac 100644 --- a/scripts/makefile +++ b/scripts/makefile @@ -47,7 +47,7 @@ COMPILER != [ "$(LLVM)" != "0" ] \ || echo $(CROSS_COMPILE)gcc -OBFLAGS = -ffreestanding -nostdlib -static -fno-pie -std=c17 -g +OBFLAGS = -ffreestanding -nostdlib -static -fpic -fno-pie -std=c17 -g WARNFLAGS = -Wall -Wextra -Wvla ARCH_CFLAGS = -D$(ARCH) @@ -61,8 +61,7 @@ LINK_FLAGS = $(LDFLAGS) $(ARCH_LDFLAGS) INCLUDE_FLAGS = -I include -include config.h -include arch/$(ARCH)/config.h # This makes sure .bss is loaded into the binary -OBJCOPY_FLAGS ?= -Obinary -R .garbage \ - --set-section-flags .bss=alloc,load,contents +OBJCOPY_FLAGS ?= -Obinary -R .garbage COMPILE = $(COMPILER) \ $(COMPILE_FLAGS) $(DEPFLAGS) $(INCLUDE_FLAGS) -- cgit v1.3