mastermakrela / kernel-dev

Template for Linux Kernel development on Apple Silicon (aarch64) using VS Code
1 stars 0 forks source link

Failed to Load CMake Project in CLion on M1 MacBook Air Using Bear and Generated CMakeLists #1

Open wuxiaoqiang12 opened 2 weeks ago

wuxiaoqiang12 commented 2 weeks ago

Hello,

First of all, I want to express my gratitude for your excellent tutorial. I was able to successfully compile the Linux kernel on my M1 chip MacBook Air. However, I encountered an issue when trying to load the project in CLion.

Here's what I did:

  1. I used Bear (https://github.com/rizsotto/Bear) to track the make process.
  2. Then, I generated a CMakeLists.txt file using the tool from this repository: https://github.com/habemus-papadum/kernel-grok.git.

But when I try to load the CMake project in CLion, it fails with numerous errors indicating that many files are missing.

Compiler exited with error code 1: /opt/homebrew/opt/llvm/bin/clang -xc -I/Users/xiaoqiang/Research/linux_kernel/linux/. -I/Users/xiaoqiang/Research/linux_kernel/linux/./include -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -Wp,-MMD,drivers/xen/xen-pciback/.conf_space.o.d -nostdinc -I.././arch/arm64/include -I.././arch/arm64/include/generated -I.././include -I.././arch/arm64/include/uapi -I.././arch/arm64/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__ --target=aarch64-linux-gnu -fintegrated-as -mlittle-endian -DKASAN_SHADOW_SCALE_SHIFT= -fmacro-prefix-map=./= -std=gnu11 -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -Wall -Wundef -Wno-format-security -Wno-trigraphs -mgeneral-regs-only -DCONFIG_CC_HAS_K_CONSTRAINT=1 -Wno-psabi -fno-asynchronous-unwind-tables -fno-unwind-tables -mbranch-protection=pac-ret+bti -Wa,-march=armv8.5-a -DARM64_ASM_ARCH=\"armv8.5-a\" -DKASAN_SHADOW_SCALE_SHIFT= -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -O2 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-gnu -Wno-unused-but-set-variable -Wno-unused-const-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -ftrivial-auto-var-init=zero -fno-stack-clash-protection -falign-functions=4 -Wvla -Wno-pointer-sign -Wcast-function-type -fstrict-flex-arrays=3 -Wimplicit-fallthrough -fno-strict-overflow -fno-stack-check -Wno-initializer-overrides -Wno-sign-compare -Wno-pointer-to-enum-cast -Wno-tautological-constant-out-of-range-compare -Wno-unaligned-access -Wno-cast-function-type-strict -g -fno-var-tracking -mstack-protector-guard=sysreg -mstack-protector-guard-reg=sp_el0 -mstack-protector-guard-offset=1144 -DMODULE -DKBUILD_BASENAME=\"conf_space\" -DKBUILD_MODNAME=\"xen_pciback\" -D__KBUILD_MODNAME=kmod_xen_pciback -c -fpch-preprocess -v -dD -E
    Homebrew clang version 18.1.8
    Target: aarch64-unknown-linux-gnu
    Thread model: posix
    InstalledDir: /opt/homebrew/opt/llvm/bin
     (in-process)
     "/opt/homebrew/Cellar/llvm/18.1.8/bin/clang-18" -cc1 -triple aarch64-unknown-linux-gnu -E -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name compiler-file10430345223622998869 -function-alignment 2 -mrelocation-model static -fno-delete-null-pointer-checks -fwarn-stack-size=2048 -mframe-pointer=non-leaf -relaxed-aliasing -fno-optimize-sibling-calls -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -target-feature +v8a -target-feature -fp-armv8 -target-feature -neon -target-abi aapcs -msign-return-address=non-leaf -msign-return-address-key=a_key -mbranch-target-enforce -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -fdebug-compilation-dir=/Users/xiaoqiang/Research/linux_kernel/linux/cmake-build-debug-clang-for-linux -target-linker-version 1053.12 -v -fcoverage-compilation-dir=/Users/xiaoqiang/Research/linux_kernel/linux/cmake-build-debug-clang-for-linux -nostdsysteminc -nobuiltininc -resource-dir /opt/homebrew/Cellar/llvm/18.1.8/lib/clang/18 -dependency-file drivers/xen/xen-pciback/.conf_space.o.d -MT compiler-file10430345223622998869.o -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -include .././include/linux/compiler-version.h -include .././include/linux/kconfig.h -include .././include/linux/compiler_types.h -I /Users/xiaoqiang/Research/linux_kernel/linux/. -I /Users/xiaoqiang/Research/linux_kernel/linux/./include -I .././arch/arm64/include -I .././arch/arm64/include/generated -I .././include -I .././arch/arm64/include/uapi -I .././arch/arm64/include/generated/uapi -I .././include/uapi -I .././include/generated/uapi -D __KERNEL__ -D KASAN_SHADOW_SCALE_SHIFT= -D CONFIG_CC_HAS_K_CONSTRAINT=1 -D "ARM64_ASM_ARCH=\"armv8.5-a\"" -D KASAN_SHADOW_SCALE_SHIFT= -D MODULE -D "KBUILD_BASENAME=\"conf_space\"" -D "KBUILD_MODNAME=\"xen_pciback\"" -D __KBUILD_MODNAME=kmod_xen_pciback -D ___CIDR_DEFINITIONS_END -fmacro-prefix-map=./= -O2 -Wall -Wundef -Wno-format-security -Wno-trigraphs -Wno-psabi -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -Wframe-larger-than=2048 -Wno-gnu -Wno-unused-but-set-variable -Wno-unused-const-variable -Wvla -Wno-pointer-sign -Wcast-function-type -Wimplicit-fallthrough -Wno-initializer-overrides -Wno-sign-compare -Wno-pointer-to-enum-cast -Wno-tautological-constant-out-of-range-compare -Wno-unaligned-access -Wno-cast-function-type-strict -std=gnu11 -ferror-limit 19 -fwrapv -fstrict-flex-arrays=3 -stack-protector 2 -mstack-protector-guard=sysreg -mstack-protector-guard-offset=1144 -mstack-protector-guard-reg=sp_el0 -ftrivial-auto-var-init=zero -fno-signed-char -fwchar-type=short -fno-signed-wchar -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -vectorize-loops -vectorize-slp -dD -target-feature -fmv -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o - -x c /private/var/folders/f0/0y9_0_p93tq_389d1l5r7jsr0000gn/T/compiler-file10430345223622998869
    clang -cc1 version 18.1.8 based upon LLVM 18.1.8 default target arm64-apple-darwin23.5.0
    ignoring duplicate directory ".././include"
    #include "..." search starts here:
    #include <...> search starts here:
     /Users/xiaoqiang/Research/linux_kernel/linux/.
     /Users/xiaoqiang/Research/linux_kernel/linux/./include
     .././arch/arm64/include
     .././arch/arm64/include/generated
     .././arch/arm64/include/uapi
     .././arch/arm64/include/generated/uapi
     .././include/uapi
     .././include/generated/uapi
    End of search list.
    error: error opening 'drivers/xen/xen-pciback/.conf_space.o.d': No such file or directory
    1 error generated.

Is there any specific configuration or additional steps I need to follow to resolve this issue? Any help would be greatly appreciated.

Thank you!

mastermakrela commented 2 weeks ago

Hi, I'm glad that the build did work :)

I don't have any experience with CLion, so I don't know how to configure it.

But the error indicates that the compiler can't find some files, so I'd check if all the paths provided to clang really exist. For example, -dependency-file drivers/xen/xen-pciback/.conf_space.o.d looks suspicious — it can only work if you are in kernel root directory.

Maybe you can tell CLion to just use the existing makefile? I.e. call make LLVM=1 ARCH=arm64 -j $(sysctl -n hw.logicalcpu) HOSTCFLAGS="-I./" when you run Build/