1

Is it theoretically possible to execute built for one POSIX kernel (Linux for example) on second (Darwin's XNU for example)
And why it isn't possible?

If it's because of libraries and/or shared objects, maybe it's possible to leave just kernel and it's dependencies from whole second OS and use everything else from first?

So you'll have only kernel and drivers from second OS, and you can chroot to some place and you'll be able to run any executable for first?

Or Can we make some kind of dynamic wrapper or static translator?

UPD: Ok, I've found something similar, but there is just cursory recommendations, maybe someone could make it more clear?

Community
  • 1
  • 1
stek29
  • 395
  • 4
  • 14
  • xBinary could be solution, but it's outdated and does not work on modern OSX – stek29 Jan 20 '16 at 12:14
  • the interesting part is that darwins kernel internals actually should have a system call wrapper inside making this easier, but I doubt it's still working the way it should. also freebsd has a support for linux binaries to a certain extend https://www.freebsd.org/doc/handbook/linuxemu.html – Alexander Oh Jan 20 '16 at 13:40

2 Answers2

4

There are just so many details that have to be right in order for programs to run. The libraries and shared objects is the first issue, but even if you replace all of those, the system call interface differs from OS to OS.

And by system call interface, I don't mean the function prototypes, I mean how user-space tasks invoke system calls in the kernel. Even on x86, there are different ways to implement the trap that transitions into kernel mode, and different ways to transmit the system call argument details to the kernel. The details of this are typically built into the libraries/shared objects.

So yes, it's theoretically possible to create a wrapping/translation layer, but that's a lot of work, and it's very difficult to get all the details right. This is one reason why virtualization has become so popular in recent years.

Gil Hamilton
  • 11,973
  • 28
  • 51
0

I happen to have a blogpost on the subject: http://codingtragedy.blogspot.com/2015/04/why-binaries-from-one-os-dont-work-on.html

In short 1. binary format 2. syscalls 3. userspace runtime, all of which can be provided in principle. Real-world examples include BSDs and Illumos running Linux binaries.

  • 1
    Link-only answers are not OK on Stack Overflow. Please, provide some basic information from you blogpost directly in the answer. (So link can be used for obtaining more info). – Tsyvarev Jan 20 '16 at 21:08