Mach-O Assembler
A robust library for building and manipulating Mach-O (Mach Object) files, the standard executable format for macOS, iOS, and other Apple platforms.
🏛️ Architecture
graph TB
subgraph "Mach-O Generation Pipeline"
A[Mach-O Program Model] --> B[Load Command Builder]
B --> C[Segment/Section Allocator]
C --> D[Symbol Table Generator]
D --> E[Mach-O Binary]
subgraph "Format Variants"
F[Object File .o]
G[Executable]
H[Dynamic Library .dylib]
end
E --> F
E --> G
E --> H
end
🚀 Features
Core Capabilities
- Multi-Type Support: Generates Mach-O Object files, Executables, and Dynamic Libraries (
.dylib). - Load Command Management: Automatically constructs essential load commands like
LC_SEGMENT_64,LC_SYMTAB,LC_DYSYMTAB, andLC_MAIN. - Architecture Support: Full support for
x86_64andarm64(Apple Silicon) binary layouts.
Advanced Features
- Fat Binary Support: Capability to bundle multiple architecture-specific Mach-O files into a single Universal Binary (🚧).
- Symbolic Linkage: Manages external symbols and dynamic library dependencies through
LC_LOAD_DYLIBcommands. - Section Alignment: Precise control over memory alignment for text, data, and __objc sections.
💻 Usage
Creating a Mach-O Dynamic Library
The following example demonstrates how to write a Mach-O program model to a .dylib file.
use ;
use Path;
🛠️ Support Status
| Platform | Object (.o) | Executable | Dylib (.dylib) | Fat Binary |
|---|---|---|---|---|
| macOS (x86_64) | ✅ | ✅ | ✅ | 🚧 |
| macOS (arm64) | ✅ | ✅ | ✅ | 🚧 |
| iOS | 🚧 | 🚧 | 🚧 | ❌ |
Legend: ✅ Supported, 🚧 In Progress, ❌ Not Supported
🔗 Relations
- gaia-types: Utilizes the
BinaryWriterfor precise byte-level construction of Mach-O headers and load commands. - gaia-assembler: Acts as the primary Mach-O encapsulation backend for the assembler when targeting Apple platforms.