Frogging-Family / linux-tkg

linux-tkg custom kernels
GNU General Public License v2.0
1.32k stars 166 forks source link

Compiling with LLVM not working #968

Open veganvelociraptor opened 1 month ago

veganvelociraptor commented 1 month ago

Compiling the kernel using LLVM instead of GCC is no longer working starting with kernel v6.9.9.

I've tried with LTO disabled and downgrading pahole to v1.26 with no luck. Downgrading pahole was a working workaround for compiling v6.8.8.

Same errors occur when trying to compile v6.10-rc7.

/usr/include/c++/14.1.1/bits/stl_vector.h:1130: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = llvm::SUnit; _Alloc = std::allocator<llvm::SUnit>; reference = llvm::SUnit&;size_type = long unsigned int]: Assertion '__n < this->size()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /usr/bin/clang --target=x86_64-linux-gnu -fintegrated-as -Werror=unknown-warning-option -Werror=ignored-optimization-argument -Werror=option-ignored -Werror=unused-command-line-argument -fmacro-prefix-map=./= -std=gnu11 -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=branch -fno-jump-tables -m64 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mstack-alignment=8 -mskip-rax-setup -march=znver3 -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mretpoline-external-thunk -mindirect-branch-cs-prefix -mfunction-return=thunk-extern -mharden-sls=all -fpatchable-function-entry=16,16 -fno-delete-null-pointer-checks -O2 -fstack-protector-strong -ftrivial-auto-var-init=zero -fno-stack-clash-protection -pg -mfentry -falign-functions=16 -fstrict-flex-arrays=3 -fno-tree-vectorize -fno-strict-overflow -fno-stack-check -Wall -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wmissing-declarations -Wmissing-prototypes -Wframe-larger-than=2048 -Wno-gnu -Wno-unused-but-set-variable -Wno-unused-const-variable -Wvla -Wno-pointer-sign -Wcast-function-type -Wimplicit-fallthrough -Werror=date-time -Werror=incompatible-pointer-types -Wenum-conversion -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-format-overflow -Wno-format-truncation -Wno-override-init -Wno-pointer-to-enum-cast -Wno-tautological-constant-out-of-range-compare -Wno-unaligned-access -Wno-cast-function-type-strict -Wno-enum-compare-conditional -Wno-enum-enum-conversion -Wno-missing-field-initializers -Wno-type-limits -Wno-shift-negative-value -Wno-sign-compare -g -gdwarf-5 -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -DCC_USING_NOP_MCOUNT -DCC_USING_FENTRY -DKBUILD_MODFILE=\"net/ipv6/ipv6\" -DKBUILD_BASENAME=\"ip6_input\" -DKBUILD_MODNAME=\"ipv6\" -D__KBUILD_MODNAME=kmod_ipv6 -c -Wp,-MMD,net/ipv6/.ip6_input.o.d -fcolor-diagnostics -o net/ipv6/ip6_input.o net/ipv6/ip6_input.c
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'net/ipv6/ip6_input.c'.
4.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@ip6_rcv_core'
#0 0x000072981e1caec0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/libLLVM.so.18.1+0x7caec0)
#1 0x000072981e1c83bd llvm::sys::CleanupOnSignal(unsigned long) (/usr/lib/libLLVM.so.18.1+0x7c83bd)
#2 0x000072981e0aac09 (/usr/lib/libLLVM.so.18.1+0x6aac09)
#3 0x000072981d450ae0 (/usr/lib/libc.so.6+0x3cae0)
#4 0x000072981d4a8e44 (/usr/lib/libc.so.6+0x94e44)
#5 0x000072981d450a30 raise (/usr/lib/libc.so.6+0x3ca30)
#6 0x000072981d4384c3 abort (/usr/lib/libc.so.6+0x244c3)
#7 0x000072981d6d2d60 std::chrono::_V2::system_clock::now() /usr/src/debug/gcc/gcc/libstdc++-v3/src/c++11/chrono.cc:52:5
#8 0x000072981ed24030 llvm::ScheduleDAGSDNodes::AddSchedEdges() (/usr/lib/libLLVM.so.18.1+0x1324030)
#9 0x000072981ed1bdfe (/usr/lib/libLLVM.so.18.1+0x131bdfe)
#10 0x000072981ee11262 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/usr/lib/libLLVM.so.18.1+0x1411262)
#11 0x000072981ee14699 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/usr/lib/libLLVM.so.18.1+0x1414699)
#12 0x000072981ee16807 (/usr/lib/libLLVM.so.18.1+0x1416807)
#13 0x000072981ee18241 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/usr/lib/libLLVM.so.18.1+0x1418241)
#14 0x0000729822552928 (/usr/lib/libLLVM.so.18.1+0x4b52928)
#15 0x000072981e7548b9 (/usr/lib/libLLVM.so.18.1+0xd548b9)
#16 0x000072981e39aba3 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib/libLLVM.so.18.1+0x99aba3)
#17 0x000072981e39ad04 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/lib/libLLVM.so.18.1+0x99ad04)
#18 0x000072981e39c7cf llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib/libLLVM.so.18.1+0x99c7cf)
#19 0x000072982718936f clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/usr/lib/libclang-cpp.so.18.1+0x158936f)
#20 0x0000729827512725 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/lib/libclang-cpp.so.18.1+0x1912725)
#21 0x00007298261918a3 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/libclang-cpp.so.18.1+0x5918a3)
#22 0x0000729827c98421 clang::FrontendAction::Execute() (/usr/lib/libclang-cpp.so.18.1+0x2098421)
#23 0x0000729827c38457 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/libclang-cpp.so.18.1+0x2038457)
#24 0x0000729827ced15d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/libclang-cpp.so.18.1+0x20ed15d)
#25 0x00005a203149334d cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/bin/clang+0x1334d)
#26 0x00005a203149767c (/usr/bin/clang+0x1767c)
#27 0x000072982796a225 (/usr/lib/libclang-cpp.so.18.1+0x1d6a225)
#28 0x000072981e0ab05a llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/lib/libLLVM.so.18.1+0x6ab05a)
#29 0x000072982796ce26 (/usr/lib/libclang-cpp.so.18.1+0x1d6ce26)
#30 0x00007298279278c9 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/usr/lib/libclang-cpp.so.18.1+0x1d278c9)
#31 0x0000729827927cbc clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/usr/lib/libclang-cpp.so.18.1+0x1d27cbc)
#32 0x00007298279461e4 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/usr/lib/libclang-cpp.so.18.1+0x1d461e4)
#33 0x00005a2031499f9b clang_main(int, char**, llvm::ToolContext const&) (/usr/bin/clang+0x19f9b)
#34 0x00005a203148b005 main (/usr/bin/clang+0xb005)
#35 0x000072981d439c88 (/usr/lib/libc.so.6+0x25c88)
#36 0x000072981d439d4c __libc_start_main (/usr/lib/libc.so.6+0x25d4c)
#37 0x00005a203148b065 _start (/usr/bin/clang+0xb065)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 18.1.8
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/ip6_input-49e827.c
clang: note: diagnostic msg: /tmp/ip6_input-49e827.sh
clang: note: diagnostic msg:

********************
make[4]: *** [scripts/Makefile.build:244: net/ipv6/ip6_input.o] Error 1
make[3]: *** [scripts/Makefile.build:485: net/ipv6] Error 2
ptr1337 commented 1 month ago

Known issue, if -march=znverX .

You need to patch your llvm or select a different Architecture at compilation. Patch for LLVM: https://github.com/CachyOS/CachyOS-PKGBUILDS/blob/master/llvm/fix-znver-kernel.patch

This is not even fixed in llvm-git yet, so who knows if it gets ever fixed. Since for LLVM its not a big thing, it is not a major issue for them.

anh0516 commented 1 month ago

I stopped using clang to compile my kernel on my system months ago because of this. Glad to see there's a fix.

For Gentoo, I had to edit the diff paths from a/lib and b/lib to a/llvm/lib and b/llvm/lib in order for the patch apply properly, because of differences in the way the LLVM tarball is unpacked. If you're not using Arch and your package manager isn't applying the diff properly, that's probably why.

The upstream Linux kernel doesn't support -march=znver{1,2,3,4,5}. So it makes sense for it to be low priority.

anh0516 commented 1 month ago

Gentoo has pulled in the patch with sys-devel/llvm-18.1.8-r2. So it's fixed on both Gentoo and CachyOS now.