Skip to content

HOSTCC invocations don't use LLD with LLVM=1 #2167

@Gelbpunkt

Description

@Gelbpunkt

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    [PATCH] SubmittedA patch has been submitted for review[TOOL] lldThe issue is relevant to LLD linkerhermetic buildshas implications for doing gcc/binutils-free builds

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions