All of 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

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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.