Repository navigation
Add optional mold linker support - #861
Merged
Merged
Conversation
helly25
requested review from
dzbarsky,
fmeum,
jsharpe and
rrbutani
as code owners
September 20, 2026 15:50
helly25
force-pushed
the
mold-linker
branch
2 times, most recently
from
September 23, 2026 21:08
15e80be to
ef091db
Compare
helly25
added a commit
that referenced
this pull request
Sep 24, 2026
The `lld` selection added in #860 does not represent an arbitrary LLD implementation: it selects the linker included in the chosen LLVM distribution. Remove that reserved name before the API ships in 1.10.0.\n\nAn omitted linker attribute or an explicit empty selection (`linker = {"": ""}`) now selects the LLVM-distribution linker. This avoids introducing another reserved linker name and leaves non-empty implementation names available for generic catalogue lookup in #861. Both Bzlmod and WORKSPACE integration fixtures exercise the explicit empty spelling.\n\n`auto` and absolute-path selection are unchanged.\n\nChecks:\n- `bazel test //toolchain/internal:all`\n- Bzlmod and WORKSPACE queries for `@llvm_toolchain_cxx20//:*`\n- Trunk checks on changed files
helly25
force-pushed
the
mold-linker
branch
from
September 24, 2026 00:26
58bc47c to
ee71b83
Compare
helly25
force-pushed
the
mold-linker
branch
from
September 24, 2026 06:54
18c8437 to
4b7d75c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add generic, versioned linker-distribution resolution and use it to provide mold as an explicit, optional linker on top of #860 and #866.
The
linkertarget map remains the only linker selector:autodiscovers the native execution-platform linker;linker_versionand its per-target formlinker_versionsselect the catalogue version with the same exact/first/latestrequirement syntax as LLVM versions. There is no hardcodedlld/moldimplementation whitelist inrules.bzlorconfigure.bzl; for example, cataloguedlldis handled exactly like any other name rather than meaning âuse the LLVM-distribution linker.âOptional mold-module integration
Mold is the first linker represented in the catalogue, but it is fully opt-in and toolchains_llvm does not depend on the mold module.
Users can select a version explicitly:
Alternatively, Bzlmod users may inject their own mold dependency:
Bare
moldis the only mold-specific behavior: the resolver readsproject(mold VERSION ...)from the injected module's upstreamCMakeLists.txtand uses that as the default version. This keeps the version in a normalbazel_dep, where Dependabot/Renovate can update it. An explicit version does not require the mold module.There are no
mold_versionormold_binaryattributes.Distribution model
toolchain/distributions/linkers.jsoncrecords URLs, SHA-256 digests, archive prefixes, and executable paths by linker name, version, and execution OS/architecture. The target selects a linker name/version while the execution platform selects the artifact, because the linker runs on the build executor during cross-compilation.The initial catalogue contains official Linux x86-64 and AArch64 mold artifacts for the BCR version (2.40.4) and the three newest stable releases (2.41.0, 2.42.0, and 2.42.1). Downloaded executables are materialized into the generated toolchain repository and declared as linker inputs for sandboxed and remote actions.
The updater is now Python-backed and refreshes both LLVM distributions and the linker catalogue. It preserves JSONC output, reads the current BCR mold version, adds the newest mold releases, requires GitHub-provided SHA-256 digests, updates generated LLVM goldens, and is deterministic across repeated runs. It deliberately never substitutes predictable asset names for checksum verification.
Tests
bazel test //...gold@1.2.3referencelinker_version = "latest:<3.0.0"trunk checkgit diff --checkLinux x86-64 end-to-end mold CI runs in both Bzlmod and WORKSPACE modes.