Leopard : Four-Way Universal Binaries
Mac OS X — 30 Oct 2007 14:13 — 1002 days ago

A post in my user forum made me aware of the fact that in Leopard, some binaries are not just two-way (PPC/Intel) but four-way Universal Binaries. The four variants are Intel 32bit, Intel 64bit, PPC 32bit and PPC 64bit.

Examples are the Apache web server binary and all its modules:

$ file /usr/sbin/httpd /usr/sbin/httpd: Mach-O universal binary with 4 architectures /usr/sbin/httpd (for architecture ppc7400): Mach-O executable ppc /usr/sbin/httpd (for architecture ppc64): Mach-O 64-bit executable ppc64 /usr/sbin/httpd (for architecture i386): Mach-O executable i386 /usr/sbin/httpd (for architecture x86_64): Mach-O 64-bit executable x86_64 $ file /usr/libexec/apache2/mod_vhost_alias.so mod_vhost_alias.so: Mach-O universal binary with 4 architectures mod_vhost_alias.so (for architecture ppc7400): Mach-O bundle ppc mod_vhost_alias.so (for architecture ppc64): Mach-O 64-bit bundle ppc64 mod_vhost_alias.so (for architecture i386): Mach-O bundle i386 mod_vhost_alias.so (for architecture x86_64): Mach-O 64-bit bundle x86_64

I think it wasn’t that way in Tiger?

Only few of the command line binaries are four-way universal:
$ file /usr/bin/* /usr/sbin/* | grep '4 architectures' /usr/bin/auvaltool: Mach-O universal binary with 4 architectures /usr/bin/mpic++: Mach-O universal binary with 4 architectures /usr/bin/mpicc: Mach-O universal binary with 4 architectures /usr/bin/mpicxx: Mach-O universal binary with 4 architectures /usr/bin/mpiexec: Mach-O universal binary with 4 architectures /usr/bin/mpif77: Mach-O universal binary with 4 architectures /usr/bin/mpif90: Mach-O universal binary with 4 architectures /usr/bin/mpirun: Mach-O universal binary with 4 architectures /usr/bin/ompi_info: Mach-O universal binary with 4 architectures /usr/bin/opal_wrapper: Mach-O universal binary with 4 architectures /usr/bin/orted: Mach-O universal binary with 4 architectures /usr/bin/orterun: Mach-O universal binary with 4 architectures /usr/sbin/httpd: Mach-O universal binary with 4 architectures
Many more are two-way:
$ file /usr/bin/* /usr/sbin/* | grep '2 architectures' | wc -l 857

The graphical end-user apps seem to be two-way too:

$ file /Applications/GarageBand.app/Contents/MacOS/GarageBand /Applications/GarageBand.app/Contents/MacOS/GarageBand: Mach-O universal binary with 2 architectures

The interesting question for me is if I need to start building my PHP5 module as four-way universal binary. That could mean a lot of additional work because not all of the many open source libraries I have to include might even be 64bit-clean.

Update: Apparently I do...


Another observation: While working on a PHP5 module build I stumbled upon what seems to be an inconsistency between architectures in the Apple-suppplied libiconv library. The PHP build fails in the link stage. The linker cannot find the symbol _libiconv in two of the four architectures.

Sure enough, the two 64bit architectures in the fat library do not seem to define this symbol:

$ for arch in i386 ppc7400 x86_64 ppc64; do echo $arch; nm -arch $arch /usr/lib/libiconv.dylib | grep _libiconv$; done i386 0000bc8d T _libiconv ppc7400 0000de7c T _libiconv x86_64 ppc64

The build succeeds if I build my own universal libiconv from source. I wonder why Apple’s PHP5 works with the system-supplied libiconv.


Comments
Posted by Ralph Martin on 31 Oct 2007 22:10

Marc

I think there is a serious problem.

httpd is started as x86_64 in Leopard on Intel (64 bit)
Mysql is currently only available prebuilt as i386 on Intel (32 bit) .

As these have different architectures, I dont *think* you can make a PHP module which plays nice with both of these at the same time (even if you compile as a 4-way binary).

Correct me if I am wrong.

But I think this means we have to either wait until there's a 64 bit MYSQL, or build one ourselves,
OR
force httpd to run in 32 bit mode.

Comments?

Posted by Ralph Martin on 31 Oct 2007 22:34

I take it back!

PHP has to be LINKED against a 64 bit capable MYSQL library.

The running mysqld is a separate process which can be a 32 bit.

Marc, just delete this and the previous comment.

[Red face]

Posted by james on 6 Nov 2007 05:43

I was able to get PHP to compile for x86_64 by modifying the Makefile as follows:

CFLAGS_CLEAN = -g -O2 -I/usr/include -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk
EXTRA_LDFLAGS = -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk

However, I only got it working with --with-apxs2 --without-iconv. I couldn't get it working with --with-mysql since I don't have x86_64 client libraries. I downloaded the mysql source and tried to compile it as x86_64, but I don't know enough about what I'm doing to get that to work. I assume since the Apple supplied mysqld isn't x86_64, that it's not possible at this time to compile it as such? I would assume however, that compiling just the client would work... but I can't figure out how to do that.

One thing I noted was that PHP didn't have to be a 4-way binary to work with the 4-way apache. I only compiled it for the x86_64 arch. Not useful for distribution... But something people might be interested in if rolling your own becomes easier.

Powered By blojsom