arch/mips/Kconfig | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
The generic CC_CAN_LINK detection does not handle different byte orders.
This may lead to userprogs which are not actually runnable on the target
kernel.
Use architecture-specific logic supporting byte orders instead.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
arch/mips/Kconfig | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index b88b97139fa8..316e3c29c431 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -4,6 +4,7 @@ config MIPS
default y
select ARCH_32BIT_OFF_T if !64BIT
select ARCH_BINFMT_ELF_STATE if MIPS_FP_SUPPORT
+ select ARCH_HAS_CC_CAN_LINK
select ARCH_HAS_CPU_CACHE_ALIASING
select ARCH_HAS_CPU_FINALIZE_INIT
select ARCH_HAS_CURRENT_STACK_POINTER
@@ -3126,6 +3127,20 @@ config CC_HAS_MNO_BRANCH_LIKELY
config CC_HAS_BROKEN_INLINE_COMPAT_BRANCH
def_bool y if CC_IS_CLANG
+config ARCH_CC_CAN_LINK
+ bool
+ default $(cc_can_link_user,-m64 -EL) if 64BIT && CPU_LITTLE_ENDIAN
+ default $(cc_can_link_user,-m64 -EB) if 64BIT && CPU_BIG_ENDIAN
+ default $(cc_can_link_user,-m32 -EL) if CPU_LITTLE_ENDIAN
+ default $(cc_can_link_user,-m32 -EB) if CPU_BIG_ENDIAN
+
+config ARCH_USERFLAGS
+ string
+ default "-m64 -EL" if 64BIT && CPU_LITTLE_ENDIAN
+ default "-m64 -EB" if 64BIT && CPU_BIG_ENDIAN
+ default "-m32 -EL" if CPU_LITTLE_ENDIAN
+ default "-m32 -EB" if CPU_BIG_ENDIAN
+
menu "Power management options"
config ARCH_HIBERNATION_POSSIBLE
---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20251222-cc-can-link-mips-c9c0e06b61f7
Best regards,
--
Thomas Weißschuh <thomas.weissschuh@linutronix.de>
On Mon, 22 Dec 2025, Thomas Weißschuh wrote: > diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig > index b88b97139fa8..316e3c29c431 100644 > --- a/arch/mips/Kconfig > +++ b/arch/mips/Kconfig > @@ -3126,6 +3127,20 @@ config CC_HAS_MNO_BRANCH_LIKELY > config CC_HAS_BROKEN_INLINE_COMPAT_BRANCH > def_bool y if CC_IS_CLANG > > +config ARCH_CC_CAN_LINK > + bool > + default $(cc_can_link_user,-m64 -EL) if 64BIT && CPU_LITTLE_ENDIAN > + default $(cc_can_link_user,-m64 -EB) if 64BIT && CPU_BIG_ENDIAN > + default $(cc_can_link_user,-m32 -EL) if CPU_LITTLE_ENDIAN > + default $(cc_can_link_user,-m32 -EB) if CPU_BIG_ENDIAN > + > +config ARCH_USERFLAGS > + string > + default "-m64 -EL" if 64BIT && CPU_LITTLE_ENDIAN > + default "-m64 -EB" if 64BIT && CPU_BIG_ENDIAN > + default "-m32 -EL" if CPU_LITTLE_ENDIAN > + default "-m32 -EB" if CPU_BIG_ENDIAN There are no `-m32'/`-m64' options with MIPS GCC; where did you get them from and how did you verify your change? Did you mean `-mabi=...' by any chance? Also does the n32 ABI have to be factored in, since IIUC this stuff is about user programs? Maciej
On Wed, Dec 31, 2025 at 02:33:40AM +0000, Maciej W. Rozycki wrote: > On Mon, 22 Dec 2025, Thomas Weißschuh wrote: > > > diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig > > index b88b97139fa8..316e3c29c431 100644 > > --- a/arch/mips/Kconfig > > +++ b/arch/mips/Kconfig > > @@ -3126,6 +3127,20 @@ config CC_HAS_MNO_BRANCH_LIKELY > > config CC_HAS_BROKEN_INLINE_COMPAT_BRANCH > > def_bool y if CC_IS_CLANG > > > > +config ARCH_CC_CAN_LINK > > + bool > > + default $(cc_can_link_user,-m64 -EL) if 64BIT && CPU_LITTLE_ENDIAN > > + default $(cc_can_link_user,-m64 -EB) if 64BIT && CPU_BIG_ENDIAN > > + default $(cc_can_link_user,-m32 -EL) if CPU_LITTLE_ENDIAN > > + default $(cc_can_link_user,-m32 -EB) if CPU_BIG_ENDIAN > > + > > +config ARCH_USERFLAGS > > + string > > + default "-m64 -EL" if 64BIT && CPU_LITTLE_ENDIAN > > + default "-m64 -EB" if 64BIT && CPU_BIG_ENDIAN > > + default "-m32 -EL" if CPU_LITTLE_ENDIAN > > + default "-m32 -EB" if CPU_BIG_ENDIAN > > There are no `-m32'/`-m64' options with MIPS GCC; where did you get them > from and how did you verify your change? Did you mean `-mabi=...' by any > chance? Yes indeed. Not sure how that happened, I do have a correct version in another branch... Thanks for spotting this. > Also does the n32 ABI have to be factored in, since IIUC this > stuff is about user programs? It can be added, but I don't think it makes much sense. It would only be used if CONFIG_MIPS32_N32=y (which is non-default) and if the toolchain which has no n64 libc, but does have a n32 libc. This seems unlikely to me, but let me know if I am mistaken. Thomas
On Fri, 2 Jan 2026, Thomas Weißschuh wrote: > > There are no `-m32'/`-m64' options with MIPS GCC; where did you get them > > from and how did you verify your change? Did you mean `-mabi=...' by any > > chance? > > Yes indeed. Not sure how that happened, I do have a correct version in > another branch... Thanks for spotting this. Great! > > Also does the n32 ABI have to be factored in, since IIUC this > > stuff is about user programs? > > It can be added, but I don't think it makes much sense. > It would only be used if CONFIG_MIPS32_N32=y (which is non-default) and if > the toolchain which has no n64 libc, but does have a n32 libc. > This seems unlikely to me, but let me know if I am mistaken. My observation over the years has been that n32 has become the industry standard for 64-bit MIPS configurations; it's the default arrangement too for the GNU compiler for `mips64*-*-linux-gnu' targets in the absence of explicit `--with-abi=64' `configure' option, and no multilib support may have been enabled in the compiler (which is not required to build Linux, as 64-bit MIPS GCC and binutils are always able to produce code for all the ABIs regardless). I've always been an n64 ABI advocate and I used to build pure-n64 64-bit environments, but I appreciate that it makes sense for an embedded target to use n32 instead, as a lot of code and data space is wasted for the handling of 64-bit pointers the upper 33 bits of which may never hold anything but zero in many deployments. Which is also why `-msym32' is used to build Linux where the upper 33 bits of immediate kernel addresses are known to always hold all-ones. It's not clear to me offhand how the infrastructure concerned here is used, but it may make sense to default to either NewABI and resort to the other if the default turns out unsupported in a given environment. This for a change I cannot decide on based on information I've gathered so far. Maciej
On Sat, Jan 03, 2026 at 08:36:46PM +0000, Maciej W. Rozycki wrote: > On Fri, 2 Jan 2026, Thomas Weißschuh wrote: (...) > > > Also does the n32 ABI have to be factored in, since IIUC this > > > stuff is about user programs? > > > > It can be added, but I don't think it makes much sense. > > It would only be used if CONFIG_MIPS32_N32=y (which is non-default) and if > > the toolchain which has no n64 libc, but does have a n32 libc. > > This seems unlikely to me, but let me know if I am mistaken. > > My observation over the years has been that n32 has become the industry > standard for 64-bit MIPS configurations; it's the default arrangement too > for the GNU compiler for `mips64*-*-linux-gnu' targets in the absence of > explicit `--with-abi=64' `configure' option, and no multilib support may > have been enabled in the compiler (which is not required to build Linux, > as 64-bit MIPS GCC and binutils are always able to produce code for all > the ABIs regardless). (...) > It's not clear to me offhand how the infrastructure concerned here is > used, but it may make sense to default to either NewABI and resort to the > other if the default turns out unsupported in a given environment. This > for a change I cannot decide on based on information I've gathered so far. This infrastructure is currently used for example programs which are part of the kernel tree. I also want to extend it to test programs [0]. While CONFIG_MIPS32_N32 is optional and off by default on the kernel side, it seems to be enabled by all the relevant defconfigs. Given that it is the default on the toolchain side, I agree that it is probably the right choice. [0] https://lore.kernel.org/lkml/20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de/ Thomas
© 2016 - 2026 Red Hat, Inc.