elfportable-executablemach-o

What is the difference between executable formats?


Are there any major differences between PE, ELF and Mach-O? I mean, are does one have capabilities the others don't? Can one carry more information then the others? Or are they just a different container format for the same info?
I am not very knowledgeable on this, but it seems to me that they all carry text (code) sections, initialized and uninitialized data sections, etc. as well as relocation, symbol, string, import and export tables.

I am not asking about minor differences, such as that format X can split a data section or that format Y can be more efficiently parsed in hardware.
I am asking about major differences, such that they might affect the choice for a new general-purpose OS. Or that if a platform had a loader for all 3 formats, would it be trivial to convert from one format to the other by just "repackaging" the sections and rewriting the tables to the new format.


Solution

  • I am asking about major differences, such that they might affect the choice for a new general-purpose OS.

    In the long-run, there are little major differences between them – each tends to eventually gain whatever features it is missing compared to the others, and they all are converging towards feature-parity over time, at least for those features which are widely considered important nowadays.

    Some unique features:

    Overall, if you were starting a new OS from scratch, and weren't particularly concerned about compatibility with Apple or Microsoft, ELF is probably the answer – if you look at the OS research community, and the hobbyist OS development community, it is the most common choice. If things go wrong, ELF is the easiest format to get help with and find people with in-depth experience with. And if you really need any of the features missing from ELF, you could always define them as your own extensions.

    It is also worth noting that there are yet other executable formats still in use, even if more obscure than the "big 3". IBM AIX uses XCOFF, which like Microsoft's PE-COFF is an evolution of AT&T's original COFF format (which AT&T later replaced with ELF), but a divergent evolution. IBM z/OS uses GOFF, which is something entirely particular to IBM. If we start looking at systems no longer in common use, myriad other formats emerge – but there is a definite tendency to move away from "let's invent our own executable format". Even systems which used to use some custom format sometimes end up migrating to ELF – a good example of that is OpenVMS, which used to use its own proprietary executable format on VAX and Alpha, but with the move to Itanium adopted ELF instead (a decision continued by the new x86-64 port). Inventing a new executable format is most likely a waste of time, unless it has some compelling advantage over existing formats, or is aimed at a very different use case from them (see WebAssembly module format for a recent entirely justifiable example of "invent a new format")