* [PATCH v3 1/3] kbuild: don't enable CC_CAN_LINK if the dummy program generates warnings
2025-11-14 13:43 [PATCH v3 0/3] kbuild: userprogs: introduce architecture-specific CC_CAN_LINK and userprog flags Thomas Weißschuh
@ 2025-11-14 13:43 ` Thomas Weißschuh
2025-11-14 13:43 ` [PATCH v3 2/3] init: deduplicate cc-can-link.sh invocations Thomas Weißschuh
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2025-11-14 13:43 UTC (permalink / raw)
To: Nicolas Schier, Nathan Chancellor, Nicolas Schier
Cc: linux-kernel, linux-kbuild, Thomas Weißschuh
It is possible that the kernel toolchain generates warnings when used
together with the system toolchain. This happens for example when the
older kernel toolchain does not handle new versions of sframe debug
information. While these warnings where ignored during the evaluation
of CC_CAN_LINK, together with CONFIG_WERROR the actual userprog build
will later fail.
Example warning:
.../x86_64-linux/13.2.0/../../../../x86_64-linux/bin/ld:
error in /lib/../lib64/crt1.o(.sframe); no .sframe will be created
collect2: error: ld returned 1 exit status
Make sure that the very simple example program does not generate
warnings already to avoid breaking the userprog compilations.
Fixes: ec4a3992bc0b ("kbuild: respect CONFIG_WERROR for linker and assembler")
Fixes: 3f0ff4cc6ffb ("kbuild: respect CONFIG_WERROR for userprogs")
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Reviewed-by: Nicolas Schier <nsc@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
---
scripts/cc-can-link.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/cc-can-link.sh b/scripts/cc-can-link.sh
index 6efcead3198989d2ab2ab6772c72d8bb61c89c4e..e67fd8d7b6841e53341045b28dc5196cc1327cbe 100755
--- a/scripts/cc-can-link.sh
+++ b/scripts/cc-can-link.sh
@@ -1,7 +1,7 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
-cat << "END" | $@ -x c - -o /dev/null >/dev/null 2>&1
+cat << "END" | $@ -Werror -Wl,--fatal-warnings -x c - -o /dev/null >/dev/null 2>&1
#include <stdio.h>
int main(void)
{
--
2.51.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v3 2/3] init: deduplicate cc-can-link.sh invocations
2025-11-14 13:43 [PATCH v3 0/3] kbuild: userprogs: introduce architecture-specific CC_CAN_LINK and userprog flags Thomas Weißschuh
2025-11-14 13:43 ` [PATCH v3 1/3] kbuild: don't enable CC_CAN_LINK if the dummy program generates warnings Thomas Weißschuh
@ 2025-11-14 13:43 ` Thomas Weißschuh
2025-11-14 13:43 ` [PATCH v3 3/3] kbuild: allow architectures to override CC_CAN_LINK Thomas Weißschuh
2025-11-19 11:58 ` [PATCH v3 0/3] kbuild: userprogs: introduce architecture-specific CC_CAN_LINK and userprog flags Nicolas Schier
3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2025-11-14 13:43 UTC (permalink / raw)
To: Nicolas Schier, Nathan Chancellor, Nicolas Schier
Cc: linux-kernel, linux-kbuild, Thomas Weißschuh
The command to invoke scripts/cc-can-link.sh is very long and new usages
are about to be added.
Add a helper variable to make the code easier to read and maintain.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Reviewed-by: Nicolas Schier <nsc@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
---
init/Kconfig | 4 ++--
scripts/Kconfig.include | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/init/Kconfig b/init/Kconfig
index cab3ad28ca49e7ac930207c9cde8d431d55dc7af..7b722e714d5c5a0580467914b226dc0700ec0797 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -84,8 +84,8 @@ config RUSTC_LLVM_VERSION
config CC_CAN_LINK
bool
- default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(m64-flag)) if 64BIT
- default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(m32-flag))
+ default $(cc_can_link_user,$(m64-flag)) if 64BIT
+ default $(cc_can_link_user,$(m32-flag))
# Fixed in GCC 14, 13.3, 12.4 and 11.5
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113921
diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include
index 33193ca6e8030e659d6b321acaea1acd42c387a4..d42042b6c9e243b46d1626d892c0c986621ce462 100644
--- a/scripts/Kconfig.include
+++ b/scripts/Kconfig.include
@@ -65,6 +65,9 @@ cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$
m32-flag := $(cc-option-bit,-m32)
m64-flag := $(cc-option-bit,-m64)
+# Test whether the compiler can link userspace applications
+cc_can_link_user = $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(1))
+
rustc-version := $(shell,$(srctree)/scripts/rustc-version.sh $(RUSTC))
rustc-llvm-version := $(shell,$(srctree)/scripts/rustc-llvm-version.sh $(RUSTC))
--
2.51.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 3/3] kbuild: allow architectures to override CC_CAN_LINK
2025-11-14 13:43 [PATCH v3 0/3] kbuild: userprogs: introduce architecture-specific CC_CAN_LINK and userprog flags Thomas Weißschuh
2025-11-14 13:43 ` [PATCH v3 1/3] kbuild: don't enable CC_CAN_LINK if the dummy program generates warnings Thomas Weißschuh
2025-11-14 13:43 ` [PATCH v3 2/3] init: deduplicate cc-can-link.sh invocations Thomas Weißschuh
@ 2025-11-14 13:43 ` Thomas Weißschuh
2025-11-19 11:58 ` [PATCH v3 0/3] kbuild: userprogs: introduce architecture-specific CC_CAN_LINK and userprog flags Nicolas Schier
3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2025-11-14 13:43 UTC (permalink / raw)
To: Nicolas Schier, Nathan Chancellor, Nicolas Schier
Cc: linux-kernel, linux-kbuild, Thomas Weißschuh
The generic test for CC_CAN_LINK assumes that all architectures use -m32
and -m64 to switch between 32-bit and 64-bit compilation. This is overly
simplistic. Architectures may use other flags (-mabi, -m31, etc.) or may
also require byte order handling (-mlittle-endian, -EL). Expressing all
of the different possibilities will be very complicated and brittle.
Instead allow architectures to supply their own logic which will be
easy to understand and evolve.
Both the boolean ARCH_HAS_CC_CAN_LINK and the string ARCH_USERFLAGS need
to be implemented as kconfig does not allow the reuse of string options.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Reviewed-by: Nicolas Schier <nsc@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
---
Makefile | 13 +++++++++++--
init/Kconfig | 4 ++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 17cfa11ca7163aa3297101ceb3c9e85f4878f12d..36e7154c66cbd4772883a84d57676c615e4480a3 100644
--- a/Makefile
+++ b/Makefile
@@ -1134,8 +1134,17 @@ ifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),)
LDFLAGS_vmlinux += --emit-relocs --discard-none
endif
-# Align the bit size of userspace programs with the kernel
-USERFLAGS_FROM_KERNEL := -m32 -m64 --target=%
+# Align the architecture of userspace programs with the kernel
+USERFLAGS_FROM_KERNEL := --target=%
+
+ifdef CONFIG_ARCH_USERFLAGS
+KBUILD_USERCFLAGS += $(CONFIG_ARCH_USERFLAGS)
+KBUILD_USERLDFLAGS += $(CONFIG_ARCH_USERFLAGS)
+else
+# If not overridden also inherit the bit size
+USERFLAGS_FROM_KERNEL += -m32 -m64
+endif
+
KBUILD_USERCFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
KBUILD_USERLDFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
diff --git a/init/Kconfig b/init/Kconfig
index 7b722e714d5c5a0580467914b226dc0700ec0797..4a2ae3cfbf26525a60936d9b29a74ef4319ba3a5 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -82,8 +82,12 @@ config RUSTC_LLVM_VERSION
int
default $(rustc-llvm-version)
+config ARCH_HAS_CC_CAN_LINK
+ bool
+
config CC_CAN_LINK
bool
+ default ARCH_CC_CAN_LINK if ARCH_HAS_CC_CAN_LINK
default $(cc_can_link_user,$(m64-flag)) if 64BIT
default $(cc_can_link_user,$(m32-flag))
--
2.51.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 0/3] kbuild: userprogs: introduce architecture-specific CC_CAN_LINK and userprog flags
2025-11-14 13:43 [PATCH v3 0/3] kbuild: userprogs: introduce architecture-specific CC_CAN_LINK and userprog flags Thomas Weißschuh
` (2 preceding siblings ...)
2025-11-14 13:43 ` [PATCH v3 3/3] kbuild: allow architectures to override CC_CAN_LINK Thomas Weißschuh
@ 2025-11-19 11:58 ` Nicolas Schier
3 siblings, 0 replies; 5+ messages in thread
From: Nicolas Schier @ 2025-11-19 11:58 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Thomas Weißschuh
Cc: Nicolas Schier, linux-kernel, linux-kbuild
On Fri, 14 Nov 2025 14:43:55 +0100, Thomas Weißschuh wrote:
> The current logic to inherit -m32/-m64 from the kernel build only works
> for a few architectures. It does not handle byte order differences,
> architectures using different compiler flags or different kinds of ABIs.
>
> Introduce a per-architecture override mechanism to set CC_CAN_LINK and
> the flags used for userprogs.
> This revision only contains the generic kbuild infrastructure bits.
> The architecture-specific will go through the architecture trees.
> They are present in v2 of the series linked below.
>
> [...]
Applied to kbuild-next, thanks!
[1/3] kbuild: don't enable CC_CAN_LINK if the dummy program generates warnings
https://git.kernel.org/kbuild/c/d81d9d38
[2/3] init: deduplicate cc-can-link.sh invocations
https://git.kernel.org/kbuild/c/80623f2c
[3/3] kbuild: allow architectures to override CC_CAN_LINK
https://git.kernel.org/kbuild/c/deab487e
Please note that commit hashes might change in case of issues with
kbuild-next.
Best regards,
--
Nicolas
^ permalink raw reply [flat|nested] 5+ messages in thread