⑨ lab ≡ ByteLabs

Darwin/Build Notes

— Igor Böhm

Random notes on how to build random pieces of software for esoteric use cases on Darwin…

Overview

The notes on this page are for building LLVM and GenSim on Darwin in such a way that I can use them to implement a JIT for a dynamic binary translator. You are probably lost and should hit the return button in your browser. Seriously, this stuff here is specialised for my use case only, go away…!

Prerequisites

Get Xcode, install brew and get the following:

 % brew install cmake
 % brew install ccache
 % brew install ninja

The rest of these notes assume you use plan9port, the closest thing to Plan9 on Darwin. Note that this plan9port is my custom version, not the official one…

Codesigning

 % cat $home/lib/entitlements.xcet
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.security.cs.allow-jit</key>
	<true/>
	<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
	<true/>
	<key>com.apple.security.get-task-allow</key>
	<true/>
</dict>
</plist>
 % codesign \
	--sign \
	- \
	--force \
	--preserve-metadata=entitlements,requirements,flags,runtime \
	--entitlements $home/lib/entitlements.xcet \
	path_to_your_binary

To disable code-signing verification (e.g. during regression testing) run the following in a Terminal:

 % spctl developer-mode enable-terminal

Next, go to System Preferences -> Security & Privacy -> Privacy, and scroll down till you see an entry for Developer Tools. Authenticate, and tick the checkbox next to Terminal.

Build LLVM for Apple Silicon

LLVM 12.0.1

The following build was tested on an M1 Mac Mini running MacOS Big Sur:

 % mkdir -p src/llvm/12.0.1
 % curl -L -o clang-12.0.1.src.tar.xz \
	https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.1/clang-12.0.1.src.tar.xz
 % curl -L -o llvm-12.0.1.src.tar.xz \
	https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.1/llvm-12.0.1.src.tar.xz
 % tar xf clang-12.0.1.src.tar.xz
 % tar xf llvm-12.0.1.src.tar.xz
 % ln -s clang-12.0.1.src clang
 % ln -s llvm-12.0.1.src llvm
 % mkdir build && cd build
 % cmake ../llvm \
      -GNinja \
      -DCMAKE_OSX_ARCHITECTURES='arm64' \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_BUILD_WITH_INSTALL_RPATH=1 \
      -DCMAKE_INSTALL_PREFIX=$HOME/lib/work/llvm/clang+llvm-12.0.1-arm64-apple-darwin \
      -DLLVM_ENABLE_WERROR=FALSE \
      -DLLVM_TARGETS_TO_BUILD='AArch64' \
      -DLLVM_ENABLE_PROJECTS='clang'

 % ninja
 % ninja install

LLVM 9.0.1

The following build was tested on an M1 Mac Mini running MacOS Big Sur:

 % mkdir -p src/llvm/9.0.1
 % curl -L -o clang-9.0.1.src.tar.xz \
	https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/clang-9.0.1.src.tar.xz
 % curl -L -o llvm-9.0.1.src.tar.xz \
	https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/llvm-9.0.1.src.tar.xz
 % tar xf clang-9.0.1.src.tar.xz
 % tar xf llvm-9.0.1.src.tar.xz
 % ln -s clang-9.0.1.src clang
 % ln -s llvm-9.0.1.src llvm
 % mkdir build && cd build
 % cmake ../llvm \
      -GNinja \
      -DCMAKE_OSX_ARCHITECTURES='arm64' \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_BUILD_WITH_INSTALL_RPATH=1 \
      -DCMAKE_INSTALL_PREFIX=$HOME/lib/work/llvm/clang+llvm-9.0.1-arm64-apple-darwin \
      -DLLVM_ENABLE_WERROR=FALSE \
      -DLLVM_TARGETS_TO_BUILD='AArch64' \
      -DLLVM_ENABLE_PROJECTS='clang'

 % ninja
 % ninja install

Build GenSim

 % brew install libantlr3c
 % brew install openjdk
 % path=(/opt/homebrew/opt/openjdk/bin $path)
 … checkout GenSim repository …
 % cmake \
	-DCMAKE_BUILD_TYPE=RELEASE \
	-DANTLR_PATH=/opt/homebrew \
	-DANTLR_JAR=/tmp/antlr-3.4-complete.jar
 % make gensim
 % file dist/bin/gensim
dist/bin/gensim: Mach-O 64-bit executable arm64
 % cp dist/bin/gensim $home/bin/gensim

#Dev #Darwin #Work #SNPS