How rui314/mold works
mold is a high-performance, cross-platform ELF linker. The principal workflow takes linker arguments and object files, resolves their sections and symbols, applies link-time transformations and target-specific relocation logic, then emits an executable or shared library. The graph also preserves documented multi-architecture support and indexed subsystems such as LTO, garbage collection, identical code folding, and debug-index generation. Some internal links are dashed because the sampled excerpts and index identify modules but do not expose their runtime call sites.
Main entry points: driver.rs Link driver · input_files.rs Input files · passes.rs Link passes · output_file.rs Output file
Components 20
Link entry
- CLI entry
cli/main.rs - Argument parsing
src/cmdline.rs - Link driver
src/driver.rs
Input analysis
- Input files
src/input_files.rs - Mapped files
src/mapped_file.rs - Input sections
src/input_sections.rs - Symbol resolution
src/symbol.rs - Linker scripts
src/linker_script.rs
Link construction
- Link passes
src/passes.rs - Section garbage collection
src/gc_sections.rs - Identical code folding
src/icf.rs - Link-time optimization
src/lto.rs - Target backend
src/target/mod.rs - Range thunks
src/thunks.rs
Output backend
- Merged sections
src/chunks/merged.rs - Output sections
src/chunks/output_section.rs - ELF output chunks
src/chunks/mod.rs - Output file
src/output_file.rs - GDB debug index
src/gdb_index.rs
Other components
- Build invocation
Connections 22
- Build invocation → CLI entry: invokes
- CLI entry → Link driver: starts link
- Link driver → Argument parsing: parses options
- Link driver → Input files: loads inputs
- Input files → Mapped files: maps files
src/input_files.rs - Input files → Input sections: parses sections
src/input_files.rs - Input files → Symbol resolution: reads symbols
src/input_files.rs - Link driver → Linker scripts: uses scripts
- Link driver → Link passes: runs passes
- Link passes → Section garbage collection: performs collection
- Link passes → Identical code folding: performs folding
- Link passes → Link-time optimization: invokes LTO
- Input sections → Merged sections: deduplicates fragments
src/chunks/merged.rs - Input sections → Output sections: provides members
src/chunks/output_section.rs - Target backend → Range thunks: defines target hooks
src/target/mod.rs - Output sections → Range thunks: uses thunks
src/chunks/output_section.rs - Link driver → Target backend: selects target
- Merged sections → Output file: writes data
src/chunks/merged.rs - Output sections → Output file: writes sections
src/chunks/output_section.rs - ELF output chunks → Output file: writes ELF chunks
- Link driver → GDB debug index: generates index
- Build invocation → Output file: receives linked ELF
README.md