* [PATCH v2] kbuild: userprogs: use correct lld when linking through clang
@ 2025-02-17 7:27 Thomas Weißschuh
2025-02-17 18:54 ` Nathan Chancellor
2025-03-04 19:03 ` Masahiro Yamada
0 siblings, 2 replies; 3+ messages in thread
From: Thomas Weißschuh @ 2025-02-17 7:27 UTC (permalink / raw)
To: Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Nick Desaulniers, Bill Wendling, Justin Stitt, Sam Ravnborg
Cc: linux-kbuild, linux-kernel, llvm, stable, Thomas Weißschuh
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: 7f3a59db274c ("kbuild: add infrastructure to build userspace programs")
Cc: stable@vger.kernel.org # needs wrapping in $(cc-option) for < 6.9
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Reproducer, using nolibc to avoid libc requirements for cross building:
$ tail -2 init/Makefile
userprogs-always-y += test-llvm
test-llvm-userccflags += -nostdlib -nolibc -static -isystem usr/ -include $(srctree)/tools/include/nolibc/nolibc.h
$ cat init/test-llvm.c
int main(void)
{
return 0;
}
$ make ARCH=arm64 LLVM=1 allnoconfig headers_install init/
Validate that init/test-llvm builds and has the correct binary format.
---
Changes in v2:
- Use --ld-path instead of -fuse-ld
- Drop already applied patch
- Link to v1: https://lore.kernel.org/r/20250213-kbuild-userprog-fixes-v1-0-f255fb477d98@linutronix.de
---
Makefile | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/Makefile b/Makefile
index 96407c1d6be167b04ed5883e455686918c7a75ee..b41c164533d781d010ff8b2522e523164dc375d0 100644
--- a/Makefile
+++ b/Makefile
@@ -1123,6 +1123,11 @@ endif
KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
+# userspace programs are linked via the compiler, use the correct linker
+ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_LD_IS_LLD),yy)
+KBUILD_USERLDFLAGS += --ld-path=$(LD)
+endif
+
# make the checker run with the right architecture
CHECKFLAGS += --arch=$(ARCH)
---
base-commit: 0ad2507d5d93f39619fc42372c347d6006b64319
change-id: 20250213-kbuild-userprog-fixes-4f07b62ae818
Best regards,
--
Thomas Weißschuh <thomas.weissschuh@linutronix.de>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] kbuild: userprogs: use correct lld when linking through clang
2025-02-17 7:27 [PATCH v2] kbuild: userprogs: use correct lld when linking through clang Thomas Weißschuh
@ 2025-02-17 18:54 ` Nathan Chancellor
2025-03-04 19:03 ` Masahiro Yamada
1 sibling, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2025-02-17 18:54 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Masahiro Yamada, Nicolas Schier, Nick Desaulniers, Bill Wendling,
Justin Stitt, Sam Ravnborg, linux-kbuild, linux-kernel, llvm,
stable
On Mon, Feb 17, 2025 at 08:27:54AM +0100, Thomas Weißschuh wrote:
> 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: 7f3a59db274c ("kbuild: add infrastructure to build userspace programs")
> Cc: stable@vger.kernel.org # needs wrapping in $(cc-option) for < 6.9
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
> ---
> Reproducer, using nolibc to avoid libc requirements for cross building:
>
> $ tail -2 init/Makefile
> userprogs-always-y += test-llvm
> test-llvm-userccflags += -nostdlib -nolibc -static -isystem usr/ -include $(srctree)/tools/include/nolibc/nolibc.h
>
> $ cat init/test-llvm.c
> int main(void)
> {
> return 0;
> }
>
> $ make ARCH=arm64 LLVM=1 allnoconfig headers_install init/
>
> Validate that init/test-llvm builds and has the correct binary format.
> ---
> Changes in v2:
> - Use --ld-path instead of -fuse-ld
> - Drop already applied patch
> - Link to v1: https://lore.kernel.org/r/20250213-kbuild-userprog-fixes-v1-0-f255fb477d98@linutronix.de
> ---
> Makefile | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index 96407c1d6be167b04ed5883e455686918c7a75ee..b41c164533d781d010ff8b2522e523164dc375d0 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1123,6 +1123,11 @@ endif
> KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
> KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
>
> +# userspace programs are linked via the compiler, use the correct linker
> +ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_LD_IS_LLD),yy)
> +KBUILD_USERLDFLAGS += --ld-path=$(LD)
> +endif
> +
> # make the checker run with the right architecture
> CHECKFLAGS += --arch=$(ARCH)
>
>
> ---
> base-commit: 0ad2507d5d93f39619fc42372c347d6006b64319
> change-id: 20250213-kbuild-userprog-fixes-4f07b62ae818
>
> Best regards,
> --
> Thomas Weißschuh <thomas.weissschuh@linutronix.de>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] kbuild: userprogs: use correct lld when linking through clang
2025-02-17 7:27 [PATCH v2] kbuild: userprogs: use correct lld when linking through clang Thomas Weißschuh
2025-02-17 18:54 ` Nathan Chancellor
@ 2025-03-04 19:03 ` Masahiro Yamada
1 sibling, 0 replies; 3+ messages in thread
From: Masahiro Yamada @ 2025-03-04 19:03 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Nathan Chancellor, Nicolas Schier, Nick Desaulniers,
Bill Wendling, Justin Stitt, Sam Ravnborg, linux-kbuild,
linux-kernel, llvm, stable
On Mon, Feb 17, 2025 at 4:28 PM Thomas Weißschuh
<thomas.weissschuh@linutronix.de> wrote:
>
> 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: 7f3a59db274c ("kbuild: add infrastructure to build userspace programs")
> Cc: stable@vger.kernel.org # needs wrapping in $(cc-option) for < 6.9
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
Applied to linux-kbuild/fixes.
Thanks.
> Reproducer, using nolibc to avoid libc requirements for cross building:
>
> $ tail -2 init/Makefile
> userprogs-always-y += test-llvm
> test-llvm-userccflags += -nostdlib -nolibc -static -isystem usr/ -include $(srctree)/tools/include/nolibc/nolibc.h
>
> $ cat init/test-llvm.c
> int main(void)
> {
> return 0;
> }
>
> $ make ARCH=arm64 LLVM=1 allnoconfig headers_install init/
>
> Validate that init/test-llvm builds and has the correct binary format.
> ---
> Changes in v2:
> - Use --ld-path instead of -fuse-ld
> - Drop already applied patch
> - Link to v1: https://lore.kernel.org/r/20250213-kbuild-userprog-fixes-v1-0-f255fb477d98@linutronix.de
> ---
> Makefile | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index 96407c1d6be167b04ed5883e455686918c7a75ee..b41c164533d781d010ff8b2522e523164dc375d0 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1123,6 +1123,11 @@ endif
> KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
> KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
>
> +# userspace programs are linked via the compiler, use the correct linker
> +ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_LD_IS_LLD),yy)
> +KBUILD_USERLDFLAGS += --ld-path=$(LD)
> +endif
> +
> # make the checker run with the right architecture
> CHECKFLAGS += --arch=$(ARCH)
>
>
> ---
> base-commit: 0ad2507d5d93f39619fc42372c347d6006b64319
> change-id: 20250213-kbuild-userprog-fixes-4f07b62ae818
>
> Best regards,
> --
> Thomas Weißschuh <thomas.weissschuh@linutronix.de>
>
>
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-04 19:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-17 7:27 [PATCH v2] kbuild: userprogs: use correct lld when linking through clang Thomas Weißschuh
2025-02-17 18:54 ` Nathan Chancellor
2025-03-04 19:03 ` Masahiro Yamada
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).