[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Linux and FreeBSD Emulation notes



I have been trying to run a commercial program that is available for
Linux and FreeBSD only. I have encountered a few problems during the
process and noticed the sparsity of documentation on the subject.

The program is a statically-linked binary, available for recent
versions of Linux and FreeBSD.  I have not been able to run the Linux
version but after some minor modifications, the FreeBSD version ran
successfully.  Here are my observations and possible solutions:

* As with any other problem, FAQ, manpages, archives and google are
  your friends, use them.

* ktrace(1) helps understand many emulation related problems.

* for statically linked binaries, library packages are NOT needed.
  This is obvious but just to keep notes complete :)

* Newer ELF binaries for Linux and FreeBSD could NOT be identified
  automatically by the kernel (tested up to 3.2-beta).

* For Linux binaries you can use elf2olf(1) to convert the binary to
  OLF format that is identified correctly by the kernel.

* (BUG REPORT) The kernel does NOT preserve the EDX register when
  emulating Linux syscalls. This caused the Linux binary to
  crash. Patching the kernel solved the crash, however the binary
  crashed later at some other place so I gave up working on the Linux
  binary and started working on the FreeBSD one.

* elf2olf does NOT work for FreeBSD ELF binaries (have not looked into
  it further). The ELF binary is NOT detected by the kernel as FreeBSD
  and (naturally) crashed in native mode.

* Obviously there are several methods out there that systems use to
  brand the ELF binaries. Recent FreeBSD binaries use an
  identification byte in ELF header while OpenBSD probe routines look
  for a 'brand' string. Supplying a proper kernel patch is beyond me
  so just patch the application binary instead:

  $ echo FreeBSD | dd of=/path/to/binary bs=1 seek=8 count=7 conv=notrunc

  This writes the string "FreeBSD" to the place where OpenBSD ELF
  loader expects it. You can also use a hex editor. Enter the string
  "FreeBSD" at offset 8 from the start of file. Do it ONLY for FreeBSD
  ELF binaries and keep a backup copy. For me it worked.

* With this patch, kernel detected and ran the FreeBSD binary
  successfully.


Hope this helps someone ...

Can



Visit your host, monkey.org