difference between i386:x64-32 vs i386 vs i386:x86_64
Asked Answered
J

2

8

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?

Joggle answered 1/4, 2016 at 2:34 Comment(2)
Note that static libraries are generally far more trouble than they are worth. Use dynamic libraries, with an ${ORIGIN}-relative -rpath if you really need to and don't need setuid or any other capabilities.Cordeiro
Does this answer your question? Difference between x86, x32, and x64 architectures?Fleming
C
13

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.

Cordeiro answered 1/4, 2016 at 2:54 Comment(7)
Thanks for the info.. in my Linux PC, i couldn't find /lib/libx32 at all.. is it can be the cause for this?Joggle
That's not surprising, if you don't have a multilib-enabled gcc base package installed, you probably won't have pulled in the glibc bits. Of course in that case, I'm not sure how you got the library at all ...Cordeiro
@SanthoshKumar likely you don't have x32 devenv installed (no libgcc, no glibc, ...). Try to install x32 and compile something simple gcc -mx32 helloworld.cSquilgee
actually it is a library provided by somebody else. to build my application, i need to link with the library. in my PC i could see /lib & /lib64 but not /libx32.Joggle
@SanthoshKumar what linux system do you have?Squilgee
@Severin : i am using OpenSuSe 13.1Joggle
@SanthoshKumar bummer, I'm ubunter. Please, check updateSquilgee
S
4

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
Squilgee answered 1/4, 2016 at 2:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.