public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] MIPS: Implement ARCH_HAS_CC_CAN_LINK
@ 2026-01-09 10:08 Thomas Weißschuh
  2026-02-09 11:59 ` Thomas Bogendoerfer
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Weißschuh @ 2026-01-09 10:08 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Maciej W. Rozycki, linux-mips, linux-kernel,
	Thomas Weißschuh

The generic CC_CAN_LINK detection does not handle different byte orders
or ABIs. This may lead to userprogs which are not actually runnable on
the target kernel.

Use architecture-specific logic supporting byte orders instead.

Modern 64-bit toolchains default to a n32 libc, which are not
supported by all kernel configurations, as MIPS32_N32 is optional.
On 64-bit, test for a n32 ABI libc first and fall back to o64 and
o32 if necessary.

Link: https://lore.kernel.org/lkml/20260105100507-14db55e3-aa71-48bf-a6ac-33b186bd082f@linutronix.de/
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Changes in v2:
- Use -mabi= over -m32/-m64
- Link to v1: https://lore.kernel.org/r/20251222-cc-can-link-mips-v1-1-6d87a8afe442@linutronix.de
---
 arch/mips/Kconfig | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index b88b97139fa8..862a86cec501 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,33 @@ 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_N32
+	bool
+	default $(cc_can_link_user,-mabi=n32 -EL) if MIPS32_N32 && CPU_LITTLE_ENDIAN
+	default $(cc_can_link_user,-mabi=n32 -EB) if MIPS32_N32 && CPU_BIG_ENDIAN
+
+config ARCH_CC_CAN_LINK_N64
+	bool
+	default $(cc_can_link_user,-mabi=64 -EL) if 64BIT && CPU_LITTLE_ENDIAN
+	default $(cc_can_link_user,-mabi=64 -EB) if 64BIT && CPU_BIG_ENDIAN
+
+config ARCH_CC_CAN_LINK_O32
+	bool
+	default $(cc_can_link_user,-mabi=32 -EL) if (32BIT || MIPS32_O32) && CPU_LITTLE_ENDIAN
+	default $(cc_can_link_user,-mabi=32 -EB) if (32BIT || MIPS32_O32) && CPU_BIG_ENDIAN
+
+config ARCH_CC_CAN_LINK
+	def_bool ARCH_CC_CAN_LINK_N32 || ARCH_CC_CAN_LINK_N64 || ARCH_CC_CAN_LINK_O32
+
+config ARCH_USERFLAGS
+	string
+	default "-mabi=n32 -EL" if ARCH_CC_CAN_LINK_N32 && CPU_LITTLE_ENDIAN
+	default "-mabi=n32 -EB" if ARCH_CC_CAN_LINK_N32 && CPU_BIG_ENDIAN
+	default "-mabi=64 -EL" if ARCH_CC_CAN_LINK_N64 && CPU_LITTLE_ENDIAN
+	default "-mabi=64 -EB" if ARCH_CC_CAN_LINK_N64 && CPU_BIG_ENDIAN
+	default "-mabi=32 -EL" if ARCH_CC_CAN_LINK_O32 && CPU_LITTLE_ENDIAN
+	default "-mabi=32 -EB" if ARCH_CC_CAN_LINK_O32 && 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>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] MIPS: Implement ARCH_HAS_CC_CAN_LINK
  2026-01-09 10:08 [PATCH v2] MIPS: Implement ARCH_HAS_CC_CAN_LINK Thomas Weißschuh
@ 2026-02-09 11:59 ` Thomas Bogendoerfer
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Bogendoerfer @ 2026-02-09 11:59 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: Maciej W. Rozycki, linux-mips, linux-kernel

On Fri, Jan 09, 2026 at 11:08:49AM +0100, Thomas Weißschuh wrote:
> The generic CC_CAN_LINK detection does not handle different byte orders
> or ABIs. This may lead to userprogs which are not actually runnable on
> the target kernel.
> 
> Use architecture-specific logic supporting byte orders instead.
> 
> Modern 64-bit toolchains default to a n32 libc, which are not
> supported by all kernel configurations, as MIPS32_N32 is optional.
> On 64-bit, test for a n32 ABI libc first and fall back to o64 and
> o32 if necessary.
> 
> Link: https://lore.kernel.org/lkml/20260105100507-14db55e3-aa71-48bf-a6ac-33b186bd082f@linutronix.de/
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
> Changes in v2:
> - Use -mabi= over -m32/-m64
> - Link to v1: https://lore.kernel.org/r/20251222-cc-can-link-mips-v1-1-6d87a8afe442@linutronix.de
> ---
>  arch/mips/Kconfig | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)

applied to mips-next
Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-02-09 11:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-09 10:08 [PATCH v2] MIPS: Implement ARCH_HAS_CC_CAN_LINK Thomas Weißschuh
2026-02-09 11:59 ` Thomas Bogendoerfer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox