Skip to contentSkip to conversation

Add support for the x86-64 x32 ABI for glibc and musl.

PATCH Superseded Guido Hatzsis 3 participants 6 messages Aug 20, 2015 – Aug 21, 2015 Kbuild

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Add support for the x86-64 x32 ABI for glibc and musl.

x32 uses 32-bit pointers on the x84-64 linux target. The kernel needs to have CONFIG_X86_X32 enabled. For more information see:
https://en.wikipedia.org/wiki/X32_ABI

Changes v1 -> v2:
Adding links for libx32 -> lib
Added copying for libs to staging directory.

---
 Makefile                                |  4 ++++
 arch/Config.in.x86                      | 29 +++++++++++++++++++++++++++++
 package/Makefile.in                     |  5 +++++
 package/glibc/glibc.mk                  |  2 +-
 package/uclibc/Config.in                |  1 +
 toolchain/toolchain-buildroot/Config.in |  1 +
 6 files changed, 41 insertions(+), 1 deletion(-)
Makefile +4 -0
index b4cef3f..d50161f 100644
@@ -448,7 +448,11 @@ $(BUILD_DIR) $(TARGET_DIR) $(HOST_DIR) $(BINARIES_DIR) $(LEGAL_INFO_DIR) $(REDIS
 # We make a symlink lib32->lib or lib64->lib as appropriate
 # MIPS64/n32 requires lib32 even though it's a 64-bit arch.
 ifeq ($(BR2_ARCH_IS_64)$(BR2_MIPS_NABI32),y)
+ifeq ($(BR2_X86_64_ABI_X32),y)
+LIB_SYMLINK= libx32
+else
 LIB_SYMLINK = lib64
+endif
 else
 LIB_SYMLINK = lib32
 endif
arch/Config.in.x86 +29 -0
index 43f6abc..baaeae1 100644
@@ -268,3 +268,32 @@ config BR2_GCC_TARGET_ARCH
 	default "c3"		if BR2_x86_c3
 	default "c3-2"		if BR2_x86_c32
 	default "geode"		if BR2_x86_geode
+
+choice
+       prompt "Target ABI"
+       depends on BR2_x86_64
+       default BR2_X86_64_ABI_GCC
+       help
+         Application Binary Interface to use. The Application Binary
+         Interface describes the calling conventions (how arguments
+         are passed to functions, how the return value is passed, how
+         system calls are made, etc.).
+
+config BR2_X86_64_ABI_GNU
+       bool "gnu"
+       depends on BR2_x86_64
+       help
+      This is the gnu ABI for x86-64 which has 64-bits wide pointers.
+
+config BR2_X86_64_ABI_X32
+       bool "x32"
+       depends on BR2_x86_64
+       help
+      The X32 ABI is x86-64 with 32 bit pointers. It runs in x86-64 mode
+      but as it has 32-bit pointers only 4 GB of RAM can be addressed.
+      https://en.wikipedia.org/wiki/X32_ABI
+
+endchoice
+
+config BR2_GCC_TARGET_ABI
+    default "x32"      if BR2_X86_64_ABI_X32
package/Makefile.in +5 -0
index 545694f..db2c0f0 100644
@@ -70,6 +70,11 @@ ABI := $(ABI)hf
 endif
 endif
 
+# Only set the ABI for x86-64 x32.
+ifeq ($(BR2_X86_64_ABI_X32),y)
+ABI = x32
+endif
+
 # For FSL PowerPC there's SPE
 ifeq ($(BR2_powerpc_SPE),y)
 ABI = spe
package/glibc/glibc.mk +1 -1
index cbfbf32..59a81d9 100644
@@ -117,7 +117,7 @@ endif
 
 define GLIBC_INSTALL_TARGET_CMDS
 	for libs in $(GLIBC_LIBS_LIB); do \
-		$(call copy_toolchain_lib_root,$(STAGING_DIR)/,,lib,$$libs,/lib) ; \
+		$(call copy_toolchain_lib_root,$(STAGING_DIR)/,,$(if $(BR2_X86_64_ABI_X32),libx32,lib),$$libs,/lib) ; \
 	done
 endef
 
package/uclibc/Config.in +1 -0
index bf40a13..f4de98b 100644
@@ -3,6 +3,7 @@ if BR2_TOOLCHAIN_BUILDROOT_UCLIBC
 # For legal-info
 config BR2_PACKAGE_UCLIBC
 	bool
+    depends on !BR2_X86_64_ABI_X32
 	default y
 
 comment "uClibc Options"
toolchain/toolchain-buildroot/Config.in +1 -0
index 13e2b15..a2ce5cd 100644
@@ -34,6 +34,7 @@ config BR2_TOOLCHAIN_BUILDROOT_UCLIBC
 		   BR2_mips    || BR2_mipsel || BR2_mips64 || BR2_mips64el || \
 		   BR2_powerpc || BR2_sh2a   || BR2_sh4	   || BR2_sh4eb    || \
 		   BR2_sparc   || BR2_xtensa || BR2_x86_64
+	depends on !BR2_X86_64_ABI_X32
 	help
 	  This option selects uClibc as the C library for the
 	  cross-compilation toolchain.
Signature · 1 line
2.5.0
#1 lore raw

PATCH v2 1/1 Add support for the x86-64 x32 ABI for glibc and musl.

Dear Guido Hatzsis,

Thanks for this contribution! Great to see someone working on x32 support!

Quoted 7 lines · Guido Hatzsis

x32 uses 32-bit pointers on the x84-64 linux target. The kernel needs to have CONFIG_X86_X32 enabled. For more information see:
https://en.wikipedia.org/wiki/X32_ABI

Changes v1 -> v2:
Adding links for libx32 -> lib
Added copying for libs to staging directory.

The changelog should go below the "---" sign after the Signed-off-by statement, since we don't want the changelog to be kept in the final commit.

Makefile $(BUILD_DIR) $(TARGET_DIR) $(HOST_DIR) $(BINARIES_DIR) $(LEGAL_INFO_DIR) $(REDIS · line 452

Quoted 10 lines
Makefile +2 -0
index b4cef3f..d50161f 100644
@@ -448,7 +448,11 @@ $(BUILD_DIR) $(TARGET_DIR) $(HOST_DIR) $(BINARIES_DIR) $(LEGAL_INFO_DIR) $(REDIS
 # We make a symlink lib32->lib or lib64->lib as appropriate
 # MIPS64/n32 requires lib32 even though it's a 64-bit arch.
 ifeq ($(BR2_ARCH_IS_64)$(BR2_MIPS_NABI32),y)
+ifeq ($(BR2_X86_64_ABI_X32),y)
+LIB_SYMLINK= libx32

Space after LIB_SYMLINK.

Quoted 11 lines
Makefile +2 -0
+else
 LIB_SYMLINK = lib64
+endif
 else
 LIB_SYMLINK = lib32
 endif
arch/Config.in.x86 +0 -0
index 43f6abc..baaeae1 100644

arch/Config.in.x86 config BR2_GCC_TARGET_ARCH · line 275

Quoted 8 lines
arch/Config.in.x86 +5 -0
@@ -268,3 +268,32 @@ config BR2_GCC_TARGET_ARCH
 	default "c3"		if BR2_x86_c3
 	default "c3-2"		if BR2_x86_c32
 	default "geode"		if BR2_x86_geode
+
+choice
+       prompt "Target ABI"
+       depends on BR2_x86_64
+       default BR2_X86_64_ABI_GCC

This option does not exist. You called it BR2_X86_64_ABI_GNU.

arch/Config.in.x86 config BR2_GCC_TARGET_ARCH · line 284

Quoted 9 lines
arch/Config.in.x86 +9 -0
+       help
+         Application Binary Interface to use. The Application Binary
+         Interface describes the calling conventions (how arguments
+         are passed to functions, how the return value is passed, how
+         system calls are made, etc.).
+
+config BR2_X86_64_ABI_GNU
+       bool "gnu"
+       depends on BR2_x86_64

Not needed, the entire choice depends on BR2_x86_64.

arch/Config.in.x86 config BR2_GCC_TARGET_ARCH · line 286

Quoted 2 lines
arch/Config.in.x86 +2 -0
+       help
+      This is the gnu ABI for x86-64 which has 64-bits wide pointers.

Indentation should be one tab + two spaces. Also, please indicate here that something such as "This is the default ABI on x86-64, and should be used unless you know what you are doing".

arch/Config.in.x86 config BR2_GCC_TARGET_ARCH · line 290

Quoted 4 lines
arch/Config.in.x86 +4 -0
+
+config BR2_X86_64_ABI_X32
+       bool "x32"
+       depends on BR2_x86_64

Not needed.

arch/Config.in.x86 config BR2_GCC_TARGET_ARCH · line 294

Quoted 4 lines
arch/Config.in.x86 +4 -0
+       help
+      The X32 ABI is x86-64 with 32 bit pointers. It runs in x86-64 mode
+      but as it has 32-bit pointers only 4 GB of RAM can be addressed.
+      https://en.wikipedia.org/wiki/X32_ABI

Please fix the indentation: one tab + two spaces.

arch/Config.in.x86 config BR2_GCC_TARGET_ARCH · line 299

Quoted 5 lines
arch/Config.in.x86 +5 -0
+
+endchoice
+
+config BR2_GCC_TARGET_ABI
+    default "x32"      if BR2_X86_64_ABI_X32

Do we need to provide a value for BR2_X86_64_ABI_GNU ? Or the ABI is empty ?

Quoted 21 lines
package/Makefile.in +5 -0
index 545694f..db2c0f0 100644
@@ -70,6 +70,11 @@ ABI := $(ABI)hf
 endif
 endif
 
+# Only set the ABI for x86-64 x32.
+ifeq ($(BR2_X86_64_ABI_X32),y)
+ABI = x32
+endif
+
 # For FSL PowerPC there's SPE
 ifeq ($(BR2_powerpc_SPE),y)
 ABI = spe
package/glibc/glibc.mk +0 -0
index cbfbf32..59a81d9 100644

package/glibc/glibc.mk endif · line 120

Quoted 5 lines
package/glibc/glibc.mk +1 -1
@@ -117,7 +117,7 @@ endif
 
 define GLIBC_INSTALL_TARGET_CMDS
 	for libs in $(GLIBC_LIBS_LIB); do \
-		$(call copy_toolchain_lib_root,$(STAGING_DIR)/,,lib,$$libs,/lib) ; \
+		$(call copy_toolchain_lib_root,$(STAGING_DIR)/,,$(if $(BR2_X86_64_ABI_X32),libx32,lib),$$libs,/lib) ; \

Hum, I'm not too happy with this. How does it work for normal x86-64 toolchains that want lib64 as the library directory?

package/uclibc/Config.in if BR2_TOOLCHAIN_BUILDROOT_UCLIBC · line 6

Quoted 12 lines
package/glibc/glibc.mk +0 -0
 	done
 endef
 
package/uclibc/Config.in +1 -0
index bf40a13..f4de98b 100644
@@ -3,6 +3,7 @@ if BR2_TOOLCHAIN_BUILDROOT_UCLIBC
 # For legal-info
 config BR2_PACKAGE_UCLIBC
 	bool
+    depends on !BR2_X86_64_ABI_X32

Change not needed, since you're doing a change in toolchain/toolchain-buildroot/Config.in to prevent selecting uClibc.

toolchain/toolchain-buildroot/Config.in config BR2_TOOLCHAIN_BUILDROOT_UCLIBC · line 37

Quoted 12 lines
package/uclibc/Config.in +0 -0
 	default y
 
 comment "uClibc Options"
toolchain/toolchain-buildroot/Config.in +1 -0
index 13e2b15..a2ce5cd 100644
@@ -34,6 +34,7 @@ config BR2_TOOLCHAIN_BUILDROOT_UCLIBC
 		   BR2_mips    || BR2_mipsel || BR2_mips64 || BR2_mips64el || \
 		   BR2_powerpc || BR2_sh2a   || BR2_sh4	   || BR2_sh4eb    || \
 		   BR2_sparc   || BR2_xtensa || BR2_x86_64
+	depends on !BR2_X86_64_ABI_X32

I would prefer the following change:

-  		   BR2_sparc   || BR2_xtensa || BR2_x86_64
+ 		   BR2_sparc   || BR2_xtensa || (BR2_x86_64 && BR2_X86_64_ABI_GNU)

Also, you need to:

* Verify that the musl C library supports the x32 ABI, and if not, make it unavailable when x32 is selected.

* Make the relevant external x86-64 toolchains depend on BR2_X86_64_ABI_GNU. You can have a look at how we handle ARM EABI vs. ARM EABIhf toolchains to see how to do this.

* Ideally, we would need to check if we have packages that package pre-built x86-64 binaries. And if we have such packages, then they should probably depend on BR2_X86_64_ABI_GNU. Of course, I'm assuming here that linking x32 binaries/libraries with x86-64 nu binaries/libraries does not work.

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH v2 1/1 Add support for the x86-64 x32 ABI for glibc and musl.

Thomas,

I just have a couple of questions:

20.08.2015, 17:16, "Thomas Petazzoni" <[email protected]>:

Quoted 9 lines
Quoted 4 lines

?+endchoice
?+
?+config BR2_GCC_TARGET_ABI
?+ default "x32" if BR2_X86_64_ABI_X32

Do we need to provide a value for BR2_X86_64_ABI_GNU ? Or the ABI is empty ?

Quoted 8 lines
Quoted 4 lines

??define GLIBC_INSTALL_TARGET_CMDS
??????????for libs in $(GLIBC_LIBS_LIB); do \
?- $(call copy_toolchain_lib_root,$(STAGING_DIR)/,,lib,$$libs,/lib) ; \
?+ $(call copy_toolchain_lib_root,$(STAGING_DIR)/,,$(if $(BR2_X86_64_ABI_X32),libx32,lib),$$libs,/lib) ; \

Hum, I'm not too happy with this. How does it work for normal x86-64 toolchains that want lib64 as the library directory?

I think that those two are related. The ABI is part of the x86-64 arch. Glibc uses libx32 and lib (not lib32 and lib64) when not using multilib. This is done here.

205 ifneq ($(call qstrip,$(BR2_GCC_TARGET_ABI)),)
206 HOST_GCC_COMMON_CONF_OPTS += --with-abi=$(BR2_GCC_TARGET_ABI) 207 endif

Do you need to set the BR2_GCC_TARGET_ABI to empty? Is this the convention?

Guido

#3 lore raw

PATCH v2 1/1 Add support for the x86-64 x32 ABI for glibc and musl.

Hi Guido,

I tried this version on the latest master and it worked further. Thank you for your work!

However it seems some packet lack support of x32.

I found out at least kexec, libffi and openssl have problems

kexec

/home/serg/projects/buildroot/output/host/usr/bin/x86_64-umsiteroot-linux-muslx32-gcc
-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os
-fno-strict-aliasing -Wall -Wstrict-prototypes -D_LARGEFILE_SOURCE
-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I./include
-I./util_lib/include -Iinclude/ -I./kexec/arch/x86_64/include -c -MD -o kexec/arch/x86_64/kexec-bzImage64.o kexec/arch/x86_64/kexec-bzImage64.c /home/serg/projects/buildroot/output/host/usr/bin/x86_64-umsiteroot-linux-muslx32-gcc
-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os
-fno-strict-aliasing -Wall -Wstrict-prototypes
-fno-zero-initialized-in-bss -mcmodel=large -Os -fno-builtin -ffreestanding -mcmodel=large -I./purgatory/include -I./purgatory/arch/x86_64/include -I./util_lib/include -I./include -Iinclude -I/home/serg/projects/buildroot/output/host/usr/lib/gcc/x86_64-umsiteroot-linux-muslx32/4.9.3/include
-c -MD -o purgatory/purgatory.o purgatory/purgatory.c
purgatory/purgatory.c:1:0: error: code model ?large? not supported in x32
mode

^

libffi is used by Python and many others.
It seems it mistakenly tries to compile legacy x86 code

libtool: compile:
/home/serg/projects/buildroot/output/host/usr/bin/x86_64-umsiteroot-linux-muslx32-gcc
-DHAVE_CONFIG_H -I. -I.. -I. -I../include -Iinclude -I../src -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I. -I../include -Iinclude -I../src -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -c ../src/x86/sysv.S -fPIC -DPIC -o src/x86/.libs/sysv.o
../src/x86/win32.S: Assembler messages:
../src/x86/win32.S:524: Error: invalid instruction suffix for push' ../src/x86/win32.S:535: Error: invalid instruction suffix for push' ../src/x86/win32.S:536: Error: invalid instruction suffix for push' ../src/x86/win32.S:608: Error: operand type mismatch for jmp' ../src/x86/win32.S:682: Error: invalid instruction suffix for pop' ../src/x86/win32.S:695: Error: operand type mismatch for push' ../src/x86/win32.S:708: Error: operand type mismatch for push' ../src/x86/win32.S:709: Error: operand type mismatch for push' ../src/x86/win32.S:724: Error: invalid instruction suffix for push' ../src/x86/win32.S:779: Error: operand type mismatch for jmp' ../src/x86/win32.S:834: Error: invalid instruction suffix for pop' ../src/x86/win32.S:846: Error: invalid instruction suffix for pop' ../src/x86/win32.S:887: Error: invalid instruction suffix for push' ../src/x86/win32.S:891: Error: invalid instruction suffix for push' ../src/x86/win32.S:934: Error: operand type mismatch for jmp' ../src/x86/win32.S:992: Error: invalid instruction suffix for pop' ../src/x86/win32.S:993: Error: invalid instruction suffix for pop' ../src/x86/win32.S:1010: Error: invalid instruction suffix for push' ../src/x86/win32.S:1062: Error: operand type mismatch for jmp' ../src/x86/win32.S:1120: Error: invalid instruction suffix for pop' ../src/x86/win32.S:1121: Error: invalid instruction suffix for pop' ../src/x86/win32.S:1122: Error: invalid instruction suffix for pop' ../src/x86/win32.S:1133: Error: operand type mismatch for `jmp'
make[5]: *** [src/x86/win32.lo] Error 1
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [all-recursive] Error 1
make[3]: *** [all] Error 2
make[2]: *** [all-all] Error 2
make[1]: *** [/home/serg/projects/buildroot/output/build/libffi-3.1/.stamp_built] Error 2

Quoted 33 lines · Guido Hatzsis

Thomas,

I just have a couple of questions:

20.08.2015, 17:16, "Thomas Petazzoni" <[email protected]

Quoted 14 lines

:

Quoted 4 lines

+endchoice
+
+config BR2_GCC_TARGET_ABI
+ default "x32" if BR2_X86_64_ABI_X32

Do we need to provide a value for BR2_X86_64_ABI_GNU ? Or the ABI is empty ?

Quoted 4 lines

define GLIBC_INSTALL_TARGET_CMDS

          for libs in $(GLIBC_LIBS_LIB); do \

- $(call copy_toolchain_lib_root,$(STAGING_DIR)/,,lib,$$libs,/lib) ; \
+ $(call copy_toolchain_lib_root,$(STAGING_DIR)/,,$(if

$(BR2_X86_64_ABI_X32),libx32,lib),$$libs,/lib) ; \

Quoted 4 lines

Hum, I'm not too happy with this. How does it work for normal x86-64 toolchains that want lib64 as the library directory?

I think that those two are related. The ABI is part of the x86-64 arch. Glibc uses libx32 and lib (not lib32 and lib64) when not using multilib. This is done here.

205 ifneq ($(call qstrip,$(BR2_GCC_TARGET_ABI)),)
206 HOST_GCC_COMMON_CONF_OPTS += --with-abi=$(BR2_GCC_TARGET_ABI) 207 endif

Quoted 8 lines

Do you need to set the BR2_GCC_TARGET_ABI to empty? Is this the convention?

Guido
_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20150821/c5dc8f86/attachment.html>

#4 lore raw

PATCH v2 1/1 Add support for the x86-64 x32 ABI for glibc and musl.

In reply to Guido Hatzsis

Dear Guido Hatzsis,

Quoted 9 lines · Guido Hatzsis
Quoted 8 lines
Quoted 4 lines

??define GLIBC_INSTALL_TARGET_CMDS
??????????for libs in $(GLIBC_LIBS_LIB); do \
?- $(call copy_toolchain_lib_root,$(STAGING_DIR)/,,lib,$$libs,/lib) ; \
?+ $(call copy_toolchain_lib_root,$(STAGING_DIR)/,,$(if $(BR2_X86_64_ABI_X32),libx32,lib),$$libs,/lib) ; \

Hum, I'm not too happy with this. How does it work for normal x86-64 toolchains that want lib64 as the library directory?

Quoted 7 lines

I think that those two are related. The ABI is part of the x86-64 arch. Glibc uses libx32 and lib (not lib32 and lib64) when not using multilib. This is done here.

205 ifneq ($(call qstrip,$(BR2_GCC_TARGET_ABI)),)
206 HOST_GCC_COMMON_CONF_OPTS += --with-abi=$(BR2_GCC_TARGET_ABI) 207 endif

Do you need to set the BR2_GCC_TARGET_ABI to empty? Is this the convention?

No, no.

But you make some changes in the main Makefile to have a libx32 -> lib symbolic link in the staging directory. So I don't see why you need to change glibc.mk to account for the libx32 thing, since libx32 is just a symlink to lib.

But maybe I need to test by myself to understand what's going on.

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#5 lore raw

PATCH v2 1/1 Add support for the x86-64 x32 ABI for glibc and musl.

Ah ok, thanks for clarifying that. I will remove that.

Cheers

Guido
21.08.2015, 04:48, "Thomas Petazzoni" <[email protected]>:

Quoted 37 lines

Dear Guido Hatzsis,

Quoted 9 lines · Guido Hatzsis

?>> ??define GLIBC_INSTALL_TARGET_CMDS
?>> ??????????for libs in $(GLIBC_LIBS_LIB); do \
?>> ?- $(call copy_toolchain_lib_root,$(STAGING_DIR)/,,lib,$$libs,/lib) ; \
?>> ?+ $(call copy_toolchain_lib_root,$(STAGING_DIR)/,,$(if $(BR2_X86_64_ABI_X32),libx32,lib),$$libs,/lib) ; \
?>
?> Hum, I'm not too happy with this. How does it work for normal x86-64
?> toolchains that want lib64 as the library directory?
?>

Quoted 7 lines

?I think that those two are related. The ABI is part of the x86-64 arch. Glibc uses libx32 and lib (not lib32 and lib64) when not using multilib. This is done here.

?205 ifneq ($(call qstrip,$(BR2_GCC_TARGET_ABI)),)
?206 HOST_GCC_COMMON_CONF_OPTS += --with-abi=$(BR2_GCC_TARGET_ABI) ?207 endif

?Do you need to set the BR2_GCC_TARGET_ABI to empty? Is this the convention?

No, no.

But you make some changes in the main Makefile to have a libx32 -> lib symbolic link in the staging directory. So I don't see why you need to change glibc.mk to account for the libx32 thing, since libx32 is just a symlink to lib.

But maybe I need to test by myself to understand what's going on.

Thanks,

Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com