In Linux Determine If a .A Library/Archive 32-Bit or 64-Bit

How to test if a shared object is 32-bit or 64-bit?

.so files use the ELF format. The ELF header comes in two variants for 32bit and 64bit platforms. Which of the two the file contains is determined by byte 0x04 in the file. It is 1 for 32bit format and 2 for the 64bit format.

You can simply read and test this byte.

The actual instruction set that the machine code is compiled for can also be determined from bytes 0x12 and 0x13, e.g. 0x03 for x86 and 0x3E for x86_64. Note that the endianess for the two bytes is determined by byte 0x05, which is either 1 for little endian or 2 for big endian.

See also the wikipedia article on the ELF format.

Determining whether a library archive for AIX is 32-bit, 64-bit, or both, from Linux

I don't think there is an easy way. If you create two AIX archives, one 32-bit and one 64-bit, as follows:

$ cat a.c
int foo (void) { return 42; }
$ xlc -q32 a.c -c -o a32.o
$ xlc -q64 a.c -c -o a64.o
$ ar -X32 cr a32.a a32.o
$ ar -X64 cr a64.a a64.o

you end up with archives that are not in a readable format by the linux ar:

$ file a32.a a64.a 
a32.a: archive (big format)
a64.a: archive (big format)
$ ar t a32.a
ar: a32.a: File format not recognized
$ ar t a64.a
ar: a64.a: File format not recognized

I tried using strings to see if anything obvious was in the archives, but found nothing. Your ony remaining option is to build a binutils package targetting AIX (download binutils, configure with option --target=powerpc-ibm-aix5.3, run make and voilà: you've got a tool called powerpc-ibm-aix5.3-ar somewhere in that build tree).

Is there an command in linux to find out whether a library has been build in 32 or 64 bit mode

An .a archive is just a collection of objects, so why not:

ar x libnet.a
file someobj.o

That will give you an answer like:

someobj.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

Have a static lib, is there a simple way to know it is for 32 bit or 64 bit?

You can use dumpbin utility with /headers option

It returns whether the library was built for 32 or 64 bit architecture.

Check DUMPBIN Reference for details.

Example usage:

c:\>dumpbin libXYZ.lib /headers

On a unix/linux system how can I learn more about a mylib.a archive?

"nm" and "ar" will give you some information about the library archive.

On a unix/linux system how can I learn more about a mylib.a archive?

"nm" and "ar" will give you some information about the library archive.

How can I get the architecture of a '.a' file?

You can also skip the ar command and use readelf, via something like:

readelf -h <archive>.a | grep 'Class\|File\|Machine'

[00:32:15] /usr/lib $ readelf -h libxslt.a | grep 'Class\|File\|Machine'
File: libxslt.a(attrvt.o)
Class: ELF32
Machine: Intel 80386
File: libxslt.a(xslt.o)
Class: ELF32
Machine: Intel 80386
... #Trimmed this, it goes on a bit
File: libxslt.a(transform.o)
Class: ELF32
Machine: Intel 80386
File: libxslt.a(security.o)
Class: ELF32
Machine: Intel 80386
[00:32:24] /usr/lib $

In case it's relevant, here's the other information that you can get from readelf -h. I just trimmed the above with grep, obviously:

File: libxslt.a(security.o)
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 2548 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 16
Section header string table index: 13

That output is for one of the object files in libxslt.a, but it gives the same information for each file.



Related Topics



Leave a reply



Submit