TUCoPS :: General Information :: ubcode.txt

Removing Useless Code from Universal Binaries

Removing Useless Code from Universal Binaries
By Tek

> Disclaimer

Please make backups prior to doing anything found in this article.  I take no
responsibility for any problems that may occur.

> What are Universal Binaries?

The Universal Binary, as called by Apple, is an application bundle (.app)
designed to run on both Intel and PowerPC-based Apple computers running OS X.

The introduction of the UB in 2005 meant that software developers could
maintain a single binary capable of running on both platforms instead a
separate one for both Intel and PPC.

Another advantage is that one would not have to rely upon emulation via
Rosetta, which can often be sluggish.

> The problem

While the Universal Binary is useful to developers, it causes a couple of
issues for users.

The first issue being that quite often universal binaries are larger that one
for a single platform.

Another issue is that time can be wasted while your machine selects the correct
code to execute.

But fear not, I have a simple solution.

> The solution

A quick search of Google will reveal a number of solutions for removing foreign
code from a UB, however they are all merely wrappers for tools already at your
disposal, and in many cases are sketchy at best.

My solution is both free and relatively safe.

First step, open up a terminal emulator. 

Now, we are going to cd to '/Applications/0xED.app/Contents/MacOS/', which is
where the 0xED binary lays.

We don't want to waste our time stripping out the code if we don't need to, so
we will first check to see if this universal or not:

iMac:/Applications/0xED.app/Contents/MacOS jim$ lipo 0xED -info
Architectures in the fat file: 0xED are: ppc i386

Since it is, we will remove the PPC code, as it is unecessary on my Intel-based 

At this point we actually have a couple of options fore removing the code; the 
first is to remove a given architecture and the second is to remove all 
architectures except the one needed.

Method 1 (-remove):

lipo 0xED -remove ppc -output 0xED

lipo <input file> -remove <architecture to remove> -output <output file>

And with that, we have removed all PPC code, stripped down the bundle size from
1.1MB to 773KB, and have possibly sped up its execution somewhat.

Method 2 (-thin):

lipo 0xED -thin i386 -output 0xED

lipo <input file> -thin <architecture to remain> -output <output file>

And with our second method we have created a thinned binary, containing only the
specified architecture, removing all other types.  This method is only handy if
there are more than two platforms present. 

Keep on hacking.


TUCoPS is optimized to look best in Firefox® on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2024 AOH