Fun with universal binaries

Yesterday I had to debug a Mac OSX program and therefore I had to learn about how Mac Universal Binaries work.

Universal Binaries contain (most of the time) PowerPC code and Intel x86 code as well. While they could easily also feature code for other architectures, like your toaster or microwave, it usually looks somewhat like this: [Header|PowerPC|Intel]. The operating system decides which code it needs and executes the part of the file suitable for its architecture.

Now in order to see what kind of binary information is “sandwiched” in the file, there is a header, very nicely described in the Mac OS X ABI Mach-O File Format Reference.

It starts off with a “magical number”, that funnily reads 0xCAFEBABE in hexadecimal. — Cafe babe? Yup.

Cafebabe

Looks like the programmers had some fun coming up with a readable magic number. :)

For a more in-depth explanation of how universal binaries look like, I recommend this blog post.

(thanks to the t-shirt model ;) )



12 Responses to “Fun with universal binaries”

  1. 1
    John Levon Says:

    Talking of universal binaries, 0xcafebabe is also used by Java (see http://www.artima.com/insidejvm/whyCAFEBABE.html
    for some interesting history).

  2. 2
    Fred Says:

    Thanks, John. I didn’t know that. Very interesting.

  3. 3
    Laurens Holst Says:

    Kinda lame that they copied Java’s magic number. If they wanted to pull the same joke, they could have taken another of the many ‘funny’ hexadecimal numbers.

    I think the worst part is that now universal binaries can not be distinguished from java class files anymore. Why the hell is there a magic number at all, then.

    ~Grauw

  4. 4
    Fred Says:

    Well, as it turns out, it was the other way around: 0xCAFEBABE was apparently first used by NeXTSTEP (you find this information on the page John (comment 1) linked to) to implement exactly the same what “Universal Binaries” are today.

    The interesting bottom line is: a) It was Sun who “stole” the magic number and b) Universal Binaries are far away from being a “new” concept.

  5. 5
    Greg Says:

    Hey Fred!

    Nice t-shirt. But when did you get the tattoos? ;-)

  6. 6
    Fred Says:

    Thanks, Greg! Do you dig my new looks? :)

  7. 7
    Laurens Holst Says:

    Fred, aha, interesting :).

  8. 8
    Pookzilla Says:

    How did I know that picture would come back to bite me in the ass…

  9. 9
    Fred Says:

    Hey there. You have to admit, this is probably the most charming way to illustrate a hex number :)

    But, do you want me to remove it? If so, just let me know and I’ll take it down ASAP.

    Yet of course, I’d be sad ;)

  10. 10
    Pookzilla Says:

    I’d be happy with removing the credit and link to the original. :)

  11. 11
    Fred Says:

    Hehe, so be it — whatever you like :) Thanks!

  12. 12
    brosowski.info » Blog Archive » Java 6 für MacOS X Leopard Says:

    […] ist übrigens die dezimale Schreibweise für 0xCAFEBABE405 , einem Beweis, dass auch Programmierer Humor […]

Leave a Reply