Differences in function name decoration for the Leopard and pre-Leopard

From the Mac OS X 10.5, or the Leopard, the function name decoration for standard C functions were changed. It is not only for the Mac, but also for other Unices also.
When I took over other’s project, he set the SDK to use to MAC OS X 10.5 on the Xcode project setting, while he set the Deployment target to Mac OS X 10.4.
The reason was that there was an external library built from a console, and with the 10.4 SDK it threw linking errors like :

_fnctl$UNIX2003 can’t be found

Why? Because it uses the external library was built without the -mmacosx-version-min=10.4, it is linked to standar library with the new convention for which $UNIX2003 postfix is appended.
( Please cf. my previous post on building universal binary for configure based Unix project for this. Apple didn’t update their tech note page for the Leopard.)

So, if you want to build external libraries from the console, try this instead :

export CFLAGS=”-O -g -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -mmacosx-version-min=10.4
export LDFLAGS=”-arch i386″
sudo ./configure –prefix=/opt/local –disable-dependency-tracking

I should mention two important things here.

1. If you build it on a Tiger machine, you don’t need to use the -mmacosx-version-min=10.4. It will use the latest version as its base target.
So, it is linked for the Tiger. However, if you build the source code on a Leopard machine, you should use the option. You may shout, “Of course”, here.

2. Please take a look at the first two lines where the CFLAGS and LDFLAGS are set. I used only -arch i386. They were set on a Leopard machine. There was something odd on a Tiger machine to build a Universal Binary version of the external library.
I expected that it is OK and enough to use “-arch i386 -arch ppc” to build a Universal Binary version of the library.

However, I found out that the generated Intel binary code on a PPC Tiger was different from that built on a Intel Leopard machine. They stripped codes differently. So, on the Tiger machine, the compiler stripped its static functions more aggressively for the Intel architecture.

So, I had to build a PPC version on a PPC Tiger machine and an Intel version on a Intel Leopard machine separately and combined them using the lipo.
(Is there any switch which controls how much it strips codes? Why the default behaviour is so different? I tried fidning those at the GCC web site, but I couldn’t find one unfortunately.)

Also, the PowerPC binary generated on a Intel Leopard looked different from that on a PPC Tiger machine. That is why I asked question, “[Q] Is the 10.4u SDK distributed for the Intel Mac and the PPC Mac different?”, to the cocoa mailing list around July, 27, 2008.

So, let’s go back to the topic where we started.
So, by compiling the external library correctly, you can change the SDK setting on the Project setting to Mac OS X 10.4, and it compiles successfully.
I would like to mention, especially to Xcode beginners, that the Deployment Target setting should be used carefully and it is not for targeting some specific version of Mac OS X when a highest version of the Mac OS X SDK is used.
I don’t like the name, “Deployment Target”. It misleads people very easily. It is sort of “Deployment Target”, but it is different from what people can easily imagine what it is for.

Almost all people upgraded from 10.0 through 10.3 Panther to 10.4 Tiger.
Because the 10.4 Tiger is quite complete version compared to its predecessors and quite reliable, I think there are still many companies which make their product for the Tiger.
Indeed, it is better to write programs which can run on the Tiger and the Leopard at the same time without changing the source codes.
(It is one of the reason I don’t use Objective-C 2.0 addition.) The Panther is also a stable version. I don’t know how many people still use the 10.3 Panther.
Apple still provides 10.3 SDK for the latest XCode 3.1. So, I guess there are still many.
But in my case I’m OK to consider only the 10.4. Anyway, point is that it is better to keep old machines for development and test purpose.
My 1Ghz iMac 17″ machine is still my main machine and it handles playing movies while it is downloading Korean soap operas and “History Special” program using P2P.
At the same time, I write codes on it and check email. The PowerPC tends to have better throughput, so it handles all of those very nicely and smoothly.
The only exception is to play HD clips with huge dimension and VC-1 clips. (Probably it is because the VC-1 decoder from the ffmpeg is not optimized enought yet.)
So, there are many good reason to keep the old machine!

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: