Hi there, we're trying to build the Linux kernel without binutils or GCC present in our kernel packages in postmarketOS. However, we're actually seeing some quite interesting issues after getting rid of binutils from the build environment.
The setup is as follows: there's no ld in the path, only ld.lld / lld, and the clang binary will actually default to attempting to invoke ld as the linker. Therefore the kernel build needs to pass -fuse-ld=lld.
We invoke make with parameters like make ARCH=arm64 LLVM=1, which we expect to then use LLD for linking (not just for the target, but also for the host).
However, we see the following:
# HOSTCC scripts/basic/fixdep
clang -Wp,-MMD,scripts/basic/.fixdep.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu11 -I ./scripts/include -o scripts/basic/fixdep scripts/basic/fixdep.c
clang: error: unable to execute command: posix_spawn failed: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
i.e. clang is invoked without explicitly requesting linkage with LLD and then fails because ld (BFD) is not in the path. We can actually work around this with HOSTCFLAGS="-fuse-ld=lld", which makes it work as intended, but I feel like LLVM=1 should imply HOSTCFLAGS="-fuse-ld=lld. In the end, that is documented to set HOSTLD=ld.lld as per https://docs.kernel.org/kbuild/llvm.html#the-llvm-argument, but apparently HOSTLD is not being used for linking with HOSTCC!?
I see https://lore.kernel.org/all/CAKwvOdnUdFjN+aCDrHKP6RzZCFB033ycN_KkB1WKucGd6VzUSg@mail.gmail.com/ from @nickdesaulniers which appears to reference this problem, but I haven't been able to find a reason why it wasn't ever changed upstream. I'd appreciate some pointers. Thank you!
Hi there, we're trying to build the Linux kernel without binutils or GCC present in our kernel packages in postmarketOS. However, we're actually seeing some quite interesting issues after getting rid of binutils from the build environment.
The setup is as follows: there's no
ldin the path, onlyld.lld/lld, and the clang binary will actually default to attempting to invokeldas the linker. Therefore the kernel build needs to pass-fuse-ld=lld.We invoke make with parameters like
make ARCH=arm64 LLVM=1, which we expect to then use LLD for linking (not just for the target, but also for the host).However, we see the following:
i.e. clang is invoked without explicitly requesting linkage with LLD and then fails because
ld(BFD) is not in the path. We can actually work around this withHOSTCFLAGS="-fuse-ld=lld", which makes it work as intended, but I feel likeLLVM=1should implyHOSTCFLAGS="-fuse-ld=lld. In the end, that is documented to setHOSTLD=ld.lldas per https://docs.kernel.org/kbuild/llvm.html#the-llvm-argument, but apparentlyHOSTLDis not being used for linking withHOSTCC!?I see https://lore.kernel.org/all/CAKwvOdnUdFjN+aCDrHKP6RzZCFB033ycN_KkB1WKucGd6VzUSg@mail.gmail.com/ from @nickdesaulniers which appears to reference this problem, but I haven't been able to find a reason why it wasn't ever changed upstream. I'd appreciate some pointers. Thank you!