Skip to content

Instantly share code, notes, and snippets.

@omarzl
Last active May 30, 2024 18:48
Show Gist options
  • Save omarzl/6133bbce3a4e175a6d0f2bc265907b89 to your computer and use it in GitHub Desktop.
Save omarzl/6133bbce3a4e175a6d0f2bc265907b89 to your computer and use it in GitHub Desktop.
Mergeable libraries
# Section 1
# Create a class
echo "class MyClass {}" > file.swift
# Compile a static library
swiftc file.swift -static -emit-library -o libStaticExample.a
# Compile a dynamic library
swiftc file.swift -emit-library -o libDynamicExample.dylib
# Compile a mergeable library
swiftc file.swift -emit-library -Xlinker -make_mergeable -o libMergeableExample.dylib
# Section 2
# Outputs Mach-O header from static library
otool -h libStaticExample.a
# Mach header
# magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
# 0xfeedfacf 16777223 3 0x00 1 10 1520 0x00002000
# Outputs Mach-O header from dynamic library
otool -h libDynamicExample.dylib
# Mach header
# magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
# 0xfeedfacf 16777223 3 0x00 6 17 1952 0x00100085
# Outputs Mach-O header from mergeable library
otool -h libDynamicExample.dylib
# Mach header
# magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
# 0xfeedfacf 16777223 3 0x00 6 18 1976 0x00100085
# Section 3
# Diff from load commands between dynamic and mergeable library
diff <(otool -l libDynamicExample.dylib) <(otool -l libMergeableExample.dylib)
# > Load command 17
# > cmd LC_ATOM_INFO
# > cmdsize 16
# > dataoff 49672
# > datasize 8048
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment