Santhosh Kumar
Santhosh Kumar

Reputation: 167

difference between i386:x64-32 vs i386 vs i386:x86_64

Can someone explain the difference between the three architectures? Actually when I built a 64-bit application in Linux, I got a link error saying:

skipping incompatible library.a when searching for library.a

Then I used objdump -f on that library and I got the below output:

a.o: file format elf32-x86-64
architecture: i386:x64-32, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000

Does it mean the library is 32-bit? Is that the reason I am getting the linker error?

Upvotes: 8

Views: 5687

Answers (2)

Severin Pappadeux
Severin Pappadeux

Reputation: 20080

Beyond usual full 64bit and good old 32bit ABI there is a special ABI (inspired by SGI n32 envirnment) where pointers are 32bit (thus they are 32bit apps), but it is designed to run on 64bit host and have full access to all x64 goodies:

  • native x64 registers and math
  • more registers
  • SSE2/3/4, AVX1/2/...
  • Full 4Gb address space on 64bit host

It is called x32 ABI, link: https://en.wikipedia.org/wiki/X32_ABI

UPDATE

On Ubuntu system I have to install two packages (with deps) to get x32 working:

 > sudo apt install gcc-multilib
 > sudo apt install libx32stdc++-5-dev 

Then compiling simlple C++ code with g++ -mx32 hellow.cpp works, making x32 executable

> file a.out
./a.out: ELF 32-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /libx32/ld-linux-x32.so.2, for GNU/Linux 3.4.0

Upvotes: 4

o11c
o11c

Reputation: 16046

There are 3 common ABIs usable on standard Intel-compatible machines (not Itanium).

  • The classic 32-bit architecture, often called "x86" for short, which has triples like i[3-6]86-linux-gnu. Registers and pointers are both 32 bits.
  • The 64-bit extension originally from AMD, often called "amd64" for short, which has GNU triple of x86_64-linux-gnu. Registers and pointers are both 64 bits.
  • The new "x32" ABI, with a triple of x86_64-linux-gnux32. Registers are 64 bits, but pointers are only 32 bits, saving a lot of memory in pointer-heavy workflows. It also ensures all the other 64-bit only processor features are available.

Each of the above has its on system call interface, own ld.so, own complete set of libraries, etc. But it is possible to run all 3 on the same kernel.

On Linux, their loaders are:

% objdump -f /lib/ld-linux.so.2 /lib64/ld-linux-x86-64.so.2 /libx32/ld-linux-x32.so.2

/lib/ld-linux.so.2:     file format elf32-i386
architecture: i386, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x00000a90


/lib64/ld-linux-x86-64.so.2:     file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x0000000000000c90


/libx32/ld-linux-x32.so.2:     file format elf32-x86-64
architecture: i386:x64-32, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x00000960

Now, if you're getting the message about "skipping incompatible library", that means something is messed up with your configuration. Make sure you don't have bad variables in the environment or passed on the command line, or files installed outside of your package manager's control.

Upvotes: 13

Related Questions