Thursday, December 11, 2008

How to determine if a file is 32 or 64 bit on AIX

I was working on an AIX box recently and had to figure out if a binary was 32 or 64 bit. Took me a bit since I am not that familiar with AIX but I eventually figured out two methods:

The first is using the 'file' command. For a 32-bit binary this command produced the following output:

# file libmod_sm20.so
libmod_sm20.so: executable (RISC System/6000) or object module

However on a 64-bit binary it actually stated 64 bits:

# file libmod_sm20.so
libmod_sm20.so: 64-bit XCOFF executable or object module not stripped

The other way was to use the 'nm' command. Not entirely sure what nm stands for. Perhaps name mangling or just 'name'.

In any case this command has the '-X' switch which allows you to specify the type of file. So if you wanted to examine only 32 bit object files you would use '-X 32'. For 64-bit you would use '-X 64'. And for both you would use '-X32-64'.

Running nm with the 32-bit flag:

# nm -X32 libmod_sm20.so
0654-210 libmod_sm20.so is not valid in the current object file mode.
Use the -X option to specify the desired object mode.

Basically gives me an error. However

# nm -X64 libmod_sm20.so

will produce copious amounts of output. This means that libmod_sm20.so is a 64-bit file because the libraries it is linking to are 64-bit.

No comments: