Reputation: 21538
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.
Upvotes: 11
Views: 3485
Reputation: 2403
Mach-O comes from CMU Mach, from 1985. It was adopted by NeXT and then Apple. PE comes from Microsoft Windows NT 3.1, from 1993. ELF comes from ATT's System V, from at the latest 1993. This article says ELF is from the late 80s.
So these are old 32b formats which have since been extended to 64b. Fields have been added and enumerations extended but their structures remain the same. Their major differences are that Mach-O is basic to OSX+iOS; PE is basic to Windows; and ELF is basic to Linux, FreeBSD, .... ELF is also supported on Windows with the Windows Subsystem for Linux. Each supports dynamic libraries, PIE, ASLR, .... You wouldn't choose one over the other based on features but rather you'd choose a target and that would choose your object/executable format. The GNU ld linker handles all three formats and indeed the OSX linker is a forked version of ld.
Upvotes: 3
Reputation: 5298
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")
Upvotes: 16