tags:

views:

731

answers:

2

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.

+1  A: 

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
brianegge
Ok, how do I extract a .o file from the archive on Linux? ar isn't seeming to be willing to do so.
Tanktalus
+5  A: 

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

FX
I didn't get that name, but that's irrelevant. The newly-built ar didn't like -X32, -X64, or -X32_64, pretty much ignoring them. But, I might be able to just look at the filenames coming out and assume they follow our standards, so, unless someone else has a better idea, this is probably going to be the long-term solution we go with, if we can get "recompile binutils and put it somewhere public" past our lawyers.
Tanktalus