0

Based on my humble understanding of computer internals, if you compile a C program for a particular instruction set architecture, the resulting executable will be the same for any operating system, with the exception of system calls.

On the other hand, executables for different instruction set architectures are completely different.

Why then, when you want to download a program for the internet, you are usually presented with choices based on your OS, rather than instruction set architecture?

Also, since there are so many instruction set architectures, I cannot really imagine what an installer looks like. For example if an installer supports 20 different architectures, is 95% of the data discarded during installation?

1 Answer 1

2

Do installation files such as .deb contain machine instructions for every supported architecture?

No, .deb packages – and generally packages for almost all Linux packaging systems – are built only for one specific architecture. Usually that architecture is even noted in the file name.

Why then, when you want to download a program for the internet, you are usually presented with choices based on your OS, rather than instruction set architecture?

  • Windows mainly supports only the x86(_64) architecture. (Most developers don't consider Alpha AXP and Itanium to be relevant, and the ARM version of Windows doesn't allow third-party programs to be run at all.)

  • OS X and iOS use "fat binaries" (see below).

  • For Linux/BSD, the compilable source code is provided and the end-user – or the distro packager – builds it for the needed architecture.

    (What if the software is only provided in binary form?
    Well, 99% of the time, if you're not on x86 then you're screwed.)

  • Android apps are distributed as Dalvik byte-code; they're translated to native code during installation (if you've got ART).

  • .NET "managed" code works the same way; the .exe files contain CIL byte-code which ngen can convert to native code during installation, or which can be run directly on the .NET runtime.

For example if an installer supports 20 different architectures, is 95% of the data discarded during installation?

Depends on the installation method. (Let's assume the program is built as a native binary, not Android/.NET/Java bytecode.)

  • In the Windows case, usually you have several different single-architecture installers in the first place, and only download the right one.

    But when the program is shipped as a single multi-architecture CD, then yes, the installer only copies files for your architecture, and ignores everything else. (There's no point in copying unusable files after all.)

  • For Linux packages it is the same – a pile of arch-specific .deb packages, for example.

  • Ever since the move from PowerPC to Intel, many OS X programs are built as "fat binaries", where a single executable file contains code for both architectures, and when you "install" it everything is copied exactly. (So, yes, the programs tend to be twice as large as they could be.)

    However, I've heard that the iOS App Store has switched to only accepting LLVM bitcode and automatically compiling it into separate versions for all architectures.

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .