Thursday, December 6, 2007

32bit or 64bit binaries on MacOS

I have just built a version of Firebird 2.03 Classic for MacOS using a new MacOS 10.5 (Leopard) system I got recently. My basic tests show everything working OK. So a copy of the build was sent to Philippe Makowski for QA. However after install he gets a bus error trying to run isql. He is running MacOS 10.4 (Tiger).

First thought as to what the problem might be was that Leopard is a 64bit OS whilst Tiger is 32bit and that gcc/ld might have built incompatible binaries for the two platforms by default.

Well - Hmm - heres the problem, how do you find out whether a binary is 64bit or not?
MacOS has no ldd. But it does have something called otool
file ./isql gives the following answer: ./isql: Mach-O executable i386
Without going into the ins and outs of how MacOS loads binaries etc there is no simple and easy way to find out for sure - even using otool...

The solution:
otool -h ./isql
./isql
mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
0xfeedface 7 3 0x00 2 16 1868 0x00000085

The key is the magic number, looking at /usr/include/mach-o/loader.h will give you the magic number for 32bit and 64bit binaries...
0xfeedface = 32bit
0xfeedfacf = 64bit

So we can see from the information above that we do have a 32 bit build. So thats not the problem.

No comments: