Open yshui opened 9 months ago
btw clang version is 17.0.6
if I use -cpu host -enable-kvm
, qemu takes 100% cpu and there is no output in console.
Turns out I just threw in the towel a bit too quickly. I missed one spot:
diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
index f614009d3e4e2..4b42006d9ce02 100644
--- a/arch/x86/realmode/rm/Makefile
+++ b/arch/x86/realmode/rm/Makefile
@@ -50,7 +50,7 @@ $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE
targets += realmode.lds
$(obj)/realmode.lds: $(obj)/pasyms.h
-LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T
+LDFLAGS_realmode.elf := --no-dynamic-linker -m elf_i386 --emit-relocs -T
CPPFLAGS_realmode.lds += -P -C -I$(objtree)/$(obj)
targets += realmode.elf
With this the kernel boots! I guess this is enough of a workaround while we wait for the lld bug to be fixed.
i feel i might know what's happening here. without --no-dynamic-linker
lld puts a .interp
into the file even when ~the linker script doesn't include one~ ld.bfd
won't.
See llvm/llvm-project#78873
OK, proposal to change the behavior of lld
was rejected, the remaining choice is to add --no-dynamic-linker
to kernel LDFLAGS.
-KBUILD_CFLAGS += -fno-strict-overflow
yikes! Don't do that!
i feel i might know what's happening here. without --no-dynamic-linker lld puts a .interp into the file even when the linker script doesn't include one ld.bfd won't.
There's also the option to add .interp
to the DISCARDS sections of the existing linker scripts. That's a pretty clean solution IMO.
yikes! Don't do that!
nix puts -fwrapv
in cflags automatically, which makes clang report -fno-strict-overflow
as unused. anyway this patch isn't relevant here :sweat_smile:
add
.interp
to the DISCARDS
good idea! how many linker scripts do we need to change?
hmm, looks like each arch has itself own linker script...
@nickdesaulniers ok, how can i move this forward? do i submit a patch to kernel mailing list.
i am kind of worried that if i explain this is needed because NixOS is designed weirdly and needs to add some stupid linker flags when building anything, Linus is going to be very mad.
@yshui Yes, you could submit a patch upstream for this. There is precedent for adding flags to workaround behavior with distribution versions of toolchains, such as -fno-PIE
because distribution versions default to PIE.
Submitted https://lore.kernel.org/llvm/20240208012057.2754421-2-yshuiv7@gmail.com/T/#u
:crossed_fingers:
There are a couple of small patches I had to apply to get the kernel to build under NixOS, the main problem in nixos/nixpkgs#242244
patch 1:
This is because NixOS clang-wrapper already includes
-fwrapv
which does the same thing.patch 2:
This is to deal with issue 242244
with these patches the kernel builds successfully, but when trying to boot it in qemu, I got:
(this is with
-cpu max
and no kvm)