ELF Assembler
A robust library for constructing and analyzing ELF (Executable and Linkable Format) binaries, tailored for Linux and Unix-like systems.
🏛️ Architecture
graph TB
subgraph "ELF Construction Pipeline"
A[Object Data] --> B[Section Header Table]
B --> C[Program Header Table]
C --> D[Relocation Resolver]
D --> E[Symbol Table Generator]
E --> F[ELF Binary]
subgraph "Metadata Sections"
G[.text / .data]
H[.symtab / .strtab]
I[.rela.text]
J[.dynamic]
end
B --> G
E --> H
D --> I
C --> J
end
🚀 Features
Format Integrity
- Multi-Type Support: Generates Relocatable files (ET_REL), Executables (ET_EXEC), and Shared Objects (ET_DYN).
- Architecture Adaptation: Automatically configures ELF Class (32/64 bit), Endianness, and OS ABI metadata.
- Section Layout: Calculates section offsets and alignment, handling serialization of the
.shstrtabsection name table.
Core Capabilities
- Symbol & Relocation: Implements full symbol table mapping and relocation type processing (e.g.,
R_X86_64_PC32), supporting external symbol references. - Dynamic Linking: Constructs
.dynamicsections, configuring metadata required by dynamic loaders such asDT_NEEDEDandDT_SONAME. - Program Header Layout: Automatically generates
PT_LOADsegments, managing read/write/execute permissions for memory segments.
Advanced Features
- Stripping: Supports optional symbol table stripping to reduce binary size.
- Zero-Copy Writing: Reduces I/O pressure by pre-allocating buffers when building large binaries.
💻 Usage
Generating a Simple ELF Executable
The following example demonstrates how to wrap raw x86_64 machine code into an ELF executable.
use ;
use ;
🛠️ Support Status
| Feature | x86_64 | ARM64 | RISC-V |
|---|---|---|---|
| ELF Header | ✅ | ✅ | ✅ |
| Program Headers | ✅ | ✅ | ✅ |
| Section Headers | ✅ | ✅ | ✅ |
| Relocations | ✅ | 🚧 | 🚧 |
| Dynamic Linking | ✅ | 🚧 | 🚧 |
Legend: ✅ Supported, 🚧 In Progress, ❌ Not Supported
🔗 Relations
- gaia-types: Utilizes the
BinaryReaderandBinaryWriterfor structured I/O of ELF headers and tables. - gaia-assembler: Provides the ELF encapsulation layer for the assembler's Linux/Unix native backends.