[PATCH] MIPS: Implement ARCH_HAS_CC_CAN_LINK

Thomas Weißschuh posted 1 patch 1 month, 2 weeks ago
There is a newer version of this series
arch/mips/Kconfig | 15 +++++++++++++++
1 file changed, 15 insertions(+)
Re: [PATCH] MIPS: Implement ARCH_HAS_CC_CAN_LINK
Posted by Maciej W. Rozycki 1 month, 1 week ago
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
Re: [PATCH] MIPS: Implement ARCH_HAS_CC_CAN_LINK
Posted by Thomas Weißschuh 1 month, 1 week ago
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
Re: [PATCH] MIPS: Implement ARCH_HAS_CC_CAN_LINK
Posted by Maciej W. Rozycki 1 month ago
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
Re: [PATCH] MIPS: Implement ARCH_HAS_CC_CAN_LINK
Posted by Thomas Weißschuh 1 month ago
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