Skip to content

perf(elf): make OutputSectionPartMap sparse and add pinned Clang link replay #101

Closed

Description

@zackees

Context

The current Linux benchmark’s captured final link is sub-second (roughly 0.22–0.30 s for reld in current hosted results) and therefore too short for stable CPU profiling. Its active runner also checks native execution but does not yet make raw artifact identity a generic gate for published performance claims, contrary to DESIGN.md §3.1 and agents/platforms/linux.md.

A controlled native ELF reproducer was profiled at main commit 6ec92be6674d026e74f7524271fbcbce68b50a39. It contains one object with 71,604 custom allocated sections and links via:

reld --no-pie -e _start --no-gc-sections --no-fork -o OUTPUT corpus-alloc.o

Ten link-only, hook-free samples had a 0.290 s median (0.293 s mean) and 334,818 KiB median peak RSS. Two self-runs and every timed output had the same SHA-256; all native outputs exited 42 with empty stdout/stderr. The instrumented phase trace reported 284.11 ms total, including:

  • Layout: 164.54 ms;
  • Compute total sizes: 34.70 ms;
  • Compute start offsets: 23.60 ms;
  • Assign IDs: 21.71 ms;
  • Split buffers: 42.60 ms;
  • Write data: 71.07 ms.

That makes dense custom-section bookkeeping the highest directly observed native-core target in this workload. Reld’s OutputSectionPartMap is still byte-identical to Wild’s older dense implementation: it allocates every discovered custom section × alignment up front.

Upstream Wild has already landed the relevant design in wild#2437 / beaf40d, followed by the sparse-offset clone reduction in 3354096. This is the measured follow-up noted, but not implemented, in closed #82.

For a real-world long-form workload, LLVM/Clang is an established C++ linker corpus used by lld, mold, and Wild. The chosen source is llvmorg-22.1.8 annotated tag e013073558445169e8732e25fa86e9913bfdd24e, peeled commit ca7933e47d3a3451d81e72ac174dcb5aa28b59d1, configured as RelWithDebInfo, clang project, X86 target, assertions off, no LTO. Compile it once and capture only Clang’s final link argv plus its complete input closure. Compilation is setup, never timing.

Proposal

  1. Port Wild’s dense-prefix + lazy BTreeMap<PartId, T> representation and the follow-up merge_and_return_start_offsets optimization into crates/reld-core, adapting current reld callers rather than mechanically cherry-picking.
  2. Add focused custom-section unit and ELF acceptance coverage before the port, including an empty custom section and a relocatable-to-final-native chain.
  3. Add a Linux-only, immutable LLVM/Clang final-link corpus mechanism. It must fetch a GitHub Release asset with a checked-in lock/manifest containing the source tag/object/peeled commit, builder image/toolchain package provenance, exact captured argument vector and response files, closure hashes, archive SHA-256, expected native-oracle stdout/stderr, and explicit output policy.
  4. Add a separate Linux replay/profile workflow. It runs one warmup followed by a fixed calibrated count of identical final-link replays that targets approximately 30 seconds total of link-only work; it does not extend the existing five-linker × three-LTO public matrix. It records calibration and sample data without mixing compile time or native-oracle time into link timing.
  5. Add generic benchmark artifact validation: two baseline and two candidate links, raw bytes/hash equality, first differing offset retained on failure, and native exact exit/stdout/stderr after each link.

Acceptance criteria

  • Commit RED evidence before the port: map tests demonstrate lazy custom-part storage; an ELF acceptance fixture exercises multiple custom sections under -r, then a final executable with exact native output.
  • Port only standard-library data structures; Cargo.toml, Cargo.lock, and the dependency baseline remain unchanged.
  • Preserve deterministic PartId iteration/order, built-in dense-range behavior, empty-custom-section layout records, relocation/symbol behavior, and all existing affected callers.
  • Build a controlled pinned pre-change baseline and candidate with the same linker-version string, so the linker’s own .comment provenance does not make an implementation-only comparison spuriously differ. Then require raw byte identity—not post-hoc field normalization—across two self-runs per side and between sides. On any mismatch retain both files and first differing offset.
  • Run the Linux native oracle after every identity and timed link with exact expected exit status, stdout, and stderr.
  • Adapt all shared reld-core callers and run the Linux, Windows, and macOS platform-required correctness layers; document any platform validation-command changes in the respective guide.
  • Publish a pinned LLVM/Clang corpus lock and a Linux-only replay path that compiles once, captures only the final link, verifies every input and the archive SHA-256 before replay, and rejects a floating branch/cache/toolchain/reference linker.
  • Replay a fixed same-argv Clang link for approximately 30 seconds of total timed link work after one untimed warmup. Store calibration, individual samples, and timing provenance; timing contains no compilation, unpacking, native oracle, or profiler overhead.
  • The replay harness enforces raw identity and exact native behavior before reporting any performance result. Reference-linker versions and toolchain/image revisions are pinned and recorded.
  • Show a material end-to-end improvement on the many-custom-section reproducer and report phase plus peak-RSS deltas. Retain the Clang-corpus result as a representative regression/performance gate; do not claim an improvement unless the artifact gate is green.
  • Include focused RED→GREEN results, reld-core tests, relevant acceptance tests, artifact evidence, profile/phase evidence, and benchmark samples in the PR.

Decisions

  • Target the sparse map first. It is the largest directly measured native Layout cost on a controlled custom-section workload and has narrow, dependency-free upstream prior art.
  • Use LLVM/Clang for the real corpus. It is a commonly published linker benchmark, is a directly runnable C++ executable, and avoids Chromium’s much larger checkout/build burden.
  • Target 30 seconds per profiling interval, not necessarily per individual link. The immutable captured final link must stay fixed; repeated identical links give a stable profile interval without turning the current benchmark matrix into multi-terabyte I/O.
  • Keep the long replay Linux-only and separate. Shared reld-core correctness remains all-platform, but the corpus and profile collection are Linux ELF concerns.
  • No artifact normalization for this implementation-only change. The harness controls the embedded linker-version string at build time so raw-byte identity remains the oracle.

Related issues

Activity

  1. zackees commented on Aug 31, 2026

    @zackees
    CollaboratorAuthor

    Corpus integration evidence:

    • Source remains pinned to annotated tag llvmorg-22.1.8 (e013073558445169e8732e25fa86e9913bfdd24e), peeled commit ca7933e47d3a3451d81e72ac174dcb5aa28b59d1, RelWithDebInfo, X86, assertions/LTO/tests/examples off.
    • The complete captured closure was 14.8 GB and native reld peaked at 19,306,060 KiB RSS, exceeding the standard hosted runner envelope (16 GB RAM / 14 GB SSD) and the 2 GiB per-release-asset limit.
    • The frozen copy is therefore explicitly a non-debug corpus: GNU binutils 2.40 strip --strip-debug was applied only to copied .o/.a inputs. Complete pre/post manifests are attached to the release and locked by SHA-256. This corpus must not support debug-heavy performance claims.
    • Published release: https://github.com/zackees/reld/releases/tag/clang-link-corpus-llvmorg-22.1.8-v1
    • Archive: 73,413,916 bytes, SHA-256 beb1f73eaab4257572ff60d04f08391b605990e4377c5d137fbf254db8ad5440; extracted closure: 332,082,368 bytes; measured peak RSS: 543,804 KiB.
    • True pinned baseline/candidate URL replay passed: 204 fixed --no-fork link-only samples totaled 31.675 s after one excluded calibration link; all two baseline + two candidate artifacts were byte-identical at SHA-256 3a2654c7294db5865f387d1dd2df465b94433d957ce89a2de28161bc353ff9e5; exact native Clang oracle passed after every link.
    • The many-custom-section A/B gate also passed raw identity. Ten balanced samples improved median wall time 0.320→0.190 s and mean peak RSS 334,336→101,704 KiB. Phase trace: total 305.18→181.75 ms, Layout 172.95→108.81 ms, total-size computation 34.71→8.64 ms, group offsets 23.53→3.78 ms, and buffer split 44.70→4.07 ms.
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions