4 ms·
There are a few roadblocks that probably will not be overcome, at least not without introducing more of those abstraction layers. The binary format itself is a
by corty 6y ago
There are a few roadblocks that probably will not be overcome, at least not without introducing more of those abstraction layers.
The binary format itself is a roadblock, because the loader of your OS needs to know that in order to load and start your program. To be compatible e.g. for PE and ELF, you would either need another loader or binaries that look like both formats at the same time. The latter isn't really possible (except for some interesting puzzles) the former is what binfmt support in Linux does. On other OSes, you do that manually like in "java foobar.class" or "wine something.exe".
The syscall convention is another problem, every OS does them somewhat differently, and even the same OS on the same architecture can have different conventions one may use: int 0x80 (or whatever number one likes), call gates, SYSENTER, traps or trampolines. I certainly forgot a few. Within those there is another variability around parameter passing and return values (register, stack, magic location, all of the above), buffer handling for larger parameters and preserved registers. Syscall names, numbers and semantics are all totally different. Then there are mechanisms like unix signals and callbacks from the OS, futures and zero-copy-IO that are very very OS specific. There also is absolutely no smallest common denominator.
Memory layout has peculiarities, like randomisation, different sections, who sets up the stack, that kind of stuff. Mostly the linker and loader will do things here, but again, it depends.
And then there are libraries. Even if you use a static binary (which you probably would have to), modern OSes still expect you to dynamically link some libraries like all syscall entry points or stubs, things like libnss, etc.
All in all quite impossible without at least another layer like wine or the java vm, some big loader switch/case and quite a bit of fiddling to adapt to some hard-to-adapt peculiarities. E.g. the Linux kernel has quite a few things built specially for wine to work.