Determining if the library archive for AIX is 32-bit, 64-bit, or both, from Linux

On AIX, I would run:

ar -X32 -t libdb2.a

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

I used shr.o and shr_64.o for verification, since this is what compiles, but they begin to appear in the actual messages in the archives, and therefore the reliability of this data has fallen to such an extent, I get false positives.

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

+3
source share
3 answers

I do not think there is an easy way. If you create two AIX archives, one 32-bit and one 64-bit, follow these steps:

$ 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 get archives that are not in a readable format using 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 to use stringsto see that there was something obvious in the archives, but nothing was found. Your remaining option is to create a binutils package designed for AIX (load binutils, configure with the option --target=powerpc-ibm-aix5.3, run, makeand voilà: you have a tool called powerpc-ibm-aix5.3-arsomewhere in this build tree).

+1
source

I would suggest extracting 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 , . perl, , file.

ar p, . :

$ 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
+1

So ... I was one year late, but I had exactly the same problem. Here is how I solved it, I hope this helps someone:

$ ar t mylib.a
myobj1.o
myobj2.o
myobj3.o

$ mkdir /tmp/mylib
$ cp mylib.a /tmp/mylib
$ cd /tmp/mylib
$ ls
mylib.a

$ ar x mylib.a
$ ls
mylib.a
myobj1.o
myobj2.o
myobj3.o

$ file *

Possible outcomes:

mylib.a: current ar archive
myobj1.o: ELF 64-bit (...)
myobj2.o: ELF 64-bit (...)
myobj3.o: ELF 64-bit (...)

OR

mylib.a: current ar archive
myobj1.o: ELF 32-bit (...)
myobj2.o: ELF 32-bit (...)
myobj3.o: ELF 32-bit (...)

Explanation: An archive library file is just a collection of .o files, when you use the t argument, you specify the contents of the archive, and when you use the x argument, you extract them. Type man ar for more instructions.

0
source

Source: https://habr.com/ru/post/1722396/


All Articles