Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

Create Account  |  Retrieve Password

How OS X Executes Applications

Posted by Hemos on Mon Mar 27, 2006 12:04 PM
from the learning-more-about-it dept.
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."
+ -
story
This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More
Loading... please wait.
  • by Anonymous Coward on Monday March 27 2006, @12:07PM (#15003800)
    When FORCE QUIT doesn't work, 120V A/C to the processor does the trick every time.
      • A/C is amps per coulomb. Since an amp is a coulomb per second, the parent is clearly refering to the frequency.
      • 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.

  • by pryonic (938155) on Monday March 27 2006, @12: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, @12:17PM (#15003871)
    Do you mean big "O" tool?
  • by Anonymous Coward on Monday March 27 2006, @12:20PM (#15003899)
    With extreme prejudice?
  • 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, @12:59PM (#15004207) Homepage

    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.

  • by davek (18465) on Monday March 27 2006, @02: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?
    • by geoffspear (692508) on Monday March 27 2006, @02: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.

    • 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

      • 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 upgra
    • The icon bounces, bounces and bounces. I know my 800Mhz iBook with 640Megs RAM isn't the latest/fastest machine, but when I boot back into Ubuntu Dapper it's MUCH faster.

      It's you and anyone else who has a 800Mhz PPC. (I've got a flowerpod iMac myself and it is a dog)

      If I you happen to have a Intel or a 2ghz G5 then its not as much as a problem.

      Even my PPC 1.5Ghz mini isn't as bad as the earlier systems.
      • Unless you're running Firefox, of course. I have an 800Mhz iBook G4 with 640MB RAM as well as a 2GHz iMac Core Duo with 512MB of RAM, and Firefox's memory leak brings both to their knees due to swapping. If only I wasn't such a fan of all those extensions and that cross-platform-ness...
    • A lot of that might be your applications. I use Thunderbird instead of Mail, and it's faster. OO.o beats NeoOffice, and Adium is faster than AIM.
    • What about kde, which does the exact same thing but tied to the mouse cursor?

      "that it does in the background isn't helping me check my email, instant message or ssh to remote boxes."

      Call me crazy, but I dont think everything linux does is helping you do those things either:

      [4294669.546000] Checking for popad bug... OK.

      POPAD BUG? WTF THAT IS NOT EMAIL/BROWSING/IM/SSH!!!! STOP WASTING MY MEGAHURTSZ!!!
    • 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.

      Go
    • I take it that transferring 17MB folders is strictly off limits then?
    • Re:Obligitory... (Score:5, Interesting)

      by moosesocks (264553) on Monday March 27 2006, @01:22PM (#15004378) Homepage
      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.
      • Re:Obligitory... (Score:4, Interesting)

        by Quantum Fizz (860218) on Monday March 27 2006, @04:54PM (#15006314)
        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 [macrumors.com], 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.
      • I hadn't thought of that. My Mac is new enough to have accelerated Quartz Extreme graphics, so the bouncing is almost free for me (the graphics card is doing all the heavy lifting).

        But for him, I'm guessing his iBook doesn't have a good enough graphics chip, so his CPU is doing all that compositing... which would really slow things down during an app launch.

        Interesting point!

        • That probably has ALLOT to do with it, I don't have the 'quartz extreme' thanks to this graphics card. Turning off the 'bounce' is something I'll def do tonight, appreciated.

          And also, just so no one is confused, I love my iBook, and OS X *is* my second favorite Desktop OS, but there's just a huge gap in speed on my setup. Still, I am foaming at the mouth (well maybe not really, but...) at the prospect of a new Intel iBook, and have already spec'd out a local store where I can trade in my old 800Mhz (along
    • Same reason 3com.com, 37signals.com, and 23.com exist: the RFC was a Request For Comments, and some people commented "no."
    • Offtopic, but can someone tell me how "0xfe.blogspot.com" is a valid domain?

      According to RFC 1034:

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

      Please read what is written a few lines above: "The following syntax will result in fewer problems with many applications that use domain names (e.g., mail, TELNET)."

      I have some code to fix if "someone@0xfe.blogspot.com" could be a valid address...

      Time to fix some code then ;-)

      • 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

      • Thanks, that looks great. I'll definitely invest some time in knowing Gobo better.

        Anychance this would make it's way to mainstream distros like Ubuntu?
      • by Anonymous Coward
        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.
          • 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 application
      • by Raffaello (230287) on Monday March 27 2006, @01:08PM (#15004268)
        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.

        • 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 handli
          • 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!
            • 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
            • Screw the disk space. It uses up much more RAM than a shared-library solution.
          • by GlassHeart (579618) on Monday March 27 2006, @02:12PM (#15004778) Journal
            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.

              • by Macka (9388) on Monday March 27 2006, @05:47PM (#15006771)
                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!

          • by Senjutsu (614542) on Monday March 27 2006, @04:22PM (#15005999)
            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?
        • 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.
    • by Haeleth (414428) on Monday March 27 2006, @12:32PM (#15003987) Journal
      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?