Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!


Forgot your password?

How OS X Executes Applications 315

MacHore writes "0xFE has an excellent tutorial on Mach-O, which is the file format used by OS X executable files and libraries. It goes into great detail about how Mach-O works, and explains what OS X actually does when it loads and runs an application. Subtopics include Universal Binaries, The Dynamic Linker, Using otool, and other goodies."
This discussion has been archived. No new comments can be posted.

How OS X Executes Applications

Comments Filter:
  • by Anonymous Coward on Monday March 27, 2006 @01:07PM (#15003800)
    When FORCE QUIT doesn't work, 120V A/C to the processor does the trick every time.
    • "kill -KILL pid" should work.
  • by pryonic ( 938155 ) on Monday March 27, 2006 @01:07PM (#15003803)
    All I do is click on the icon and it launches the application! It obviously doesn't do any of that fancy stuff the article mentions or the pixies would tell me!

    Universal Binaries, The Dynamic Linker, Using otool? pah!

  • by Anonymous Coward on Monday March 27, 2006 @01:17PM (#15003871)
    Do you mean big "O" tool?
  • by Anonymous Coward on Monday March 27, 2006 @01:20PM (#15003899)
    With extreme prejudice?
  • by tygt ( 792974 )
    Am I the only one to notice that the supposed binary representation of 0xFE on the blogger's page is actually that of 0x7E (ie, it's missing a one)?
  • Decent article (Score:3, Interesting)

    by hackstraw ( 262471 ) * on Monday March 27, 2006 @01:59PM (#15004207)

    I'm fairly new to OS X, and don't know much of the internals and I have no clue on developing via Xcode or a lick about Objective-C.

    The otool command is new to me. Its handy because I too was getting "No such file or directory" with trying to use ldd. One thing this article does not mention is weather OS X calls mmap() on an executable and/or libraries? It probably does. I believe all modern OSes do this now, but I could be wrong.

  • there is a graphical version of otool that is perhaps a bit easier to use. It is called "TimmyOTool" and is located here [mac.com].
  • by davek ( 18465 ) on Monday March 27, 2006 @03:29PM (#15004926) Homepage Journal
    Does this executable format have anything to do with the binaries being able to execute on both ppc and intel machines?

    I have a friend who just got a new intel mac laptop. There are a lot of programs which won't run correctly because they don't fully support the intel architecture. However, I know from my linux experience that if I compile something for ppc, and then something for x86, neither executable will even LOAD on the other architecture, let alone execute with any functionality. When I download things for this new mac, I never select anything that is intel specific, and programs like oggdrop and vlc seem to work just fine.

    Is this some magic that the program is doing? Or is it on the system level? Or am I missing something obvious about macs?
    • As a previous poster mentioned, PPC executables run through an emulation layer called "Rosetta". However, Mac OS X binaries are stored in the Mach-O format. A Mach-O file can be divided into multiple segments, each of which can contain machine code for a different architecture. So, Universal applications really do include equivalent code for both PPC and x86. It's not really magic so much as it is that the loader knows to look for non-native code in a binary and run it through Rosetta if no x86 code exi

    • by geoffspear ( 692508 ) on Monday March 27, 2006 @03:51PM (#15005118) Homepage
      The answer is "sort of".

      The architecture does support Universal Binaries, which have code for both PPC and intel processors. This isn't really anything new or magical, the OS is just smart enough to know which code to execute. The same thing existed in the classic MacOS to support both PPC and 680x0 systems with FAT binaries.

      As with the classic MacOS, there's also an emulator involved, so the newer architecture can run (most) binaries compiled on the older architecture.

      However, compile something just for the Intel processors, and it won't run on your PPC hardware. If I understand your question correctly, if things worked the way you were assuming, Mach-O itself would guarantee any Mach-O binary would run on either system.

Houston, Tranquillity Base here. The Eagle has landed. -- Neil Armstrong