Emulating Linux Binaries Under MAC Os X

Is a Linux executable compatible with OS X?

No, Linux and Mac OS X binaries are not cross-compatible.

For one thing, Linux executables use a format called ELF.

Mac OS X executables use Mach-O format.

Thus, even if a lot of the libraries ordinarily compile separately on each system, they would not be portable in binary format.

Furthermore, Linux is not actually UNIX-based. It does share a number of common features and tools with UNIX, but a lot of that has to do with computing standards like POSIX.

All this said, people can and do create pretty cool ways to deal with the problem of cross-compatibility.

EDIT:

Finally, to address your point on byte-code: when making a binary, compilers usually generate machine code that is specific to the platform you're developing on. (This isn't always the case, but it usually is.)

Is this file unable to be executed in macOS?

In general, binaries that are designed for one OS cannot be executed on another. Your binary is designed for Linux, so it will not run on macOS. There are emulators that allow this in some cases, although macOS does not ship with one.

In addition, your binary, like most Linux binaries, is an ELF executable, and macOS uses Mach-O executables. The macOS kernel wouldn't even be able to parse the binary format to execute it.

If you want to run this binary on a Mac, you can try using Docker or a Linux VM to run this binary.

Compile Linux program from Mac OS X with Free Pascal

Success! If you install Fink and then say

sudo fink install fpc-i386-linux

it will install Free Pascal and everything you need to cross compile. You will then be able to say

/sw/bin/fpc -Tlinux hw.pas

and get a Linux executable.

Executing Binary Files

It's highly unlikely that a binary compiled for a particular OS will run on another. Either get a binary for Mac, or get the source and compile it yourself.

There are many things that will cause issues - version of libc and libstdc++, there can be difference in versions of .so libraries - different API interface to the OS itself. Or even a different binary format (ie VMS binaries do not run on AIX).

Is it possible to run an executable built for one operating system on another?

  1. First, the dynamic library is not the only OS specific part, the startup code is statically linked and OS X/Linux specific.
  2. The OS X binary is macho, Linux requires ELF.
  3. Even if it were ELF, there is an ELF identifier that needs to be patched to make the dyn loader even consider it.
  4. syscalls might be inlined. (man 2 usage), same with FD set macros and many other macros in OS X libc headers.
  5. the calling conventions might be different (

    • register usage
    • stack alignment
    • passing of small structures in registers.

etc,etc. In this case e.g. OS X uses AIX ABI, and Linux SysV.
)

In general, POSIX is a source compatibility concept, not a binary one. So no, this is not possible, or only under unworkable constrained requirements. Exceptions are things like the Linuxator on BSD systems.



Related Topics



Leave a reply



Submit