About Darling

How Darling Works

Darling works in a way very similar to Wine.

It parses executable files for the Darwin kernel (Mach Object Files; Mach-O), loads them into the memory (just like ld-linux.so does with ELF executables) and executes them. That is indeed not sufficient. Darling needs to provide ABI-compatibile set of libraries and frameworks as available on OS X.

This is done by either

  • directly mapping functions to those available on Linux, or
  • wrapping native functions to bridge the ABI incompatibility, or
  • providing a reimplementation on top of other native APIs.

Special focus is aimed at the Objective-C runtime. Upon loading an Objective-C executable, Darling locates all Objective-C metadata and through its translation layers, it registers everything with the GNUstep libobjc2 runtime.

iOS

Darling could be used to run applications compiled for iOS (iPhone/iPad). This would require porting some minimum amount of assembly code to the ARM architecture and actually supporting the frameworks used on that platform (UIKit to begin with). As Android currently dominates the market, there is probably little reason to invest time in such an effort.

Project Chameleon may be worth looking at nonetheless.

So far, the experiments show that Android NDK not only is extremely buggy, but the system misses usual GNU libraries used on iOS. Root privileges would also be needed.

localhost darling # LD_LIBRARY_PATH=lib bin/dyld 
This is Darling dyld for arm.
Copyright (C) 2012-2013 Lubos Dolezel
Copyright (C) 2011 Shinichiro Hamaji

Usage: bin/dyld program-path [arguments...]

Environment variables:
        DYLD_DEBUG=1 - enable debug info (lots of output)
        DYLD_ROOT_PATH=<path> - set the base for library path resolution (overrides autodetection)
        DYLD_BIND_AT_LAUNCH=1 - force dyld to bind all lazy references on startup

localhost darling # LD_LIBRARY_PATH=lib bin/dyld bin/main-ios 
Your vm.mmap_min_addr is too low for this application to be loaded. Try running `sysctl -w vm.mmap_min_addr="4096"'
localhost darling # sysctl -w vm.mmap_min_addr="4096"
vm.mmap_min_addr = 4096
localhost darling # LD_LIBRARY_PATH=lib bin/dyld bin/main-ios
Cannot load /usr/lib/libgcc_s.1.dylib: File not found: libgcc_s.1.dylib

Perhaps, Ubuntu for Mobile/Tablets would be better.

Implementation

Darling is implemented in C++11 (and Objective-C). This is the case even for C-style APIs. The reason for this decision is the simplicity of the resulting code. C++'s features enable us to greatly reduce the amount of code needed to implement features, avoid code duplication and therefore reduce the risk of bugs.