3 ms·
How is it possible to build once and run on both Windows and Linux if Windows uses the PE executable format and Linux uses ELF? Is there some kind of trickery
by nextaccountic 6y ago
How is it possible to build once and run on both Windows and Linux if Windows uses the PE executable format and Linux uses ELF?
Is there some kind of trickery to make a file both PE and ELF valid? Doesn't magic numbers conflict?
- wernercd 6y agoIL code. .net compiles to intermediate language which runs on a local interpeter. https://en.wikipedia.org/wiki/Common_Intermediate_Language https://en.wikipedia.org/wiki/Common_Intermediate_Language https://www.i-programmer.info/programming/other-languages/933-getting-started-with-il.html https://www.i-programmer.info/programming/other-languages/93...
- jart 6y agoAPE executables are PE executables that embed a shell script in the MS-DOS stub. The GNU or LLVM linker is configured to generate a printf '\177ELF...' >$0 statement which inserts the ELF or Mach-O header into the first 64-bytes depending on where the executable is run. See https://justine.lol/ape.html https://justine.lol/ape.html and https://raw.githubusercontent.com/jart/cosmopolitan/master/ape/ape.S https://raw.githubusercontent.com/jart/cosmopolitan/master/a...
- nextaccountic 6y agoThis is so freaking cool!
- nextaccountic 6y ago.. actually, wait, are you the author? Thanks for open sourcing this! Can I use it to make a Rust executable? Maybe it can post-process the executable built by Rust somehow? (I guess Rust needs to link against the cosmopolitan libc and otherwise not make any syscalls) Maybe it's possible to make a cosmopolitan Rust target, like, x86-unknown-cosmopolitan? Also, does it support x86_64? (and maybe a fat x86/x86_64 binary as well?)