Skip to content

Meta: road to a working cross-platform link (Windows / Linux / macOS) #2

Open

Description

@zackees

Slice burn-down


Meta issue. Tracks everything between here and "reld links a real program on Windows, Linux, and macOS." Incremental linking is explicitly out of scope for this issue — it is the product, but it is the second problem. Sub-issues to be split out of the checklists below as work starts.

0. Where we actually are

  • crates/reld is 28 lines. --targets prints three strings; everything else exits 2.
  • crates/reld-testkit (~500 lines) is the real asset: seeded C workload generator + bench + stress drivers, all three consumers (bench / stress / differential) designed in from the start.
  • CI, sanitizers, stress, and the benchmark-publishing pipeline are green and wired.
  • The reld column in the published benchmark reads n/a and will keep reading n/a until §2 lands.

So: the scaffolding is ahead of the linker, which is the correct order, and the next commit is the first one that has to write an actual output file.


1. Decisions to lock before writing linker code

These change the schedule by person-years, not days. Each needs an explicit answer recorded in DESIGN.md.

  • D1 — Fork wild's ELF backend, or reimplement? wild is MIT/Apache-2.0 and its core is already format-neutral by design. Forking hands us Linux/ELF at production quality on day one and lets all net-new effort go to PE/COFF and Mach-O — the two formats nobody has solved openly. Reimplementing buys independence and understanding we will need anyway when incremental lands. This is the single highest-leverage decision in the project. Recommendation: fork, and stay rebaseable against upstream for as long as that is cheap.
  • D2 — Driver surface. Three incompatible CLIs: GNU ld/lld (Linux), MSVC link.exe (Windows), ld64 (macOS). Toolchains reach us via -fuse-ld=/-Clinker-flavor, so we need argv[0] dispatch the way lld does (ld.reld, reld-link, ld64.reld). Decide the multi-call layout now; retrofitting it is miserable.
  • D3 — Target matrix for v0. Proposal: x86_64-unknown-linux-gnu, x86_64-pc-windows-msvc, aarch64-apple-darwin. Note macOS forces us to arm64 first, not x86_64 — Apple Silicon is the machine that matters and it changes which relocation code gets written first.
  • D4 — Input parsing. object crate for correctness-first bring-up vs. hand-rolled zero-copy mmap readers (what wild does, for speed). Possible answer: object behind our own trait for v0, swap later — but only if the trait is drawn so the swap is real.
  • D5 — PDB, and whether the Windows story is credible without it. A dev-loop linker whose output cannot be debugged is not a dev-loop linker. Writing PDB is a large subproject on its own (pdb/pdb2 crates are read-oriented). Options: (a) write PDB, (b) emit DWARF into PE and support only LLDB, (c) ship v0 with no debug info and a loud warning. This is the most likely thing to quietly sink the Windows target and needs an answer before M2 starts, not during.
  • D6 — Ad-hoc code signing on Apple Silicon is mandatory, not optional polish — unsigned arm64 Mach-O binaries do not execute. Confirm whether we generate the LC_CODE_SIGNATURE blob ourselves or shell out to codesign for v0.

2. Milestones — "it works everywhere"

Sequenced deliberately: ELF first (best-documented, best reference implementations, and D1 may hand it to us), then PE, then Mach-O.

M1 — Linux / ELF / x86_64

  • Link a static non-PIE hello.o from cc -c into a binary that runs and exits 0
  • Archive (.a) member semantics: lazy pull, --start-group/--end-group, --whole-archive
  • PIE + -pie/-no-pie, GOT/PLT construction, R_X86_64_* relocation coverage
  • Dynamic linking against system libc: DT_NEEDED, symbol versioning, .dynsym/.dynstr/.hash/.gnu.hash
  • TLS (initial-exec + global-dynamic at minimum; TLSDESC noted as a gap if punted)
  • .eh_frame / .eh_frame_hdr — C++ exceptions and Rust panics both die without this
  • Common flags accepted or explicitly rejected with a real message: -L -l -o -rpath -soname --gc-sections -z ... --as-needed
  • Linker scripts: at minimum detect, and fail loudly rather than silently mislink
  • Gate: cargo build of a nontrivial crate with -Clink-arg=-fuse-ld=reld, and the binary runs

M2 — Windows / PE-COFF / x86_64

  • Link cl.exe/clang-cl objects into a running .exe
  • Import libraries + __imp_ thunks, IAT construction, delay-load left as an explicit gap
  • COMDAT selection semantics (IMAGE_COMDAT_SELECT_*) — the classic silent-wrong-answer generator
  • Base relocations + ASLR, .pdata/.xdata unwind tables (SEH is not optional on x64)
  • Subsystem/entry-point selection, /SUBSYSTEM, /ENTRY, DLL output + export tables + .def
  • TLS via _tls_used / .tls directory
  • link.exe-compatible flag surface for the subset MSVC and rustc actually emit
  • Resolve D5 and implement whatever it says
  • Gate: a Rust binary linked by reld runs, and a breakpoint hits in the chosen debugger (or the no-debug-info limitation is documented in the README, not just the issue tracker)

M3 — macOS / Mach-O / arm64

  • Load commands, __TEXT/__DATA_CONST/__LINKEDIT segment layout
  • arm64 relocations, stubs, __got, branch islands for large images
  • Chained fixups (LC_DYLD_CHAINED_FIXUPS) — the modern format; classic rebase/bind opcodes are legacy and may be skippable
  • LC_BUILD_VERSION / -platform_version, SDK + deployment target plumbing
  • .tbd stub dylibs — linking against the shared cache means never touching a real libSystem.dylib
  • Ad-hoc code signature (D6)
  • Objective-C section semantics only if a target workload needs it; otherwise record as a scoped gap
  • Gate: a Rust binary linked by reld runs on a clean Apple Silicon machine with Gatekeeper in its default state

M4 — Cross-cutting core (concurrent with M1–M3, not after)

  • Symbol resolution engine: weak/strong, common symbols, duplicate diagnosis, archive-order sensitivity
  • Section GC (--gc-sections) and string/constant merging — format-neutral per DESIGN §4.1
  • Error taxonomy. Undefined-symbol messages that name the referencing object and demangle the symbol are cheap to build, and are the single most visible daily quality difference between linkers. Do this early; it also makes every other milestone easier to debug.
  • Never-hang / never-OOM / never-silently-miscompile on malformed input

3. Testing — what has to exist for any of the above to be believable

The generator already exists and already anticipates this. What's missing is the oracle.

  • T1 — Differential execution testing (primary oracle). Same objects → reld and → reference linker; run both binaries, compare exit code and stdout. Deliberately not a byte comparison — reproducible output is an explicit non-goal, so a byte-diff oracle would be wrong as well as noisy. This turns the existing seeded stress harness from a crash-finder into a correctness-finder, which is a much bigger upgrade than its cost.
  • T2 — Self-host / bootstrap. Link reld with reld. Strongest single correctness signal available, and it costs one CI job. Add as a gate the moment M1 passes.
  • T3 — Real-world corpus. A pinned list of C/C++/Rust projects linked by reld in CI, published as a pass-rate percentage on the benchmark branch. Same honesty policy as §6 of DESIGN: a regressing number is still published. A link-success table is more persuasive at this stage than any speed chart, and we can publish it long before the speed column has content.
  • T4 — Per-format conformance suites. Targeted objects that isolate one feature each (weak symbol, COMDAT, TLS model, unwind table), so a failure names the feature rather than the program.
  • T5 — Malformed-input fuzzing. Truncated/corrupt objects and archives. Requirement is a clean error, not a panic and not a wrong binary.
  • T6 — Runner matrix. Confirm the three GitHub-hosted runners cover us, including arm64 macOS; flag anything needing self-hosted hardware early.
  • T7 — Sanitizer/stress coverage extended to the real linker as it lands, rather than staying pointed at the placeholder.
  • T8 — --verify mode. Re-link from scratch and compare symbol addresses against the fast path. Currently redundant; becomes the safety net that makes incremental's "fall back when uncertain" rule (DESIGN §4.2) enforceable rather than aspirational. Cheap to add now, expensive to retrofit.

4. Known feature gaps to record, not necessarily to fix

Worth writing down so they are scoped decisions rather than later surprises: LTO (non-goal, but rustc passes -flto and we must reject it comprehensibly), linker scripts, --build-id, incremental (deferred by design), delay-load imports, Objective-C/Swift metadata, symbol versioning depth on ELF, /DEBUG:FASTLINK, universal/fat Mach-O binaries, static PIE, and 32-bit anything.


5. Suggested first slice

  1. Answer D1 — everything downstream depends on it.
  2. Answer D2 and land multi-call argv[0] dispatch (small, unblocks all toolchain integration testing).
  3. Land T1 against a reference linker while reld still links nothing. The harness proves itself against a known-good linker before it has to judge ours — and it starts producing signal on the first day M1 emits bytes.
  4. Then M1.

Ordering note: 3 before 4 is the part that is easy to skip and expensive to skip.

Activity

  1. added
    enhancement
    on Aug 1, 2026
  2. zackees commented on Aug 1, 2026

    @zackees
    CollaboratorAuthor

    Deep dive complete — plan filed, phases broken out

    Full execution-ready plan in #3 (docs/plan/, 10 documents), grounded in file-level analysis of wild, mold and radlink plus a survey of incremental-linking prior art.

    Phase issues

    #4 P0 — Fork wild: vendor, license, rename, open the COFF dispatch point
    #5 P1 — Acceptance harness (ships before P3)
    #6 P2 — Prove Linux: self-host, corpus pass rate, benchmark column
    #7 P3 — PE/COFF, MinGW ABI (largest phase)
    #8 P4 — Mach-O arm64
    #9 P5 — MSVC ABI + the PDB decision
    #10 DECISION — two contradictions in DESIGN.md
    #11 I0–I7 — Incremental linking

    What changed from the original meta issue

    D1 answered: fork wild. But the framing shifts — wild's Mach-O backend is a skeleton with 40 todo!()s, arm64-only, feature-gated off. We inherit production ELF, the GNU arg parser, and a differential test methodology. We do not inherit a working Mach-O, and Windows is greenfield.

    D3 answered: windows-gnu first. DWARF needs only section concatenation plus SECREL/SECTION relocations; MSVC needs PDB, which is ~20k lines in radlink — larger than its entire linking core.

    New, and the first real surgery in P3: wild's core speaks an ELF relocation vocabulary threaded through platform.rs and layout.rs. It must be generalized, not forked — forking the abstraction is the mistake that cost LLD 36,441 lines in 2021.

    Testing is better specified than I originally proposed. wild's oracle uses each input object's relocation list as ground truth, locates the output bytes via a .layout sidecar, infers which relaxation was applied, reverses the arithmetic, and compares recovered symbol-level targets. Plus two things I'd underweighted: mutation-injection to prove the oracle works at all, and mold's skip-list ratchet that fails CI when a skipped external test starts passing.

    The two findings that most change the incremental plan

    1. The daemon is a precondition, not an optimization. HP-UX measured a 118 MB binary: 2 objects changed → 11.3s, 30 objects changed → 16.7s. Changing 15× more cost 48% more, because reloading state dominates. gold's null relink on Chrome was ~30s. DESIGN.md's millisecond target is unachievable with on-disk state — and this is the one place reld genuinely diverges from wild, which plans no daemon.

    2. wild was named for incremental linking, published a design in Nov 2024, and still hasn't implemented it as of 0.9.0 — because the base linker consumed the time and once it was fast the incentive decayed. That is the failure mode most likely to happen to us, and it argues for shipping I2 (daemon + warm full link, zero patching) as a standalone win rather than treating incremental as one big milestone.

    Also: .eh_frame_hdr / .pdata / __unwind_info are global address-sorted tables that cannot be padded or indirected around. That is what killed gold's C++ support, and it is identical on all three of our formats.

  3. zackees commented on Aug 1, 2026

    @zackees
    CollaboratorAuthor

    Correction: LTO is a deferred stretch goal, not a non-goal.

    My earlier comment on this issue listed LTO as a non-goal — that was wrong, and it was wrong in DESIGN.md and README.md too. Corrected in d3706df and recorded as D13.

    LTO is sequenced after the fast linker on all three platforms: the inner loop is the priority, and LTO interacts with symbol resolution, archive extraction, layout and debug info, so pulling it forward would slow down the thing the project exists to deliver.

    Consequences now written into the plan:

    • Do not delete wild's inherited linker-plugin LTO (~1467 LOC, works with known issues on ELF). P2 pins current behaviour rather than removing it — the starting position is "partially works," not "absent."
    • Until implemented per format, LTO flags get a specific diagnostic naming the feature, never a silent mislink. This matters because build systems pass them unconditionally: rustc passes -plugin on the MinGW gcc path, MSBuild passes /LTCG.
    • /GL objects must hard-error — they contain IL, not machine code, and are not linkable at all without LTO.
    • When LTO lands it will be incompatible with the incremental path (gold and MSVC both fall back), so that fallback trigger is permanent.
  4. zackees commented on Aug 2, 2026

    @zackees
    CollaboratorAuthor

    Adversarial review complete — plan restructured

    Six reviewers attacked the plan from different angles. Findings in REVIEW-01.md and REVIEW-02.md (R1–R44). The plan did not survive unamended.

    Two decisions refuted by evidence

    D10 — "reject auto-import" is false. Measured on the local MSYS2 UCRT64 toolchain: a six-line C++ program with std::string and exceptions fails to link with --disable-auto-import --disable-runtime-pseudo-reloc, because libstdc++-6.dll data exports are referenced from constant initializers and MinGW headers don't mark them dllimport. Auto-import + pseudo-reloc v2 are now required.

    D3 — gnu-first was wrong. It priced only the debug-info axis and priced MinGW compatibility at zero. Corrected, gnu additionally needs auto-import, ~25 linker-script-provided symbols the CRT references, .rsrc on every link, .CRT$X* and .ctors, COMDAT-grouped DWARF, and long-form .idata$N import libs — all where radlink gives zero help. Now msvc first, carrying the shared COFF core.

    The finding that changed the product plan

    I had scheduled I2 (daemon + warm full link) as "the first shippable win." Published lld phase data: input parsing 5.04%, string merging 66.54%. Caching parsed inputs skips the 5% and repeats the 66% — corroborated by wild's own benchmark page ("link time here is dominated by how quickly we can deduplicate strings").

    Worse, string merging is also a soundness hole: the I1 fingerprint is structurally blind to SHF_MERGE offset shifts.

    D16 now gates the whole incremental workstream on IX-T0: measure first. If parsing is ~5% on our workloads, the parse-caching daemon is not built at all.

    Other criticals

    • The test oracle reports green on formats it never examined — header_diff.rs falls through _ => {} for non-ELF. COFF appears zero times in 10,195 lines. Even on ELF, coverage is ~50–70% of relocations. D17 adds a coverage floor and one malfunction site per format.
    • The plan was unaware of wild's fourth backend. "wasm" appeared zero times in ten documents; it's ~6,650 LOC and 2 CI jobs. D14: deleted in P0.
    • IMAGE_SCN_LNK_NRELOC_OVFL → silent mislink. Measured: plain gcc -c emits it; reading NumberOfRelocations literally applies 65,535 of 70,001 relocations.
    • macOS was missing __unwind_info construction entirely — plus kernel-enforced MH_PIE, hard __PAGEZERO, MH_DYLDLINK (static arm64 executables don't run), and LC_MAIN.
    • P0's acceptance was unachievable three ways, and every P0–P2 command is unrunnable on the Windows dev host. Added P0-T0: a Linux dev container.
    • -fuse-ld= doesn't work with MinGW gcc (measured) — three phase docs relied on it.

    One correction in the plan's favour: I overstated P3-T1. wild already reuses the ELF relocation vocabulary across Mach-O and Wasm unchanged — 1–3 days, not the most invasive change in the phase.

    Sequencing now

    P0 ─► P1 ─► P2 ─► IX (ELF, scope from measurement) ─► P3 win-msvc ─► P4 macOS ─► P5 win-gnu
    

    D15 moves incremental ahead of P4/P5. Rationale: DESIGN.md's own ~1.5–2 person-years-per-format estimate meant the product feature didn't start for 3–4 person-years — which is precisely how wild, named for incremental linking, still hasn't reached it in two years.

  5. zackees commented on Aug 2, 2026

    @zackees
    CollaboratorAuthor

    [meta #2] child #4 -> CLOSED (validated by PR #12: all 13 CI checks green; Linux container 417 passed, 0 failed, 1180 expected skips; post-merge compile/license/driver/COFF/Wasm/upstream-diff gates green).

  6. zackees commented on Aug 2, 2026

    @zackees
    CollaboratorAuthor

    [meta #2] child #5 -> CLOSED (validated by PR #15 / merge 7351cb8: all 14 CI, sanitizer, and stress checks green; Linux acceptance 230 passed / 595 architecture-disabled at 71% relocation coverage; differential 100/100 seeds; mold exact 407 native trials with 406 passed + 1 environment-ignore; post-merge summary/policy/reld-diff checks green).

  7. zackees commented on Aug 7, 2026

    @zackees
    CollaboratorAuthor

    🤝 Handoff — session summary & continuation guide

    reld went from "prints three strings and exits 2" to a linker that runs on Windows, Linux, and macOS, self-hosts, and posts competitive numbers on the published benchmark graph. The founding claim ("runs and targets everywhere" + "benchmarks auto-generated and published") is real and CI-proven.

    Strategy pivot that made this fast

    Rather than write native COFF/Mach-O backends first (person-years, #7/#8), reld became a polylinker / bridge: Linux links natively (inherited wild ELF core); Windows/macOS link by delegating to lld (the rust-lld in every toolchain) — COFF→lld-link, Mach-O→ld64.lld. This lit up all three platforms + the benchmark now, with native codegen as later work.

    Landed this session (all merged to main, CI-green)

    PR What
    #20 BR-1 Windows COFF bridge → lld-link (raw-argv pass-through, -flavor dedup, exit-code propagation)
    #22 BR-2 Windows CI proof — links a 16-file/4-dep rusqlite(bundled, C) program with reld
    #31 BR-3 macOS Mach-O bridge → ld64.lld (-Clinker-flavor=ld64.lld), macos-arm64 e2e
    #24 BR-4a reld participates in the benchmark (discovers the ld.reld driver shim)
    #26 BR-4b benchmark JSON schema v2 (target per history line, per-series mode)
    #28 BR-4c cross-platform bench smoke on windows-msvc + macos CI legs
    #33 Polylinker docs — reframed README/DESIGN, amended D13 (LTO delegated, not rejected), new agents/docs/polylinker.md (shipped-vs-designed table)
    #35 B8a polylinker router foundation — Engine registry + RELD_ENGINE/--engine= override + routing-reason log
    #39 Benchmark ON — fixed the reld n/a (a time_link output-path bug, NOT a reld bug) + surfaced link failures. reld now charts real numbers on the Linux graph.
    #41 Windows self-host — link reld with reld-link (CI gate)
    #44 (in flight) macOS self-host — link reld with reld via ld64.lld

    Design issues filed (not implemented): #19 (linker daemon / running-process broker v2, blocked on IX-T0 per D16), #30 (polylinker flag-router — B8 implementation).

    Verified current state

    • reld links + runs the rusqlite/C-linking e2e on Linux (native), Windows (COFF bridge), macOS (Mach-O bridge) — all in CI.
    • Published benchmark (benchmark-stats branch): reld charts native Linux numbers, competitive — e.g. large(512): reld 0.0445s vs wild 0.0523 / lld 0.091 / mold 0.118 / bfd 0.200.
    • Self-host proven on Windows (CI), macOS pending test(ci): self-host — link reld with reld via ld64.lld on macos-arm64 (#43) #44.

    Remaining work (rough priority)

    1. 3-OS benchmark publish matrix — publish per-OS graphs (competitors on Win/mac; reld Linux-only until Meta: road to a working cross-platform link (Windows / Linux / macOS) #2 below). Publish step is guarded to the default branch, so workflow_dispatch on a branch validates without publishing.
    2. Windows/macOS rustc-based reld measurement — clang can't drive reld off-Linux (reld links there via rustc -Clinker), so a rustc/warm-relink bench is needed for reld numbers on Win/mac. (Note: on those platforms reld ≈ lld + bridge overhead.)
    3. B8 flag-router (Polylinker: flag-aware router over bundled linkers (LTO/optimized via routing + fallbacks) — design + docs #30) — LTO/-flto → route to a capable engine on Linux (native lacks LTO). Builds on B8a's registry.
    4. Linker daemon (Linker daemon: thin reld-link client + broker-versioned daemon holding the object graph (running-process broker v2, zccache-embedded instrumentation) #19) — gated by D16/IX-T0: measure per-phase timing FIRST; do not build the daemon on assumption.
    5. Native COFF/Mach-O codegen (P3: PE/COFF backend, MinGW (windows-gnu) ABI #7/P4: Mach-O backend, aarch64-apple-darwin #8); ELF burn-down (Track and remove inherited reld-diff ignore patterns #13/Burn down the native mold-suite skip list #14/test(linux): add scheduled >2 GiB ELF output scale gate #16).

    Key gotchas for the next agent

    • Toolchain: all cargo/rustc locally go through soldr (a hook rejects bare invocations); CI uses bare cargo. soldr builds under target/<triple>/debug/; CI's bare cargo uses target/debug/.
    • Dev box is Windows — macOS/Mach-O work is CI-verified only (macos-arm64 runner). Combine proven patterns and let CI judge.
    • The ELF/native path is the inherited wild core — untouched by the bridge. Bridge lives in crates/reld-core/src/bridge.rs, routed from crates/reld/src/main.rs (Args::bridge_target()), format-aware via BridgeTarget{Coff,MachO}.
    • Dispatch-verify benchmark/workflow changes before merging — a code review can't catch a runner-only bug (that's how the reld n/a output-path bug was found).
    • Honesty policy: never chart a failing linker as a silent n/a; keep shipped vs designed explicit in docs (the polylinker router is designed, not implemented).
    • e2e fixture: ci/e2e/sqlite-bridge/ (own workspace, root-excluded) is the 16-file/4-dep rusqlite regression used as the standard link gate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions