5 ms·
Why does linux only support ELF? Other executable formats, for instance, support multiple architectures per file. Why does Linux not?
by PrinceKropotkin 6y ago
Why does linux only support ELF?
Other executable formats, for instance, support multiple architectures per file. Why does Linux not?
- saagarjha 6y agoIt seems like you’re really asking two questions. My comment for the first one is that you can use binfmt_misc to add your own executable formats. For the second one, is there anything other than Mach-O that does that?
- pdmccormick 6y agoThe Linux kernel actually does allow executing non-ELF executables, via the binfmt_misc (https://en.wikipedia.org/wiki/Binfmt_misc https://en.wikipedia.org/wiki/Binfmt_misc) mechanism. My favourite use for this feature is via `qemu-user-static`, which allows you to transparently "run" executables compiled for other architectures thanks to QEMU emulation. Very handy for embedded systems development.
- pjmlp 6y agoI remember some people using this to launch java applications.
- JoshTriplett 6y agoFor one thing, lack of demand. Linux distributions can relatively easily ship different packages for different architectures, and doing so is more space-efficient. It seems to me like shipping multiple binaries within a package is mostly useful for the distribution of proprietary software, and even in that case, it isn't that hard to ship two binaries and a shell script.
- PrinceKropotkin 6y agoHow does linux negotiate which arch's binary is loaded? I know plan9 had arch-specific object paths bound at boot time to PATH. How do you, say, boot multiple arches off the same root NFS share?
- moonchild 6y agoThat's a function of your runtime dynamic linker, which is most likely provided by glibc (on linux). I believe it supports a.out still; at the very least, it used to.
- pjc50 6y agohttps://www.phoronix.com/scan.php?page=news_item&px=Linux-Dropping-A.Out https://www.phoronix.com/scan.php?page=news_item&px=Linux-Dr... : >20 years after obsoleting it, it's being dropped. Longer than I would expect!
- bregma 6y agoNope. It's a function of the kernel, which needs to know the binary format in order to load the executable. The dynamic linker is invoked at a later phase of execution, and in the case of the ELF file it does that by reading the dynamic linker's name from the PT_INTERP entry in the Dynamic table stored in the PT_DYNAMIC segment. By default, if the kernel doesn't recognize the ELF magic (first 4 bytes in the file are `\0x7fELF`), or can't load the dynamic linker specified in the PT_INTERP entry (eg. wrong architecture), it will launch /bin/sh as the interpreter and feed the loaded file to it assuming it's a text file containing a shell script. If the kernel has the bin_fmt mod loaded, it can also recognize other binary formats before falling back to /bin/sh.
- bregma 6y agoYou can only ever run software for one architecture on a single machine, why pay for getting stuff you can't use?
- PrinceKropotkin 6y agoIt's pretty common to run multiple arches off an eg fileserver, is it not? Seems like it'd be useful to keep the same path used across arches.