English 中文(简体)
Determining whether a library archive for AIX is 32-bit, 64-bit, or both, from Linux
原标题:
  • 时间:2009-11-10 03:12:09
  •  标签:
  • aix

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.

最佳回答

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

问题回答

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

So... I m one year late, but I just had the exact same problem. Here is how I solved it, I hope it 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 of ar you list the contents of the archive and when you use the "x" argument of ar you extract them. Type man ar for further instructions.





相关问题
strndup call is currupting stack frames

I have seen a strange behavior with "strndup" call on AIX 5.3 and 6.1. If I call strndup with size more than the size of actual source string length, then there is a stack corruption after that call. ...

How can I get the uptime of a IBM AIX box in seconds?

I m writting a Perl script for which I need the uptime in seconds to do some calculation, in all the machine in the shop (i.e. linux, SunOS, and AIX). I have a way to get the uptime for linux (/proc/...

How to find dll loaded by a process in AIX?

How to find which dynamic libs .so are loaded currently by a process, also those dll are dynamically loaded with dllopen. I want to debug a process to find out which libs its using currently.

SNMP on AIX 5.3

I need to monitor a system with AIX 5.3, but can t find a good source for the OIDs. Does anybody know the OIDs for CPU, Memory and Harddisk values?

Unix: fast remove directory for cleaning up daily builds

Is there a faster way to remove a directory then simply submitting rm -r -f *directory* ? I am asking this because our daily cross-platform builds are really huge (e.g. 4GB per build). So the ...

热门标签