Expand description
qld is a fast, parallel linker that accepts GNU ld, gold, lld and mold command lines, and can also be driven as a library.
§Status
Pre-alpha. The pipeline is being implemented milestone by milestone; see
ROADMAP.md. Nothing outside this crate’s root re-exports should be
considered stable, and the root API will not be stable until 1.0.
§Library use
Build LinkOptions by hand or from a command line (parse_gnu), and
call link. Diagnostics go to a DiagnosticSink of your choice.
Inputs can be byte buffers (InputKind::bytes, MemoryFiles), the
output can come back as bytes (link_to_memory, OutputBuffer), a
link can be cancelled from another thread (CancelToken), and it runs
in the caller’s rayon pool, as it is, when called inside
rayon::ThreadPool::install.
A link built with LinkOptions::new is hermetic and silent: the
process never exits, nothing is written to its standard output or
standard error, and no environment variable is read.
LinkOptions::use_process_defaults opts into all three, and
parse_gnu applies it, because it describes the link the qld binary
runs.
use qld::{InputAttrs, InputKind, LinkOptions, OutputKind};
use qld::diag::Collect;
let mut options = LinkOptions::new();
options.kind = OutputKind::StaticExecutable;
options.push_input(InputKind::bytes("main.o", object), InputAttrs::default());
let diagnostics = Collect::new();
let image: Vec<u8> = qld::link_to_memory(&options, &diagnostics)?;The examples/ directory has complete programs: link_argv,
in_memory, custom_sink, rayon_pool and cancel.
§Layout
Modules follow the link pipeline described in docs/architecture.md:
| Module | Role |
|---|---|
args | Option model and the argv front ends |
[input] | Mapping input files, identifying formats, archives |
[symbols] | String interning and the global symbol table |
[passes] | Format-neutral passes: GC, ICF, section merging |
[script] | GNU linker script parser and evaluator |
[output] | Output file writer and post-write steps |
[elf], [coff], [macho], [hunk] | Format backends |
[arch] | Instruction-level helpers shared across formats |
[debug] | DWARF handling: compression, indexes, line lookup |
[demangle] | Itanium C++ and Rust symbol demangling for diagnostics |
[hints] | Suggestions for undefined symbols: missing -l, versions, near misses |
[plugin] | LTO plugin host (feature plugin) |
Format backends own their own symbol precedence and layout rules. The shared modules must not depend on a backend.
Only args, diag, error and target are documented; the
other modules are public for qld’s own tests and tools, and are not
covered by semantic versioning.
Re-exports§
pub use args::CancelToken;pub use args::InputAttrs;pub use args::InputKind;pub use args::InputSpec;pub use args::LinkOptions;pub use args::OutputBuffer;pub use args::OutputKind;pub use args::ParseOutcome;pub use args::TextOutput;pub use args::parse_gnu;pub use args::parse_gnu_with;pub use diag::Diagnostic;pub use diag::DiagnosticSink;pub use diag::Severity;pub use error::Error;pub use error::Result;pub use target::Architecture;pub use target::BinaryFormat;pub use target::Endianness;pub use target::OperatingSystem;pub use target::PointerWidth;pub use target::Target;
Modules§
- args
- Command-line option model and the argv front ends that fill it in.
- diag
- Diagnostics: warnings, errors and notes reported during a link.
- error
- Fatal error type.
- target
- Target description: the format, architecture and ABI being linked for.
Structs§
- Memory
Files - An
InputProviderholding files in memory, keyed by path. - Script
Error - A fatal problem in a linker script, with the position it was found at.
Constants§
- PROGRAM_
NAME - Program name used to prefix diagnostics.
Traits§
- Input
Provider - Answers for paths before the file system does; see the module documentation.
Functions§
- link
- Runs a link described by
options. - link_
to_ memory - Runs a link described by
optionsand returns the output image instead of writingLinkOptions::output, which then only names the output. - version_
line - Version string, printed by
--versionand-v.