From: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
To: Nicolas Schier <nsc@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nicolas.schier@linux.dev>
Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Subject: [PATCH v3 3/3] kbuild: allow architectures to override CC_CAN_LINK
Date: Fri, 14 Nov 2025 14:43:58 +0100 [thread overview]
Message-ID: <20251114-kbuild-userprogs-bits-v3-3-4dee0d74d439@linutronix.de> (raw)
In-Reply-To: <20251114-kbuild-userprogs-bits-v3-0-4dee0d74d439@linutronix.de>
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
next prev parent reply other threads:[~2025-11-14 13:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2025-11-19 11:58 ` [PATCH v3 0/3] kbuild: userprogs: introduce architecture-specific CC_CAN_LINK and userprog flags Nicolas Schier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251114-kbuild-userprogs-bits-v3-3-4dee0d74d439@linutronix.de \
--to=thomas.weissschuh@linutronix.de \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=nicolas.schier@linux.dev \
--cc=nsc@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).