X32 System V Application Binary Interface
A new 32bit psABI for x86-64 with 32bit pointer size.
|
|
News
- As of revision 177914, all x32 changes have been merged with GCC trunk.
- Update x32 psABI to add R_X86_64_RELATIVE64 relocation for x32.
- Update x32 psABI to allow R_X86_64_64 relocation.
- Update x32 psABI to specify that pointers are zero-extended to 64bit when returned or passed in a register.
- The preliminary system call number scheme is:
- In kernel, x86-64 and x32 share the same system call slot if they are the same.
- First 512 system call slots are reserved for common and x86-64 specific ones. X32 specific system call slots start at 512.
- All x32 system call numbers have the bit 30 set.
- This scheme is implemented on hjl/x32/syscall/v3.0 kernel branch.
- Its source is available on hjl/x32 banch at
               http://git.kernel.org/?p=devel/binutils/hjl/x86-64-psabi.git;a=summary
- The GNU binutils support is available on master branch at
http://sourceware.org/git/?p=binutils.git;a=summary
Only GNU linker supports x32. Gold doesn't support x32.
Only GNU linker supports x32. Gold doesn't support x32.
- Linux kernel 3.0 prototype is available on hjl/x32/syscall/v3.0 branch at
http://git.kernel.org/?p=linux/kernel/git/hjl/linux-2.6.git;a=summary
X32 support is enabled by setting CONFIG_X86_X32_ABI=y in .config.
X32 support is enabled by setting CONFIG_X86_X32_ABI=y in .config.
- GDB support is on hjl/x32 branch at
- Glibc port is on hjl/x32 branch at
- X32 is functional complete with C, C++, Objective C and Fortran on GCC trunk as of revision 177914.
Related work:
-
J. Liu and Y. Wu. Performance characterization of the 64-bit x86 architecture from compiler optimizationsâ perspective. In Proceedings of the International Conference on Compiler Construction, CCâ06, 2006
Comparison
- Test machines:
- Fedora 14/x86-64
- kernel-2.6.35.11-84.3.fc14
- glibc-2.13-1
- X32 glibc
- 181.mcf from SPEC CPU 2000 (memory bound):
- Intel Core i7
- ~32% faster than x86-64.
- ~1% slower than ia32.
- Sizes in bytes:
                    text     data      bss      dec      hex   filename
                 12155      336     7036    19527     4c47   mcf.32
                12421      664    13568    26653    681d   mcf.64
                 11583      412     7040    19035     4a5b   mcf.x32
                 12155      336     7036    19527     4c47   mcf.32
                12421      664    13568    26653    681d   mcf.64
                 11583      412     7040    19035     4a5b   mcf.x32
- Intel Atom
- ~28% faster than x86-64.
- ~0.5% slower than ia32.
- Sizes in bytes:
                    text     data      bss      dec      hex   filename
                 12059      336     7036    19431     4be7   mcf.32
                 12341      664    13568    26573    67cd   mcf.64
                  11411      412     7040    18863     49af   mcf.x32
                    text     data      bss      dec      hex   filename
                200519    16388   1068916   1285823    139ebf   crafty.32
                172389    16868   1069784   1259041    133621   crafty.64
                174723    16564   1068916   1260203    133aab   crafty.x32
                 text     data      bss      dec      hex   filename
             199339    16388   1068916   1284643    139a23   crafty.32
             171157    16868   1069784   1257809    133151   crafty.64
             173535    16564   1068916   1259015    133607   crafty.x32
                 12059      336     7036    19431     4be7   mcf.32
                 12341      664    13568    26573    67cd   mcf.64
                  11411      412     7040    18863     49af   mcf.x32
- 186.crafty from SPEC CPU 2000 (64bit integer):
- Intel Core i7
- ~5% slower than x86-64.
- ~29% faster than ia32.
- Sizes in bytes:
                200519    16388   1068916   1285823    139ebf   crafty.32
                172389    16868   1069784   1259041    133621   crafty.64
                174723    16564   1068916   1260203    133aab   crafty.x32
- Intel Atom
- ~6% slower than x86-64.
- ~7% faster than ia32.
- Sizes in bytes:
             199339    16388   1068916   1284643    139a23   crafty.32
             171157    16868   1069784   1257809    133151   crafty.64
             173535    16564   1068916   1259015    133607   crafty.x32
X32 API
- X32 API is designed for environments where the current ia32 API is sufficient. It can be viewed as ia32 with register extended to 64bit plus 8 more registers as well as IP relative address. Everything else is still 32bit.
- X32 kernel interface uses the same kernel structure layouts as ia32, implemented with "syscall" instruction.
- Use the same 64bit system calls with 64bit arguments:
- Both 32bit and 64bit values can be passed in 64bit argument.
- Â In kernel facing data structures, the long long field in struct/union is aligned at 4 byte, not 8 byte.
- The future x32 kernel system call interface:
- Should we change time_t from 32bit to 64bit?
Get Started
- Install Fedora 15/x86-64 with the latest updates.
- Get x32 enabled rpms from
- Update to x32 enabled yum first: # yum update yum
- Update to x32 enabled rpm and kernel: # yum update
- Install glibc x32 binary rpms: # yum install glibc-devel.x32glibc-static.x32
- Untar x32 libgcc under /.
- Install the latest binutils:
- Download the latest binutils snapshot from:
ftp://sourceware.org/pub/binutils/snapshots/binutils-2.21.51.tar.bz2
- Configure, build and install binutils as usual:
- ../configure --target=x86_64-pc-linux-gnu ....
- Make sure that the new x32 as, ld .... are in the front of your PATH such that they will be used by x32 GCC.
- Install x32 GDB:
- Check out hjl/x32 branch at:
http://git.kernel.org/?p=devel/gdb/hjl/x86.git;a=summary - Configure, build and install GDB as usual:
- ../configure --target=x86_64-pc-linux-gnu ....
- X32 GDB can debug ia32, x86-64 and x32 binaries.
- Install x32 GCC
- Check out GCC trunk.
- Configure GCC with --enable-languages=c,c++,fortran,objc --with-multilib-list=m32,m64,mx32
- Build and install x32 GCC:
- Copy x32 libgcc_s.so.1 to /libx32 by hand.
- X32 GCC supports:
- -m32: To generate ia32 binaries.
- -m64: To generate x86-64 binaries.
- -mx32: To generate x32 binaries.
- Build x32 glibc:
- Check out glibc hjl/x32 branch at:
http://git.kernel.org/?p=devel/glibc/hjl/x86.git;a=summary
- Configure glibc with:
            CC="x32-gcc -mx32" CXX="x32-g++ -mx32" CFLAGS="-O2 -g" ../configure
            (the "x32-" prefix is only needed if you installed your tools that way)
            "make xcheck" should only have a few expected failures:
            "make xcheck" should only have a few expected failures:
- nptl/tst-cancel-wrappers.out
- rt/tst-cpuclock2.out
- rt/tst-cputimer1.out
- The target tuple is the same as an x86_64 system. e.g. x86_64-linux
- The toolchain will support both x86_64 and x32 binaries. The default is still x86_64, but x32 support can be selected by various flags at runtime:
- Selecting x32 depends on the tool:
- gas: --x32
- ld: -m elf32_x86_64
- gcc: -mx32
- gdb: bfd automatically detects things
- gcc will automatically pass the correct flags down to the assembler/linker when it is given -mx32 itself.
- Differences between x32 and x86_64:
- long and pointer sizes:
- X32: 32bits.
- X86_64: 64bits
- Library API is the same as ia32.
- To compile a package for x32:
- Always add -mx32 to compiler and configure it as x86-64:
- To configure C and C++ programs, use
- CC="gcc -mx32 " CXX="g++ -mx32" ./configure
- Add x32 support on existing x86_64 support:
- C/C++ codes:
- Use int64_t or long long instead of long for 64bit integer.
- Assembler codes:
- Use 32bit instructions on long and pointer.
- You can do
            #ifdef __x86_64__
            ...
            # ifdef __LP64__
              LP64 code
            # else
               X32 code
            # endif
            ....
            #endif /* __x86_64__ support. */
            See libgcc/config/i386/morestack.S on x32 branch in GCC source for examples.
            ...
            # ifdef __LP64__
              LP64 code
            # else
               X32 code
            # endif
            ....
            #endif /* __x86_64__ support. */
            See libgcc/config/i386/morestack.S on x32 branch in GCC source for examples.
What You Can Help
- GCC
- The current x32 implementation isn't optimized:
- Atom LEA optimization is disabled.
- Memory addressing should be optimized.
- Enable other languages for x32.
- Kernel:
- The preliminary system call number scheme is:
- In kernel, x86-64 and x32 share the same system call slot if they are the same.
- First 512 system call slots are reserved for common and x86-64 specific ones. X32 specific system call slots start at 512.
- All x32 system call numbers have the bit 30 set.
- Add a meta register to ptrace interface to identify x32 process.
- Port additional packages:
- strace
- valgrind
- openssl
- gmp
- mpfr