Skip to content

feat: link Windows COFF in-process through prebuilt llvm-ld-coff (reld#96) - #202

Merged
zackees merged 2 commits into
mainfrom
feat/96-llvm-ld-in-process
Sep 19, 2026
Merged

zackees merged 2 commits into
mainfrom
feat/96-llvm-ld-in-process

Conversation

@zackees

@zackees zackees commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Closes #96.

Windows COFF and MinGW links now run in-process through llvm-ld-coff, which is LLD's COFF linker (lld-link/MSVC and MinGW drivers) built as a shared library with a C ABI. It only ever links Windows PE/COFF. Its Linux and macOS builds are Windows cross-linkers.

reld never compiles LLVM

llvm-ld builds and publishes its own prebuilts for eight hosts (zackees/llvm-ld#36, release v0.1.0): Windows x64/arm64, Linux glibc and musl on x64/arm64, and macOS x64/arm64. reld only consumes them:

  • ci/llvm_ld.lock.json pins v0.1.0 per host triple by SHA-256, generated from the release's own SHA256SUMS.
  • ci/fetch_llvm_ld.py downloads, verifies and caches the pinned archive. CI caches it by lock-file hash.
  • Updates are one-sided. Updating llvm-ld is a lock-file change, and updating reld never rebuilds llvm-ld.

How reld uses it

  • Loading (crates/reld-core/src/llvm_ld.rs): the library is loaded at runtime through the already-approved libloading, so there's no new dependency and no host cfg. The C ABI version is checked before any call.
  • Fallback: anything short of a working library — absent, disabled, wrong ABI, busy — is treated as "unavailable", and the link falls back to the lld-link subprocess bridge, which stays the escape hatch (RELD_LLVM_LD=off). An explicit RELD_BRIDGE_LINKER bypasses the in-process path.
  • Scope: both drivers are used — WinLink for reld-link, and MinGW for links that TargetProbe (routing: TargetProbe drives engine selection, plus Engine::MingwLld (reld#123 Phase 3, step 2) #184) identifies as PE-MinGW.
  • Feature flag: llvm-ld is on by default, and clippy is clean with it off too.

Release and CI

  • Release packaging: release.yml bundles the library next to reld in every archive except musl, because a static musl reld can't load a shared library. The native legs then extract the finished archive and run the reld-link inside it with no override, proving the shipped layout is found and used in-process. The Windows smoke asserts the same.
  • Linux CI: phase1-native does an in-process Windows cross-link through libllvm_ld.so.
  • Windows-MSVC CI: phase1-native-run stages llvm_ld.dll next to reld-link.exe before the sqlite e2e and self-host, so all of SQLite and reld itself are linked through llvm-ld-coff in-process. It then runs the e2e and executes the result.
  • ci/llvm_ld_e2e.py requires the in-process output to be byte-identical to the lld-link subprocess's.

Measured locally

These results use the published v0.1.0 library, not a local build:

  • Loads on another distro: libllvm_ld.so depends only on libc/libm because libstdc++ is linked statically, and it loads on NixOS even though it was built on Ubuntu.
  • Byte-identical: in-process output matches the lld-link subprocess exactly, for both the MSVC and MinGW drivers.
  • Errors propagate: an undefined symbol produces LLD's own diagnostic, and reld exits 1.
  • Faster: 8.9 ms vs 56.6 ms per small link, about 6.4× (release build, 40 links). On tiny links that is mostly the per-link process spawn it removes, and process creation costs more on Windows. Large links add llvm-ld's own optimizations on top.
  • Checks: fmt, clippy with the feature on and off, the Dylint boundary check, and the dependency policy are clean. reld-core: 266 tests. bridge-route: 13. Python: 369.

🤖 Generated with Claude Code

zackees and others added 2 commits September 18, 2026 20:22
…d#96)

llvm-ld-coff (zackees/llvm-ld) is LLD's COFF linker, the lld-link/MSVC and
MinGW drivers, built as a shared library with a C ABI. Every build of it links
Windows PE/COFF; the Linux and macOS builds are Windows cross-linkers.

reld now offers every COFF and MinGW link to it in-process before falling back
to spawning lld-link:

- crates/reld-core/src/llvm_ld.rs loads the library at runtime through the
  already-approved libloading (no new dependency, no host cfg), checks the C
  ABI version before any call, and treats anything short of a working library
  as "unavailable", so the subprocess bridge stays the fallback and the escape
  hatch (RELD_LLVM_LD=off). An explicit RELD_BRIDGE_LINKER bypasses it.
- reld never compiles LLVM. ci/llvm_ld.lock.json pins llvm-ld v0.1.0 per host
  triple by SHA-256; ci/fetch_llvm_ld.py downloads, verifies and caches it.
  Updating llvm-ld is a lock-file change; updating reld never rebuilds it.
- release.yml bundles the library next to reld in every archive except musl
  (static musl reld cannot load a shared library) and smokes the packaged
  layout, with no override, to prove reld finds and uses it.
- CI proves the path on Linux (a Windows cross-link) and on Windows MSVC,
  where the sqlite e2e and the self-host link now run in-process.
  ci/llvm_ld_e2e.py requires byte-identical output to the lld-link subprocess.

Measured locally: identical output to lld-link, and 8.9 ms vs 56.6 ms per
small link (about 6.4x), mostly the per-link process spawn it removes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…th /Brepro

A pull_request run of release.yml exists to validate the pipeline, but it
checked out the already-existing v0.1.0 tag, so the new llvm-ld staging step
ran against source lacking ci/fetch_llvm_ld.py. PR runs now build the PR's
commit; manual dispatches still rebuild an existing tag. The llvm-ld pin and
fetch script now also trigger the workflow.

The Windows e2e compared outputs of two links made a second apart; lld-link
stamps the PE header with the link time, so they differed. /Brepro makes the
comparison deterministic.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zackees
zackees merged commit d0ca7a9 into main Sep 19, 2026
39 checks passed
@zackees
zackees deleted the feat/96-llvm-ld-in-process branch September 19, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Phase 3: add reld-owned Rust bindings and route Windows through vendored llvm-ld

1 participant