RossComputerGuy / nixpkgs-llvm-ws

Flake workspace / repo to stage and track Nixpkgs/NixOS's ability to be compiled completely with LLVM
MIT License
14 stars 0 forks source link

Linux kernel. Can't build with llvm 18. #1

Closed VeilSilence closed 1 week ago

VeilSilence commented 3 months ago

Greetings.

Trying to build kernel with llvm 18, but without success.

Details

```nix PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Running pass 'Function Pass Manager' on module 'vmlinux.a(ip6_input.o at 1076674)'. 1. Running pass 'X86 DAG->DAG Instruction Selection' on function '@ip6_rcv_core' #0 0x00007ffff02dd2de llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0xedd2de) #1 0x00007ffff02da72b SignalHandler(int) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0xeda72b) #2 0x00007fffeee495c0 __restore_rt (/nix/store/m71p7f0nymb19yn1dascklyya2i96jfw-glibc-2.39-52/lib/libc.so.6+0x405c0) #3 0x00007fffeeeaab55 __libc_realloc (/nix/store/m71p7f0nymb19yn1dascklyya2i96jfw-glibc-2.39-52/lib/libc.so.6+0xa1b55) #4 0x00007ffff0243574 llvm::SmallVectorBase::grow_pod(void*, unsigned long, unsigned long) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0xe43574) #5 0x00007ffff0a4ba44 llvm::SUnit::addPred(llvm::SDep const&, bool) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x164ba44) #6 0x00007ffff0d71caa llvm::ScheduleDAGSDNodes::AddSchedEdges() (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x1971caa) #7 0x00007ffff0d69d22 (anonymous namespace)::ScheduleDAGRRList::Schedule() (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x1969d22) #8 0x00007ffff0e4e59e llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x1a4e59e) #9 0x00007ffff0e50e37 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x1a50e37) #10 0x00007ffff0e5338a llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x1a5338a) #11 0x00007ffff41e4850 (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x4de4850) #12 0x00007ffff0807378 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x1407378) #13 0x00007ffff0487d19 llvm::FPPassManager::runOnFunction(llvm::Function&) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x1087d19) #14 0x00007ffff048806c llvm::FPPassManager::runOnModule(llvm::Module&) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x108806c) #15 0x00007ffff0488a6e llvm::legacy::PassManagerImpl::run(llvm::Module&) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x1088a6e) #16 0x00007ffff2180d5c codegen(llvm::lto::Config const&, llvm::TargetMachine*, std::function>> (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex const&) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x2d80d5c) #17 0x00007ffff2181a69 llvm::lto::thinBackend(llvm::lto::Config const&, unsigned int, std::function>> (unsigned int, llvm::Twine const&)>, llvm::Module&, llvm::ModuleSummaryIndex const&, llvm::DenseMap, std::equal_to, std::allocator>, llvm::DenseMapInfo, llvm::detail::DenseMapPair, std::equal_to, std::allocator>>> const&, llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::MapVector, llvm::detail::DenseMapPair>, llvm::SmallVector, 0u>>*, std::vector> const&)::'lambda'(llvm::Module&, llvm::TargetMachine*, std::unique_ptr>)::operator()(llvm::Module&, llvm::TargetMachine*, std::unique_ptr>) const (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x2d81a69) #18 0x00007ffff218254e llvm::lto::thinBackend(llvm::lto::Config const&, unsigned int, std::function>> (unsigned int, llvm::Twine const&)>, llvm::Module&, llvm::ModuleSummaryIndex const&, llvm::DenseMap, std::equal_to, std::allocator>, llvm::DenseMapInfo, llvm::detail::DenseMapPair, std::equal_to, std::allocator>>> const&, llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::MapVector, llvm::detail::DenseMapPair>, llvm::SmallVector, 0u>>*, std::vector> const&) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x2d8254e) #19 0x00007ffff21610e0 (anonymous namespace)::InProcessThinBackend::runThinLTOBackendThread(std::function>> (unsigned int, llvm::Twine const&)>, std::function>> (unsigned int, llvm::Twine const&)>> (unsigned int, llvm::StringRef, llvm::Twine const&)>, unsigned int, llvm::BitcodeModule, llvm::ModuleSummaryIndex&, llvm::DenseMap, std::equal_to, std::allocator>, llvm::DenseMapInfo, llvm::detail::DenseMapPair, std::equal_to, std::allocator>>> const&, llvm::DenseSet> const&, std::map, std::allocator>> const&, llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::MapVector, llvm::detail::DenseMapPair>, llvm::SmallVector, 0u>>&)::'lambda'(std::function>> (unsigned int, llvm::Twine const&)>)::operator()(std::function>> (unsigned int, llvm::Twine const&)>) const (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x2d610e0) #20 0x00007ffff21750a9 std::_Function_handler, std::equal_to, std::allocator>, llvm::DenseMapInfo, llvm::detail::DenseMapPair, std::equal_to, std::allocator>>> const&, llvm::DenseSet> const&, std::map, std::allocator>> const&, llvm::MapVector, llvm::detail::DenseMapPair>, llvm::SmallVector, 0u>>&)::'lambda'(llvm::BitcodeModule, llvm::ModuleSummaryIndex&, llvm::DenseMap, std::equal_to, std::allocator>, llvm::DenseMapInfo, llvm::detail::DenseMapPair, std::equal_to, std::allocator>>> const&, llvm::DenseSet> const&, std::map, std::allocator>> const&, llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::MapVector, llvm::detail::DenseMapPair>, llvm::SmallVector, 0u>>&) (llvm::BitcodeModule, std::reference_wrapper, std::reference_wrapper, std::equal_to, std::allocator>, llvm::DenseMapInfo, llvm::detail::DenseMapPair, std::equal_to, std::allocator>>> const>, std::reference_wrapper> const>, std::reference_wrapper, std::allocator>> const>, std::reference_wrapper, llvm::detail::DenseMapPair> const>, std::reference_wrapper, llvm::detail::DenseMapPair>, llvm::SmallVector, 0u>>>)>>::_M_invoke(std::_Any_data const&) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0x2d750a9) #21 0x00007ffff019688e std::_Function_handler)::'lambda'()>::_M_invoke(std::_Any_data const&) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0xd9688e) #22 0x00007ffff025f307 llvm::ThreadPool::processTasks(llvm::ThreadPoolTaskGroup*) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0xe5f307) #23 0x00007ffff025fd68 void* llvm::thread::ThreadProxy>(void*) (/nix/store/fr74q0nf9wlkfmf1qqmsklykmc09sic6-llvm-18.1.8-lib/lib/libLLVM.so.18.1+0xe5fd68) #24 0x00007fffeee99a42 start_thread (/nix/store/m71p7f0nymb19yn1dascklyya2i96jfw-glibc-2.39-52/lib/libc.so.6+0x90a42) #25 0x00007fffeef1905c __GI___clone3 (/nix/store/m71p7f0nymb19yn1dascklyya2i96jfw-glibc-2.39-52/lib/libc.so.6+0x11005c) /nix/store/m101dg80ngyjdb02g6jwy80sr7kzj26g-bash-5.2p26/bin/bash: line 1: 227071 Segmentation fault (core dumped) /nix/store/8bg6ll2cr9p7kg6ygwn6x3axg57p310g-lld-18.1.8/bin/ld.lld -m elf_x86_64 -mllvm -import-instr-limit=5 -z noexecstack -r -o vmlinux.o -T .tmp_initcalls.lds --whole-archive vmlinux.a --no-whole-archive --start-group --end-group make[2]: *** [../scripts/Makefile.vmlinux_o:62: vmlinux.o] Error 139 make[1]: *** [/build/source/Makefile:1305: vmlinux_o] Error 2 make: *** [../Makefile:240: __sub-make] Error 2 ```

My LLVM stdenv

```nix { llvmPackages_18, patchelf, overrideCC, pkgs, }: let noBintools = { bootBintools = null; bootBintoolsNoLibc = null; }; hostLLVM = llvmPackages_18.override noBintools; buildLLVM = llvmPackages_18.override noBintools; mkLLVMPlatform = platform: platform // { linux-kernel = platform.linux-kernel // { makeFlags = (platform.linux-kernel.makeFlags or []) ++ [ "LLVM=1" "LLVM_IAS=1" #"V=1" #to test if flags applied "CC=${buildLLVM.clangUseLLVM}/bin/clang" "LD=${buildLLVM.lld}/bin/ld.lld" "HOSTLD=${hostLLVM.lld}/bin/ld.lld" "AR=${buildLLVM.llvm}/bin/llvm-ar" "HOSTAR=${hostLLVM.llvm}/bin/llvm-ar" "NM=${buildLLVM.llvm}/bin/llvm-nm" "STRIP=${buildLLVM.llvm}/bin/llvm-strip" "OBJCOPY=${buildLLVM.llvm}/bin/llvm-objcopy" "OBJDUMP=${buildLLVM.llvm}/bin/llvm-objdump" "READELF=${buildLLVM.llvm}/bin/llvm-readelf" "HOSTCC=${hostLLVM.clangUseLLVM}/bin/clang" "HOSTCXX=${hostLLVM.clangUseLLVM}/bin/clang++" ]; }; }; stdenv' = pkgs.overrideCC hostLLVM.stdenv hostLLVM.clangUseLLVM; in stdenv'.override (old: { hostPlatform = mkLLVMPlatform old.hostPlatform; buildPlatform = mkLLVMPlatform old.buildPlatform; extraNativeBuildInputs = [hostLLVM.lld patchelf]; }) ```

debug.txt

RossComputerGuy commented 3 months ago

Already tracked upstream https://github.com/NixOS/nixpkgs/issues/321667

VeilSilence commented 3 months ago

Sorry, pressed enter accidently. Error different that was mentioned in nixpkgs#321667 as far as I can tell. With LLVM 17, I can build kernel succesfully.

RossComputerGuy commented 3 months ago

Gotcha, that is a very cursed error.

VeilSilence commented 3 months ago

I looked at this cachyos LTO-llvm kernel , and I can't figure how they manage to bypass that. Tried different kernels also.

RossComputerGuy commented 2 months ago

Seems like Garnix was able to build the kernel with LLVM 18. Are you able to build the kernel using this project?

VeilSilence commented 2 months ago

Sorry for long response. In last week, when 6.10.2 xanmod kernel released, I updated to new kernel with clang 17. After that, i didn't update my system at all. Today, after flake update, nix again rebuild kernel, but in this time, it's failed with:

Details

```nix last 40 log lines: > CC [M] drivers/gpu/drm/nouveau/nouveau_dma.o > CC [M] drivers/gpu/drm/nouveau/nouveau_fence.o > CC [M] drivers/gpu/drm/nouveau/nv04_fence.o > CC [M] drivers/gpu/drm/nouveau/nv10_fence.o > CC [M] drivers/gpu/drm/nouveau/nv17_fence.o > CC [M] drivers/gpu/drm/nouveau/nv50_fence.o > CC [M] drivers/gpu/drm/nouveau/nv84_fence.o > CC [M] drivers/gpu/drm/nouveau/nvc0_fence.o > CC [M] drivers/gpu/drm/nouveau/nouveau_led.o > LD [M] drivers/gpu/drm/nouveau/nouveau.o > AR drivers/gpu/built-in.a > AR drivers/built-in.a > AR built-in.a > AR vmlinux.a > GEN .tmp_initcalls.lds > LD vmlinux.o > vmlinux.o: warning: objtool: set_ftrace_ops_ro+0x3a: relocation to !ENDBR: blake2s_compress_ssse3+0x99 > OBJCOPY modules.builtin.modinfo > GEN modules.builtin > MODPOST Module.symvers > CC .vmlinux.export.o > UPD include/generated/utsversion.h > CC init/version-timestamp.o > LD .tmp_vmlinux.btf > BTF .btf.vmlinux.bin.o > LD .tmp_vmlinux.kallsyms1 > NM .tmp_vmlinux.kallsyms1.syms > KSYMS .tmp_vmlinux.kallsyms1.S > AS .tmp_vmlinux.kallsyms1.o > LD .tmp_vmlinux.kallsyms2 > NM .tmp_vmlinux.kallsyms2.syms > KSYMS .tmp_vmlinux.kallsyms2.S > AS .tmp_vmlinux.kallsyms2.o > LD vmlinux > BTFIDS vmlinux > FAILED: load BTF from vmlinux: Invalid argument > make[2]: *** [../scripts/Makefile.vmlinux:34: vmlinux] Error 255 > make[2]: *** Deleting file 'vmlinux' > make[1]: *** [/build/source/Makefile:1324: vmlinux] Error 2 > make: *** [../Makefile:240: __sub-make] Error 2 ```

I have 64GB ram, so ram shouldn't be cause this issue. Honestly, I have no idea, why it's suddenly breaks. I'm gonna test atm nix build github:NixOS/nixpkgs#pkgsLLVM.linuxPackages.kernel

I also noticed, that in your repo, there is nix llvm-ldd fix kernel patch. I didn't use it previously. I will try with this patch also.

Updated:

Nix build didn't compiled kernel for me. Different error, but still.

nix-build.txt

Details

```nix MKPIGGY arch/x86/boot/compressed/piggy.S AS arch/x86/boot/compressed/piggy.o CC [M] drivers/regulator/tps65086-regulator.mod.o CC [M] drivers/regulator/tps6524x-regulator.mod.o CC [M] drivers/regulator/tps65912-regulator.mod.o CC [M] drivers/regulator/tps65132-regulator.mod.o LD arch/x86/boot/compressed/vmlinux ZOFFSET arch/x86/boot/zoffset.h OBJCOPY arch/x86/boot/vmlinux.bin AS arch/x86/boot/header.o CC [M] drivers/regulator/tps68470-regulator.mod.o CC [M] drivers/regulator/wm8994-regulator.mod.o CC [M] drivers/reset/reset-ti-syscon.mod.o CC [M] drivers/reset/reset-tps380x.mod.o CC [M] drivers/tty/serial/8250/8250_pci.mod.o CC [M] drivers/tty/serial/8250/8250_exar.mod.o CC [M] drivers/tty/serial/8250/serial_cs.mod.o CC [M] drivers/tty/serial/8250/8250_pci1xxxx.mod.o CC [M] drivers/tty/serial/8250/8250_men_mcb.mod.o LD arch/x86/boot/setup.elf CC [M] drivers/tty/serial/8250/8250_dfl.mod.o CC [M] drivers/tty/serial/8250/8250_dw.mod.o x86_64-unknown-linux-gnu-ld: error: ../arch/x86/boot/setup.ld:15: unable to move location counter (0x204) backward to 0x1ef for section '.bstext' CC [M] drivers/tty/serial/8250/8250_lpss.mod.o make[2]: *** [../arch/x86/boot/Makefile:107: arch/x86/boot/setup.elf] Error 1 make[1]: *** [../arch/x86/Makefile:283: bzImage] Error 2 make[1]: *** Waiting for unfinished jobs... ```

In this case, ld error now. I'll try with your patch now and with llvm stdenv

VeilSilence commented 1 week ago

With clang19, kernel with LTO optimization was build successfully. Last time I tried clang18, kernel refused to build still. I guess we can close this issue?