Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] arch/x86: add support for x86_64 x32 ABI
@ 2025-12-11  9:58 brvs2022
  2025-12-30 13:12 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 3+ messages in thread
From: brvs2022 @ 2025-12-11  9:58 UTC (permalink / raw)
  To: buildroot@buildroot.org; +Cc: Romain Naour, Thomas Petazzoni

From d9e20f4b358b08de6c01fbb1e7b605e01332e2db Mon Sep 17 00:00:00 2001
From: Trevor Bastion <brvs2022@outlook.com>
Date: Thu, 11 Dec 2025 09:46:09 +0000
Subject: [PATCH] arch/x86: add support for x86_64 x32 ABI

Add support for the x86_64 x32 ABI, which uses the 64-bit x86
instruction set while keeping 32-bit pointers and size types.

Introduce a BR2_x86_64_x32 option, update the x86 toolchain and
architecture logic to recognize x32 as a valid ABI, and adjust
the READELF architecture name handling so x32 binaries are
reported consistently alongside i386 and pure x86_64.

Signed-off-by: Trevor Bastion <brvs2022@outlook.com>
Signed-off-by: Trevor Bastion <brvs2022@outlook.com>
---
 arch/Config.in             | 10 +++++++++-
 arch/Config.in.x86         | 13 +++++++++----
 linux/Config.in            |  2 +-
 package/Makefile.in        |  5 +++++
 package/glibc/Config.in    |  1 +
 package/glibc/glibc.mk     |  4 ++++
 package/iptables/Config.in |  2 ++
 package/musl/Config.in     |  1 +
 system/system.mk           |  5 +++++
 9 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/arch/Config.in b/arch/Config.in
index 34422c0d50..cc37de87bb 100644
--- a/arch/Config.in
+++ b/arch/Config.in
@@ -248,6 +248,14 @@ config BR2_x86_64
 	  architecture compatible microprocessor).
 	  http://en.wikipedia.org/wiki/X86_64
 
+config BR2_x86_x32_ABI
+	bool "x86_x32_ABI"
+	select BR2_USE_MMU
+	help
+	  The x32 ABI provides 32-bit integers, long and pointers (ILP32) on Intel
+	  and AMD 64-bit hardware. 
+	  https://en.wikipedia.org/wiki/X32_ABI
+
 config BR2_xtensa
 	bool "Xtensa"
 	# MMU support is set by the subarchitecture file, arch/Config.in.xtensa
@@ -433,7 +441,7 @@ if BR2_sparc || BR2_sparc64
 source "arch/Config.in.sparc"
 endif
 
-if BR2_i386 || BR2_x86_64
+if BR2_i386 || BR2_x86_64 || BR2_x86_x32_ABI
 source "arch/Config.in.x86"
 endif
 
diff --git a/arch/Config.in.x86 b/arch/Config.in.x86
index f9b32130b2..bd7aeddc6a 100644
--- a/arch/Config.in.x86
+++ b/arch/Config.in.x86
@@ -36,7 +36,7 @@ config BR2_X86_CPU_HAS_AVX512
 choice
 	prompt "Target Architecture Variant"
 	default BR2_x86_i586 if BR2_i386
-	depends on BR2_i386 || BR2_x86_64
+	depends on BR2_i386 || BR2_x86_64 || BR2_x86_x32_ABI
 	help
 	  Specific CPU variant to use
 
@@ -723,10 +723,15 @@ config BR2_ARCH
 	# i586).
 	default "i686"		if BR2_i386
 	default "x86_64"	if BR2_x86_64
+	default "x86_64"	if BR2_x86_x32_ABI
 
 config BR2_NORMALIZED_ARCH
-	default "i386"		if !BR2_x86_64
-	default "x86_64"	if BR2_x86_64
+	default "i386"		if !BR2_x86_64 && !BR2_x86_x32_ABI
+	default "x86_64"	if !BR2_i386 && !BR2_x86_x32_ABI
+	default "x86_64"	if !BR2_i386 && !BR2_x86_64
+
+config BR2_GCC_TARGET_ABI
+	default "mx32"		if BR2_x86_x32_ABI
 
 config BR2_ENDIAN
 	default "LITTLE"
@@ -804,7 +809,7 @@ config BR2_GCC_TARGET_ARCH
 
 config BR2_READELF_ARCH_NAME
 	default "Intel 80386"			if BR2_i386
-	default "Advanced Micro Devices X86-64" if BR2_x86_64
+	default "Advanced Micro Devices X86-64" if BR2_x86_64 || BR2_x86_x32_ABI
 
 # vim: ft=kconfig
 # -*- mode:kconfig; -*-
diff --git a/linux/Config.in b/linux/Config.in
index 10024bef38..569315a5d1 100644
--- a/linux/Config.in
+++ b/linux/Config.in
@@ -250,7 +250,7 @@ config BR2_LINUX_KERNEL_APPENDED_UIMAGE
 
 config BR2_LINUX_KERNEL_BZIMAGE
 	bool "bzImage"
-	depends on BR2_i386 || BR2_x86_64 || BR2_s390x
+	depends on BR2_i386 || BR2_x86_64 || BR2_x86_x32_ABI || BR2_s390x
 
 config BR2_LINUX_KERNEL_ZIMAGE
 	bool "zImage"
diff --git a/package/Makefile.in b/package/Makefile.in
index 5ebb5f9ba8..b9d991270e 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -67,6 +67,11 @@ else ifeq ($(BR_BUILDING),y)
 $(error No C library enabled, this is not possible.)
 endif
 
+ifeq ($(BR2_x86_x32_ABI),y)
+ABI = x32
+TARGET_ABI += -mx32
+endif
+
 # The ABI suffix is a bit special on ARM, as it needs to be
 # -uclibcgnueabi for uClibc EABI, and -gnueabi for glibc EABI.
 # This means that the LIBC and ABI aren't strictly orthogonal,
diff --git a/package/glibc/Config.in b/package/glibc/Config.in
index b066616a01..6642304644 100644
--- a/package/glibc/Config.in
+++ b/package/glibc/Config.in
@@ -20,6 +20,7 @@ config BR2_PACKAGE_GLIBC_ARCH_SUPPORTS
 	default y if BR2_sh
 	default y if BR2_sparc64
 	default y if BR2_x86_64
+	default y if BR2_x86_x32_ABI
 	default y if BR2_microblaze
 	default y if BR2_arcle && BR2_ARC_ATOMIC_EXT && !BR2_arc750d && !BR2_arc770d
 	depends on !BR2_POWERPC_CPU_HAS_SPE
diff --git a/package/glibc/glibc.mk b/package/glibc/glibc.mk
index a7727cbad8..a3fec13605 100644
--- a/package/glibc/glibc.mk
+++ b/package/glibc/glibc.mk
@@ -75,6 +75,10 @@ else ifeq ($(BR2_MIPS_OABI32),y)
 GLIBC_EXTRA_CFLAGS += -mabi=32
 endif
 
+ifeq ($(BR2_x86_x32_ABI),y)
+GLIBC_EXTRA_CFLAGS += -mx32
+endif
+
 ifeq ($(BR2_ENABLE_DEBUG),y)
 GLIBC_EXTRA_CFLAGS += -g
 endif
diff --git a/package/iptables/Config.in b/package/iptables/Config.in
index ef02c26242..e5a9b06152 100644
--- a/package/iptables/Config.in
+++ b/package/iptables/Config.in
@@ -1,5 +1,6 @@
 config BR2_PACKAGE_IPTABLES
 	bool "iptables"
+	depends on !BR2_x86_x32_ABI
 	help
 	  Linux kernel firewall, NAT, and packet mangling tools.
 
@@ -17,6 +18,7 @@ config BR2_PACKAGE_IPTABLES_NFTABLES
 	bool "nftables compat"
 	# uses dlfcn
 	depends on !BR2_STATIC_LIBS
+	depends on !BR2_x86_x32_ABI
 	depends on BR2_USE_WCHAR
 	depends on BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_12
 	select BR2_PACKAGE_LIBMNL
diff --git a/package/musl/Config.in b/package/musl/Config.in
index 70475326f5..a35af97e15 100644
--- a/package/musl/Config.in
+++ b/package/musl/Config.in
@@ -20,6 +20,7 @@ config BR2_PACKAGE_MUSL_ARCH_SUPPORTS
 	default y if BR2_s390x
 	default y if BR2_sh
 	default y if BR2_x86_64
+	default y if BR2_x86_x32_ABI
 	depends on !BR2_POWERPC_CPU_HAS_SPE # not supported, build breaks
 	depends on !(BR2_powerpc64 || BR2_powerpc64le) || BR2_POWERPC_CPU_HAS_ALTIVEC
 	# sh2 nommu is supported by musl, but we don't have support
diff --git a/system/system.mk b/system/system.mk
index 52e810868a..465d8c62db 100644
--- a/system/system.mk
+++ b/system/system.mk
@@ -84,6 +84,11 @@ define SYSTEM_LIB_SYMLINK
 	ln -snf lib $(1)/lib64
 	ln -snf lib $(1)/usr/lib64
 endef
+else ifeq ($(BR2_x86_x32_ABI),y) 
+define SYSTEM_LIB_SYMLINK
+	ln -snf lib $(1)/libx32
+	ln -snf lib $(1)/usr/libx32
+endef
 else
 define SYSTEM_LIB_SYMLINK
 	ln -snf lib $(1)/lib32
-- 
2.52.0

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH] arch/x86: add support for x86_64 x32 ABI
  2025-12-11  9:58 [Buildroot] [PATCH] arch/x86: add support for x86_64 x32 ABI brvs2022
@ 2025-12-30 13:12 ` Thomas Petazzoni via buildroot
  2025-12-30 17:21   ` Julien Olivain via buildroot
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Petazzoni via buildroot @ 2025-12-30 13:12 UTC (permalink / raw)
  To: brvs2022@outlook.com; +Cc: buildroot@buildroot.org, Romain Naour

Hello Trevor,

Thanks for your patch!

On Thu, 11 Dec 2025 09:58:29 +0000
"brvs2022@outlook.com" <brvs2022@outlook.com> wrote:

> From d9e20f4b358b08de6c01fbb1e7b605e01332e2db Mon Sep 17 00:00:00 2001
> From: Trevor Bastion <brvs2022@outlook.com>
> Date: Thu, 11 Dec 2025 09:46:09 +0000
> Subject: [PATCH] arch/x86: add support for x86_64 x32 ABI

It seems like you didn't use "git send-email", and therefore we have
this header within the e-mail body, which isn't quite good. Could you
use git send-email instead?

> Add support for the x86_64 x32 ABI, which uses the 64-bit x86
> instruction set while keeping 32-bit pointers and size types.

Is this still maintained/support in upstream gcc/glibc? I have vague
memories of discussions about dropping support for x32, but maybe my
memory is wrong.


> +config BR2_x86_x32_ABI
> +	bool "x86_x32_ABI"

You're adding support for it as if it's a separate architecture, which
is not correct. It should be an option inside the x86-64 architecture.


>  config BR2_NORMALIZED_ARCH
> -	default "i386"		if !BR2_x86_64
> -	default "x86_64"	if BR2_x86_64
> +	default "i386"		if !BR2_x86_64 && !BR2_x86_x32_ABI
> +	default "x86_64"	if !BR2_i386 && !BR2_x86_x32_ABI
> +	default "x86_64"	if !BR2_i386 && !BR2_x86_64

This seems odd. Aren't the last two lines better expressed as:

	default "x86_64"	if BR2_x86_64 || BR2_x86_x32_ABI

but of course that will change if BR2_x86_x32_ABI is no longer a
separate architecture.

> +config BR2_GCC_TARGET_ABI
> +	default "mx32"		if BR2_x86_x32_ABI

> +ifeq ($(BR2_x86_x32_ABI),y)
> +ABI = x32
> +TARGET_ABI += -mx32

I don't think assigning TARGET_ABI is needed here, because above,
you're setting BR2_GCC_TARGET_ABI to mx32 already, which has the
following consequence:

1. For internal toolchains: gcc is built with --with-abi=mx32

2. For external toolchains: the toolchain wrapper will pass -mabi=mx32


>  	depends on !BR2_POWERPC_CPU_HAS_SPE
> diff --git a/package/glibc/glibc.mk b/package/glibc/glibc.mk
> index a7727cbad8..a3fec13605 100644
> --- a/package/glibc/glibc.mk
> +++ b/package/glibc/glibc.mk
> @@ -75,6 +75,10 @@ else ifeq ($(BR2_MIPS_OABI32),y)
>  GLIBC_EXTRA_CFLAGS += -mabi=32
>  endif
>  
> +ifeq ($(BR2_x86_x32_ABI),y)
> +GLIBC_EXTRA_CFLAGS += -mx32

I'm also not 100% sure this is needed as gcc will be built with
--with-abi=mx32. Could you test without this?


> diff --git a/package/iptables/Config.in b/package/iptables/Config.in
> index ef02c26242..e5a9b06152 100644
> --- a/package/iptables/Config.in
> +++ b/package/iptables/Config.in
> @@ -1,5 +1,6 @@
>  config BR2_PACKAGE_IPTABLES
>  	bool "iptables"
> +	depends on !BR2_x86_x32_ABI

Is iptables the only problematic package?

Will you help fix x32 build issues in our autobuilders? Indeed, beyond
initial support, there is the on-going maintenance effort and we
clearly don't want to be "alone" to struggle with the x32 issues once
the support has been merged.

Thanks a lot!

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH] arch/x86: add support for x86_64 x32 ABI
  2025-12-30 13:12 ` Thomas Petazzoni via buildroot
@ 2025-12-30 17:21   ` Julien Olivain via buildroot
  0 siblings, 0 replies; 3+ messages in thread
From: Julien Olivain via buildroot @ 2025-12-30 17:21 UTC (permalink / raw)
  To: Thomas Petazzoni; +Cc: brvs2022, buildroot, Romain Naour

Hi Thomas,

On 30/12/2025 14:12, Thomas Petazzoni via buildroot wrote:
> Hello Trevor,
> 
> Thanks for your patch!
> 
> On Thu, 11 Dec 2025 09:58:29 +0000
> "brvs2022@outlook.com" <brvs2022@outlook.com> wrote:
[...]
>> Add support for the x86_64 x32 ABI, which uses the 64-bit x86
>> instruction set while keeping 32-bit pointers and size types.
> 
> Is this still maintained/support in upstream gcc/glibc? I have vague
> memories of discussions about dropping support for x32, but maybe my
> memory is wrong.

You may refer to this lkml thread [1] from December 2018.
Kernel CONFIG_X86_X32_ABI is apparently still there, as of
v6.18.2 [2]. It also seems Kernel and glibc are still receiving
patches for x32 from time to time (e.g. [3] [4]).

So even if it's a "niche" use-case, I believe it can still be a
candidate to be included in Buildroot (because x32 is still supported
in current and upcoming versions of upstream kernel/gcc/libc).

Best regards,

Julien.

[1] 
https://lore.kernel.org/lkml/CALCETrXoRAibsbWa9nfbDrt0iEuebMnCMhSFg-d9W-J2g8mDjw@mail.gmail.com/
[2] 
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/arch/x86/Kconfig?h=v6.18.2#n3140
[3] 
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=2883f01ec37dd8668e7222dfdb5980c86fdfe277
[4] 
https://sourceware.org/git/?p=glibc.git;a=history;f=sysdeps/unix/sysv/linux/x86_64/x32
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

end of thread, other threads:[~2025-12-30 17:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-11  9:58 [Buildroot] [PATCH] arch/x86: add support for x86_64 x32 ABI brvs2022
2025-12-30 13:12 ` Thomas Petazzoni via buildroot
2025-12-30 17:21   ` Julien Olivain via buildroot

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