Skip to content

Commit dfc1b16

Browse files
t-8chmasahir0y
authored andcommitted
kbuild: userprogs: use correct lld when linking through clang
The userprog infrastructure links objects files through $(CC). Either explicitly by manually calling $(CC) on multiple object files or implicitly by directly compiling a source file to an executable. The documentation at Documentation/kbuild/llvm.rst indicates that ld.lld would be used for linking if LLVM=1 is specified. However clang instead will use either a globally installed cross linker from $PATH called ${target}-ld or fall back to the system linker, which probably does not support crosslinking. For the normal kernel build this is not an issue because the linker is always executed directly, without the compiler being involved. Explicitly pass --ld-path to clang so $(LD) is respected. As clang 13.0.1 is required to build the kernel, this option is available. Fixes: 7f3a59d ("kbuild: add infrastructure to build userspace programs") Cc: [email protected] # needs wrapping in $(cc-option) for < 6.9 Signed-off-by: Thomas Weißschuh <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 7eb1721 commit dfc1b16

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,11 @@ endif
11231123
KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
11241124
KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
11251125

1126+
# userspace programs are linked via the compiler, use the correct linker
1127+
ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_LD_IS_LLD),yy)
1128+
KBUILD_USERLDFLAGS += --ld-path=$(LD)
1129+
endif
1130+
11261131
# make the checker run with the right architecture
11271132
CHECKFLAGS += --arch=$(ARCH)
11281133

0 commit comments

Comments
 (0)