Darwin/macOS emulation layer for Linux
Go to file
2012-08-02 14:17:23 +02:00
include Remove whitespace [Gun.io WhitespaceBot] 2011-10-21 06:55:37 -04:00
libmac OSAtomicEnqueue operation implementation 2012-08-02 14:17:23 +02:00
mach Handle fflush(NULL) properly 2012-04-02 16:47:00 +09:00
.gdbinit Apparently, we want set follow-fork-mode child 2011-03-27 21:12:06 +09:00
.gitignore Remove whitespace [Gun.io WhitespaceBot] 2011-10-21 06:55:37 -04:00
binfmt_misc.sh Now binfmt_misc.sh handles 32bit Mach-O as well 2011-06-16 23:40:24 +09:00
env_flags.h Log output can be controled by env 2011-03-26 05:28:18 +09:00
extract.cc Use return values of fwrite 2011-10-11 11:09:08 +09:00
fat.cc s/x86/i386/ 2011-05-22 16:12:26 +09:00
fat.h Add fat.h and fat.cc to share code in extract.cc 2011-03-11 02:52:03 +09:00
gdb_maloader.py Add a gdb command to output no demangled symbols 2011-03-26 20:00:49 +09:00
ld-mac.cc Don't try mmapping empty segments 2011-12-28 19:12:19 +09:00
ld-mac.sh Add a short description and license to ld-mac.sh 2011-06-16 23:53:12 +09:00
log.cc Log output can be controled by env 2011-03-26 05:28:18 +09:00
log.h Add a make target to create a release binary 2011-03-28 21:00:36 +09:00
mach-o.cc Fixes for classic (<10.5) binaries 2011-12-12 16:33:35 +09:00
mach-o.h Use values in classic weak binds 2011-12-08 03:25:22 +09:00
macho2elf.cc Use return values of fwrite 2011-10-11 11:09:08 +09:00
Makefile Version 0.4 2011-12-13 12:26:22 +09:00
no_trampoline.tab The first code commit. 2011-03-10 00:55:54 +09:00
README Now ld in xcode4 should work 2011-11-13 18:10:55 +09:00
rename.tab Handle compat_mode, used from uname(1) 2012-07-02 23:42:22 +09:00
runtests.sh Use ld-mac explicitly in runtests.sh 2011-11-12 09:54:39 +09:00
unpack_xcode.sh Can unpack xcode-4.1 for snow leopard 2011-11-12 10:35:21 +09:00

This is a userland Mach-O loader for linux.

* Usage

% make release
% ./ld-mac mac_binary [options...]

You need OpenCFLite (http://sourceforge.net/projects/opencflite/)
installed if you want to run some programs such as dsymutil.
opencflite-476.17.2 is recommended.

* How to use compiler tool chains of Xcode

Get xcode_3.2.6_and_ios_sdk_4.3__final.dmg (or another xcode package).

% git clone git@github.com:shinh/maloader.git
% ./maloader/unpack_xcode.sh xcode_3.2.6_and_ios_sdk_4.3__final.dmg
% sudo cp -a xcode_3.2.6_and_ios_sdk_4.3__final/root /usr/i686-apple-darwin10
% cd maloader
% make release
% ./ld-mac /usr/i686-apple-darwin10/usr/bin/gcc mach/hello.c
% ./ld-mac a.out

* How to run Mach-O binaries using binfmt_misc

% ./binfmt_misc.sh
% /usr/i686-apple-darwin10/usr/bin/gcc mach/hello.c
% ./a.out

To remove the entries, run the following command:

% ./binfmt_misc.sh stop

* How to try 32bit support

% make clean
% make all BITS=32

If you see permission errors like

ld-mac: ./mach/hello.c.bin mmap(file) failed: Operation not permitted

you should run the following command to allow users to mmap files to
addresses less than 0x10000.

% sudo sh -c 'echo 4096 > /proc/sys/vm/mmap_min_addr'

Or, running ld-mac as a super user would also work.

* How to run both 64bit Mach-O and 32bit Mach-O binaries

% make both
% ./binfmt_misc.sh start `pwd`/ld-mac.sh
% /usr/i686-apple-darwin10/usr/bin/gcc -arch i386 mach/hello.c -o hello32
% /usr/i686-apple-darwin10/usr/bin/gcc -arch x86_64 mach/hello.c -o hello64
% /usr/i686-apple-darwin10/usr/bin/gcc -arch i386 -arch x86_64 mach/hello.c -o hello
% ./hello32
Hello, 32bit world!
% ./hello64
Hello, 64bit world!
% ./hello
Hello, 64bit world!
% LD_MAC_BITS=32 ./hello
Hello, 32bit world!

* Which programs should work

OK

- gcc-4.2 (link with -g requires OpenCFLite)
- otool
- nm
- dyldinfo
- dwarfdump
- strip
- size
- dsymutil (need OpenCFLite)
- cpp-4.2
- clang
-- clang-70 (xcode 3.2.6): OK, but linking wasn't checked due to lack of sysroot
-- clang-137 (xcode 4.0): OK

not OK

- llvm-gcc
- gnumake and bsdmake
- lex and flex
- ar
- m4
- gdb
- libtool
- nasm and ndisasm (i386)
- mpicc, mpicxx, and mpic++

* Notice

- Running all Mac binaries isn't my goal. Only command line tools such
  as compiler tool chain can be executed by this loader.
- A slide about this: http://shinh.skr.jp/slide/ldmac/000.html

* TODO

- read dwarf for better backtracing
- make llvm-gcc work
- make ld in xcode4 work
- improve 32bit support
- handle dwarf and C++ exception

* License

Simplified BSD License.

Note that all files in "include" directory and some files in "libmac"
were copied from Apple's Libc-594.9.1.
http://www.opensource.apple.com/release/mac-os-x-1064/