Slashdot Mirror


How OS X Executes Applications

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."

43 of 315 comments (clear)

  1. How I execute applications :) by Anonymous Coward · · Score: 5, Funny

    When FORCE QUIT doesn't work, 120V A/C to the processor does the trick every time.

    1. Re:How I execute applications :) by voidware · · Score: 2, Funny

      A/C is amps per coulomb. Since an amp is a coulomb per second, the parent is clearly refering to the frequency.

    2. Re:How I execute applications :) by squiggleslash · · Score: 2, Insightful
      No, he's refering to the operating system "A" combined with the "C" kernel. It's pretty logical to be honest, and it avoids insult to the thousands of developers of A whose work would be forgotten if it was all named after some crappy programming language that happened to write a kernel of its own.

      Confused? Not as much as me.

      --
      You are not alone. This is not normal. None of this is normal.
  2. How it launches? by pryonic · · Score: 3, Funny
    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!

    --
    Never underestimate the power of stupid people in large groups.
    1. Re:How it launches? by eonlabs · · Score: 2, Insightful

      "I forgive you stupid people" -Neurotically Yours

      --
      I wouldn't consider the mad hatter mad. Just reality impaired. He sure can make a mean cup of tea.
  3. "Using otool" by Anonymous Coward · · Score: 5, Funny

    Do you mean big "O" tool?

    1. Re:"Using otool" by mederjo · · Score: 2, Funny

      The other day I was buying a bunch of computer science/programming type books from Amazon. One thing I'm really interested in is something with a good description of Big-O ( Oh ) notation and how to assign it to an algorithm. I searched for "Big O" and of course I ended with a whole lot of results about having/giving orgasms, fellatio, cunnilingus etc. Not *quite* what I was looking for...

      Please include all jokes relating to reading /. and sexual activity, or lack thereof for someone posting to /., in the box below.

      BTW, does anyone know of a book with a really good treatment of Big-Oh, hopefully including good worked examples ?

      Regards,

      Jo Meder

  4. Ooh, I know this one! by Anonymous Coward · · Score: 5, Funny

    With extreme prejudice?

  5. Re:Obligitory... by MBCook · · Score: 2, Informative
    I have a 1.67 GHz G4 with a gig of ram and I almost never have speed problems, everything is quite snappy enough (although I hear the new MacBook Pros would put my Mac to shame). More memory may help you if that is an option (I didn't follow Macs well enough back then to know what your max is).

    That said, I seem to remember (and personal experience seems to bear this out) that OS X is really slow executing a fork() system call relative to Linux. I'm not sure if this is has to do with using a microkernel, or is because of specific decisions they made, but anything that fork()s a lot will run slower than on the same computer running Linux.

    My only suggestion to you would be... are you running the Dashboard? As interesting as it is, I avoid it because it is a resource HOG like nothing else on the system. If you google around you can even find a way to completely disable it.

    In general it is a very responsive system. The only time I can consistently cause a beachball is copying files (digital pictures) off of a CF card. This uses enough kernel time that the computer does seem to stop responding for tiny fractions of a second (and my CPU usage goes WAY up). I don't know what the computer is doing, but it has got to be able to do it faster. My theory? Hard coded uninterruptible sleep statements for timing purposes. Just a random guess though.

    All that said, I regularly use a 2.3 GHz Windows laptop and I am constantly amazed at how long it seems to take some applications to launch, and how different it is. IE will come up almost instantly most times. But sometimes it takes 30 seconds to launch and show the page (then feels slow after that). Other apps can do the same thing sometimes. But most applications (IE is preloaded by the OS) take just as long as on my Mac, if not longer.

    --
    Comment forecast: Bits of genius surrounded by a sea of mediocrity.
  6. "0xFE - 1111110b - 0376" by tygt · · Score: 2, Insightful

    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)?

  7. Re:0xFE by generic-man · · Score: 3, Insightful

    Same reason 3com.com, 37signals.com, and 23.com exist: the RFC was a Request For Comments, and some people commented "no."

    --
    For more information, click here.
  8. Re:I don't have a Mac by Haeleth · · Score: 4, Funny

    Oh dear, does Linux practice this awful act as well? I'm an opponent of capital punishment, so it's now clear to me that I can't, in all conscience, use a Mac or Linux. No application, however detestable a crime it may be accused of, should ever face what is no more than state-sanctioned murder!

    My question to Slashdot, therefore, is what operating system should I choose?

    I've heard good things about FreeBSD's jails, which are apparently very secure without being inhumane. But on the other hand, Windows also has some advantages - I understand it opposes the death penalty so strongly that that it's been known to commit suicide in protest when a user attempts to execute too many applications?

  9. Re:Kinda OT.. yet relevant to this thread by Anonymous Coward · · Score: 2, Informative

    Close, but not quite the same thing. GoboLinux apps are not relocatable, for isntance. The great thing about OSX apps (and other real appdir implimentations) is that they can be installed in the users home directory, on their desktop, on a network folder, on a disc, or in any system shared folder just as easily as it can be installed in the official "Applications" folder.

  10. Re:0xFE by MagicM · · Score: 4, Funny

    Bastards.

  11. Re:What this means by Zwets · · Score: 5, Funny
    Expect an increase of the number of Mac virii

    And wormii! Don't forget wormii.

    --
    One of the lessons of history is that nothing is often a good thing to do and always a clever thing to say. - Will Duran
  12. Re:What this means by andreMA · · Score: 5, Insightful
    Expect an increase of the number of Mac virii out there in a now to 3 month timeframe.
    Yes, because this information was a closely held secret before this meddlesome blogger came along. I bet Steve Jobs is really pissed and is taking out a contract on his life.
  13. Re:Obligitory... by ElephanTS · · Score: 2, Insightful

    I have an old 600MHz iBook with 640MB and it is slow to launch stuff. A 600MHz iMac is a much faster machine with the same amount of RAM but those are the compromises of a cheap portable machine. The 2.5" drive is slow too - it's not necessarily Mach's fault. You should have seen OSX 10.0 - launching without all the fancy prebinding that came later was really really slow even on 'fast' machines. I still hope for further optimisations on Mach but it's all about design compromises so I don't hold my breath.

    Got a client's 2.1GHz Macbook Pro here and it's really quick to launch everything - Aperture just opens in one bounce and Safari is close to instant. The relative 'slowness' of mach will become irrelevant in the future for sure.

    --
    spoonerize "magic trackpad"
  14. Re:0xFE by boneshintai · · Score: 2, Informative

    Actually, the full grammar in the RFC is

    <domain> ::= <subdomain> | " "

    <subdomain> ::= <label> | <subdomain> "." <label>

    <label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]

    <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp>

    <ldh-str>

    <let-dig-hyp> ::= <let-dig> | "-"

    <let-dig> ::= <letter> | <digit>

    <letter> ::= any one of the 52 alphabetic characters A through Z in upper case and a through z in lower case

    <digit> ::= any one of the ten digits 0 through 9

    So a hostname beginning with a digit is actually invalid by the RFC. Nobody actually uses that definition; it turns out it's fairly easy to distinguish a DNS name 127.0.0.com from an IP string 127.0.0.1 in other ways.

  15. Decent article by hackstraw · · Score: 2, Interesting


    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.

  16. Re:Kinda OT.. yet relevant to this thread by Raffaello · · Score: 4, Insightful

    When I try and install something on OS X that doesn't have the required dependencies, it simply fails to work and gives no user-friendly clues why.

    We're talking about applications here. On Mac OS X, a properly packaged application lives in a .app directory which contains all dependencies with the sole exception of frameworks that are present on any version of Mac OS X that the app is capable of running on. In other words, a properly packaged Mac OS X app has no external dependencies - everything it needs to run is either in the .app directory, or comes standard with Mac OS X.

    Any application packaging that assumes that users will not relocate an application is broken on Mac OS X. This means that any having dependencies not contained inside the .app directory (aka the app bundle) is broken, since users can and will relocate apps to removable media for use on other machines.

    Now, some misguided *nix hackers will cobble together an application to run on Mac OS X that scatters little *nix file turds all over various directories, or will hard code installation directories so the application is not relocatable. These are both wrong on Mac OS X (though common practice on *nix) because Mac users have been relocating applications since the mid 1980s, and will continue to do so.

  17. Re:What this means by minus_273 · · Score: 2, Funny

    Actually, I am a mac user/developer and I expect the number of Mac worms to increase by 5-10 times the current amount. I dont want to agree with windows fanboys, but have to admit this. This really a cuse for alarm. The number of worms will increase by at least 5x and millions of mac users are not protected.

    --
    The war with islam is a war on the beast
    The war on terror is a war for peace
  18. Re:Kinda OT.. yet relevant to this thread by Raffaello · · Score: 2, Insightful

    Just as importantly, even if you can install it to any user specified directory, can you move it elsewhere after installation and still have it work? Can you move it to a CD, pop that CD in any other Linux user's machine and have the app run off the CD? Properly packaged Mac OS X apps do all these things.

  19. Re:Obligitory... by moosesocks · · Score: 4, Interesting

    A lot of that has to do not only with Mach, but simply with the fact that up until recently, a lot of OSX applications (specifically, those built on Carbon) were not multithreaded. In other words, if one bit of the application hangs or times out, the application and everything that depends on it goes to hell.

    This is why BeOS appeared to be lightning fast on even slow machines. Even the smallest tasks were executed independently, and bottlenecks were hardly noticiable.

    Apple's doing a good job making everything work, and Cocoa is definitely a step in the right direction, but apple really needs to kill all of the single-threaded applications they've got now. The Finder is the most prolific and outrageous example of this, and anybody who's ever lost a network connection while a network share was mounted knows what I'm talking about (the system virtually hangs for 45 seconds until the connection times out. awful. simply awful)

    Otherwise, I love OSX.

    --
    -- If you try to fail and succeed, which have you done? - Uli's moose
  20. Re:Kinda OT.. yet relevant to this thread by tpgp · · Score: 2, Informative

    We're talking about applications here. On Mac OS X, a properly packaged application lives in a .app directory which contains all dependencies with the sole exception of frameworks that are present on any version of Mac OS X that the app is capable of running on. In other words, a properly packaged Mac OS X app has no external dependencies

    So - you install a version of the gimp - you get a copy of gtk, install eog - you get a copy of gtk, install.... well I think you get my point.

    While the Apple way of handling applications is nice and all, it's really more suited to a closed, vertically integrated framework, whilst linux's method is more suited to an open, looser framework. (where all apps can share libraries, rather then each having their own copy of a library)

    Additionally - linux apps are not harder to install. Imagine you're working in a small business, you need an application to print barcodes.

    On the Mac you have scour the web deciding Free or Paid, can I trust this site? Am I downloading a trojan. Oh, this is windows only, but says I can run it using VPC. Will it work on my new macbook under rosetta? Once you've downloaded it, things are pretty sweet, but finding the download can be a PITA.

    On the linux box (I am going to choose Debian as I'm familiar with it). Fire up synaptic from the gnome menu. Search for barcode. Two results returned. Both of these programs I know to be free of trojans, compatable with my system & configured for it. To install, I double click.

    Now - its easier for a binary-only software maker to distribute to Macs, but thats a different discussion.

    --
    My pics.
  21. Re:Kinda OT.. yet relevant to this thread by Goaway · · Score: 3, Insightful

    My god! That will use up megabytes of disk space!

    I also find it totally hilarious how Linux users are now advocating a completely centralized model of software distribution. Freedom of choice! As long as you only ever choose things approved by your distro maker!

  22. Re:Interesting, but why? by Fahrvergnuugen · · Score: 4, Informative
    --
    Kiteboarding Gear Mention slashdot and get 10% off!
  23. Re:Kinda OT.. yet relevant to this thread by GlassHeart · · Score: 4, Informative
    So - you install a version of the gimp - you get a copy of gtk, install eog - you get a copy of gtk, install.... well I think you get my point.

    No, the post you were responding to phrased it poorly.

    What is inherent in a MacOS X version (say, 10.4.5) already covers most of what an application might need, including Apple's "equivalent" of gtk. Go browse the Apple Developer docs sometime, and you'll see a much richer set of libraries that come with the OS by default. Thus, if an application wants an "obscure" library and decides to bundle it, the cost to the system is minimal even if another app has the same one. The MacOS bundle is not at all the equivalent of statically linking against gtk and other "fundamental" libraries in Linux.

    On the Mac you have scour the web deciding Free or Paid, [...] Once you've downloaded it, things are pretty sweet, but finding the download can be a PITA.

    Have you ever heard of versiontracker?

    On the linux box (I am going to choose Debian as I'm familiar with it). Fire up synaptic from the gnome menu. Search for barcode. Two results returned. Both of these programs I know to be free of trojans, compatable with my system & configured for it. To install, I double click.

    Which can bring in new versions of a library, which in turn brings in new versions of another application, which may be broken in some way (like any app can be). In other words, installing one app in Linux can effectively break another one. You pay for the isolation available to MacOS X apps in the form of disk space and RAM, both of which can be relatively cheap depending on what you're doing with your computer.

  24. Re:0xFE by fishbowl · · Score: 2, Interesting

    >3com.com and 3m.com are technically invalid...

    In old-school records management, 3Com is filed under "T", and 3M is filed under "M" (The name of the company is "Minnesota Mining and Minerals".

    --
    -fb Everything not expressly forbidden is now mandatory.
  25. Re:Kinda OT.. yet relevant to this thread by tpgp · · Score: 2, Insightful

    My god! That will use up megabytes of disk space!

    *sighs* - OS X provides a core set of libraries, linux provides a choice of which core set you want to use.

    Both operating systems (unlike you) understand the importance of using dynamic libraries to save disk space.

    If every file on your mac was statically compiled, we would be talking gigabytes, not megabytes.

    I also find it totally hilarious how Linux users are now advocating a completely centralized model of software distribution. Freedom of choice! As long as you only ever choose things approved by your distro maker!

    You only find it totally hilarious because you fail to understand the difference between making it convenient for users to use software from a central source and forcing users to use software from a central source.

    --
    My pics.
  26. are osx binaries cross-architecture? by davek · · Score: 2, Interesting

    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?

    --
    6th Street Radio @ddombrowsky
    1. Re:are osx binaries cross-architecture? by geoffspear · · Score: 4, Informative
      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.

      --
      Don't blame me; I'm never given mod points.
    2. Re:are osx binaries cross-architecture? by gandreas · · Score: 2, Interesting

      Rosetta supports Altivec, and surprisingly well in fact (I tested a fractal rendering application I've written and the Rosetta Altivec version ran a surprising 6.3x faster than the Rosetta non-Altivec version, as opposed to the much more expected 3.2x faster that it did on a G5).

    3. Re:are osx binaries cross-architecture? by aduzik · · Score: 2, Informative

      Yeah, I realized that after I posted. What Rosetta doesn't support, and what I meant to say, was that Rosetta doesn't support certain G5-specific features. My bad.

      --
      If it's not one thing it's your mother.
  27. Re:Kinda OT.. yet relevant to this thread by PitaBred · · Score: 2, Insightful

    Screw the disk space. It uses up much more RAM than a shared-library solution.

  28. Re:Kinda OT.. yet relevant to this thread by handslikesnakes · · Score: 2, Insightful

    And lets not forget having to upgrade every application when there's a bug or vulnerability in the library they all duplicate.

  29. Re:Obligitory... by Kadin2048 · · Score: 2, Interesting

    Up until about 4 weeks ago I was using a 400MHz "Sawtooth" G4 with 768MB RAM and the stock 32MB video card as my main machine, running 10.4 with all the latest updates, new version of iLife, etc. I really didn't think it was that bad, and in fact when I upgraded to my new machine (a dual 2GHz G5), I was actually surprised that the UI "speed feel" didn't change all that much. Opening applications and windows are noticeably faster, but the difference wasn't as dramatically night and day as some previous upgrades I've made. This is not a criticism of the new machine as much as I think it's a credit to how well OS X performs on older hardware, at undemanding tasks. Sure, that machine was an absolute horror if you wanted to transcode a few hours of MPEG-2 video (might as well just let it run overnight), but for day-to-day stuff it really wasn't bad. I think in some ways, OS X gets a bad rap for being a resource hog. There are definitely parts of it that are (Dashboard, etc.) but in general I don't think it is.

    I have a Kubuntu system running on an HP workstation (Pentium 4 Prescott, 512MB RAM, NVidia NVS 200 Quadro), which if K/Ubunutu's reputation for running on older hardware was as good as people say it is, ought to fly. (In fact this was why I bought this machine in the first place -- I thought it ought to be smoking, for the very basic level of stuff I wanted to do with it.) However, I can bog the system down by dragging a large selection rectangle on the KDE desktop: it takes probably 3 or more seconds for the selection box to catch up with the cursor going from one corner of the screen to the other, and XOrg's processor utilization goes up into the 95-98% range. I was shocked the first time I did this. Is this a big deal? No, not really -- but it sure makes the machine feel slow. I accept that the Mac/PC thing isn't a scientific comparison because the hardware is different, but really I think the advantage ought to go to the PC here (3.2GHz P4 with a 64MB display card, versus a 400MHz Mac with an ancient 32MB one?), and it comes out feeling worse.

    Anyway, I just wanted to agree with you; the seemingly accepted wisdom that Mac OS X is inferior to a Linux desktop on older hardware is something I have yet to see a whole lot of evidence for. One of these days maybe I'll load Kubuntu-PPC (or Ubuntu -- perhaps KDE is the problem) onto my iBook and see how it fares, but as of right now I'd say there are a lot of valid reasons to use a Linux desktop, but UI responsiveness isn't one of them.

    --
    "Ladies and gentlemen, my killbot features Lotus Notes and a machine gun. It is the finest available."
  30. Re:Kinda OT.. yet relevant to this thread by Arandir · · Score: 2, Informative

    Sorry, that's not the equivalent. Not even close.

    --
    A Government Is a Body of People, Usually Notably Ungoverned
  31. Yeah, let's talk about bloat... by Senjutsu · · Score: 3, Insightful

    How bloated must that be?

    Seriously, how many copies of a library does that leave you having installed?


    Generally? One.

    Remember, this isn't a Linux distro, where the user has all the choices in the world except the one that matters most: the choice to have all of their apps look and behave in a consistent manner. 99.99999% of all apps targeting OS X link against the standard system Carbon or Cocoa frameworks. The odd app might have a really large third party library linked in and included in the app bundle, but that tends to be the exception rather than the rule, as the bundled libraries tend to be of the small, utility type that only run a few K. How bloated is it? Not very at all.

    Now compare that with the situation on your average Linux distro: Instead of one version of one or two frameworks, every third app is written against a different toolkit. Want GIMP? Install GTK. KDevelop? Need QT too. Your text editor links against the athena toolkit, your system management utilities against Tk, your games against SDL, your audio editor against WxWidgets, your file manager against GNOME, something else against FLTK, FOX, Lesstif, Xaw...your shared libraries folder reads like an explosion at the acronym factory. Repeat ad naseum for your XML parsing libraries, your regex libraries, your sound libraries, etc, etc.

    And it doesn't end there. Binary compatibility between library releases is the exception rather than the rule. Every third GTK app requires that a different point revision of the GTK libraries be installed. XMMS requires that you install libraries that are several major revisions out of date. You've got 6 different versions of three different XML parsing libraries installed, 2 regex engines, 3 copies of your JPEG, PNG, etc libraries, 3 or 4 different audio libraries with a couple different versions installed. Multiple versions of multiple libraries; an endless proliferation of crap that all does the same job with only the most miniscule of differences. All for the sake of an illusion of "choice" foisted on the end user by a fractious developer base with a raging case of Not Invented Here Syndrome and a belief that their convenience is more important than a consistent experience for the end user.

    Now, how bloated must that be?

  32. Excellent, Smithers! by Medievalist · · Score: 2, Insightful

    Despite all the boring back-and-forth between the supporters and detractors of defining a new plural word meaning computer virii (as opposed to biological viruses) you have just made the first intelligent comment that wasn't annoyingly longwinded pedantry.

    And furthermore.... oh, shit!

  33. Re:Obligitory... by Quantum+Fizz · · Score: 3, Interesting
    The Finder is the most prolific and outrageous example of this, and anybody who's ever lost a network connection while a network share was mounted knows what I'm talking about (the system virtually hangs for 45 seconds until the connection times out. awful. simply awful)

    Hopefully you won't need to wait too much longer. As reported on Mac Rumors , as of at least Jan. 26, Apple has been seeking a "Finder Software Engineer". Hopefully we can see a better Finder out in Leopard.

    The job requirements were listed as

    • Participate in all of the various stages of feature development from design brainstorms, through feature development, all the way to fixing that last critical elusive bug under a tight release deadline.
    • You will be required to produce clear designs, excellent implementation and tight code.
    • Deliver tight, well implemented features, fix bugs and develop Finder into the best file browser on the planet.
    • Work on performance and responsiveness of the Finder, making it feel lightweight, fast, snappy and pleasant to use.
  34. Re:Kinda OT.. yet relevant to this thread by essinger · · Score: 2, Funny

    Help! I can't understand why 'apt-get install Half-Life_2' isn't working!

    > Lets see, for Windows I must:
    > 1) Goto Store
    > 2) Pay for Software
    > 3) Insert CD
    > 4) Wonder what Autoplay is going to do
    > 5) Navigate non-standard installation

    > For my debian/ubuntu systems:
    > 1) apt-get install softwarex

  35. Re:Kinda OT.. yet relevant to this thread by Macka · · Score: 4, Insightful
    Have you ever heard of versiontracker?

    *puts small business owner hat on*

    No.
    So you're telling us that a "small business owner" doesn't know how to Google for an app and stumble onto VersionTracker (which he/she should suspect exists anyway as similar sites exist for Windows) but the same "small business owner" knows what a Terminal app is; knows how to drive a command line, and knows that he/she needs to use a command called "apt-get".

    I don't believe you!

  36. Re:Kinda OT.. yet relevant to this thread by Blakey+Rat · · Score: 2, Interesting

    The reason Apple lets you is probably more historical than anything...

    Mac OS has let you move apps anywhere before the concept of an "Applications Folder" even existed. (I don't think Apple added one in until Mac OS 7... or maybe even 8.) Used to be you'd put your common applications on the root level of the drive and then make a Utilities folder for the other stuff. At least I did. But really, the whole filesystem was a playground and you could put stuff where you want.

    Now OS X lets you put applications anywhere, but it's too goddamned stupid to figure it out. My Applications folder was messy, so I made categories... "Media Players," "Internet Apps," etc. The first time I ran Software Update, OS X decided to re-download ALL of the apps that come with it because it thought I deleted them. So the choice is have an organized Applications folder, or don't use Software Update... pain in ass!

    Behind the Finder, Software Update is probably the stupidest application on OS X.