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

aix
13,395

Solution 1

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).

Solution 2

I'd suggest extract one of the .o files from the .a archive, and then running the file command on it. Example:

$ file fortune/fortune.o
fortune/fortune.o: ELF 32-bit MSB relocatable, SPARC, version 1 (SYSV), not stripped

file isn't standard on every system, but can easily be compiled. Alternatively, there are a couple of perl modules which do the same thing as file.

ar offers the p command which prints the file in question. For example:

$ ar p libcurl.a base64.o > /tmp/base64.o
$ file /tmp/base64.o  
base64.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
Share:
13,395
Tanktalus
Author by

Tanktalus

Quiet

Updated on June 27, 2022

Comments

  • Tanktalus
    Tanktalus about 2 years

    On AIX, I would run:

    ar -X32 -t libdb2.a
    

    and check for output to determine if there is a 32-bit object in the archive. Similarly with -X64 for checking for a 64-bit object. However, what about if I'm on another platform, and need to check the archive to see what it has? Usually I'm on Linux when I need to check, but I could just as easily be on Solaris or HP-UX.

    I used to check for shr.o and shr_64.o, since that's what's being compiled, but those are starting to show up in actual messages that are in the archives, and thus the reliability of these have dropped to the point where I'm getting false positives.

    If anyone has a pointer, preferably something I can do in perl, that'd be great.