Skip to content

Link Linux builds with mold; line tables only for debug builds - #749

Open
xbmc4lyfe wants to merge 2 commits into
mainfrom
linux-mold-linker
Open

xbmc4lyfe wants to merge 2 commits into
mainfrom
linux-mold-linker

Conversation

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator

What

  • Linux builds (x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu) link with mold through scripts/link-mold.sh, set as the Cargo linker in a new root .cargo/config.toml.
    • It goes through linker, not rustflags, because an environment RUSTFLAGS (AGENTS.md's -D warnings, just build's -C target-cpu tiers) replaces config rustflags and would silently drop the choice.
    • -fuse-ld=mold comes last, so it overrides the -fuse-ld=lld rustc passes on x86_64.
    • If mold is missing, the link stops with an install hint and never falls back to another linker. This was checked in a rust:1.100.0 container with no mold: error: linking with /src/scripts/link-mold.sh failed ... RustyGet links Linux builds with mold, which is not installed.
    • macOS keeps Apple's linker, and musl/Alpine (docker) is untouched.
  • [profile.dev] debug = "line-tables-only" (the test profile inherits it). Panics, backtraces and gdb bt keep function and file:line; variable debug info is dropped. No test reads symbolic backtraces. CARGO_PROFILE_DEV_DEBUG=true brings full debug info back for a debugger session.
  • Docs: mold is in the install requirements and apt line (site/content/install.md) and in the build-deb.sh needs list. .gitignore now keeps /.cargo/.
  • Open item: .github/workflows/build.yml and nativeness.yml must add mold to their apt installs in their apt installs. The push token lacks the workflow scope, and Actions is unavailable anyway, so that edit is left for an owner with that scope.

Benchmark LB-1 (warm sccache, 32 jobs, median of 3, every sample kept)

Hosts: rustyget-x86-b and rustyget-arm-b (Ubuntu 24.04, Rust 1.100.0, mold 2.30.0, lld 18.1.3). Steps:

  • tests: clean cargo build --tests, RUSTFLAGS="-D warnings"
  • incr: append a comment to rust/src/crc.rs, then rebuild
  • rel: clean cargo build --release --bin rustyget (fat LTO, x86 target-cpu=x86-64-v3)
step arch before (default) lld 18 mold mold + line-tables-only
tests x86_64 40.0 s (rust-lld 23) 38.9 42.2 33.5
incr x86_64 41.5 39.0 39.0 37.0
rel x86_64 87.0 93.9 89.8 n/a
tests arm64 64.3 s (GNU ld) 58.2 55.5 51.0
incr arm64 62.0 56.7 55.6 47.2
rel arm64 93.8 93.5 96.0 n/a

What the numbers show:

  • Since Rust 1.90, x86_64 Linux already links with the bundled rust-lld. There mold matches it within noise, and the gain comes from line tables.
  • arm64 used GNU ld, and mold cuts about 9 s from the clean test build.
  • The release (LTO) time doesn't change.
  • split-debuginfo=unpacked gave nothing (x86 40.2, arm 59.8).
  • The relink takes as long as the clean build. Most of the remaining time is rustc compiling the rustyget lib-test and integration-test units that sccache can't cache, not linking.

Evidence: ~/rustyget-requests/linkbench/ (bench.sh, samples.csv and logs per host, meta.txt).

Validation

Linux (rg-farm, GitHub Actions unavailable):
(running on head d9b04ed; lines added when done)

macOS (m5air, platform config touched): (running on head d9b04ed)

Release deb (rg-farm, rustyget-x86-g, from deploy-6790 + this head): sha256 ce4df842149c433cceebc15245bdc49b6d4c2672f07ea8a9e593e0da7e375ec1.

  • Both tier binaries carry mold 2.30.0 in .comment.
  • Size is 24 MB, the same as the earlier LTO debs.
  • Depends: libc6 (>= 2.39), libssl3t64, so it installs on Ubuntu 24.04 and 26.04.

Farm hosts: I installed mold on rustyget-arm-b, avx2-4 and x86-b..h, and asked the fleet session to add it to provisioning.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM

xbmc4lyfe and others added 2 commits November 26, 2026 20:17
Linux x86_64 and aarch64 builds now link through scripts/link-mold.sh. It is
set as the Cargo linker in .cargo/config.toml, so an environment RUSTFLAGS
(-D warnings, the target-cpu tiers) can't drop it. A build host without mold
stops with an install hint instead of silently falling back to another linker.
Debug and test builds use debug = "line-tables-only": panics and backtraces keep
file:line, and the full variable debug info is dropped.

Benchmark LB-1 (warm sccache, 32 jobs, median of 3): on arm64 the clean test
build went from 64.3 s to 55.5 s with mold and to 51.0 s with line tables, and
the relink from 62.0 s to 47.2 s. x86_64 already linked with rust-lld, so mold
alone changes nothing there (40.0 s vs 42.2 s, within noise); line tables
bring it to 33.5 s. The release (LTO) build time is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
-fuse-ld=mold makes the compiler driver look for ld.mold, so check that
name. Cargo finds .cargo/config.toml from its working directory only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T04:22:05.145359Z d9b04ed PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9b04edaca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/link-mold.sh
Comment on lines +8 to +12
if ! command -v ld.mold >/dev/null 2>&1; then
echo "error: RustyGet links Linux builds with mold, which is not installed." >&2
echo " Debian/Ubuntu: sudo apt install mold Fedora: sudo dnf install mold" >&2
echo " Arch: sudo pacman -S mold (see site/content/install.md)" >&2
exit 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Install mold in Linux CI before making it mandatory

On Linux CI runners without ld.mold, this new guard terminates linking, but .github/workflows/build.yml still installs only build-essential pkg-config libssl-dev just python3 par2 before running cargo test. The required Linux x86_64 and arm64 build jobs therefore fail instead of testing the change. .github/workflows/nativeness.yml also omits mold before its Clippy invocation. Add the dependency to both workflows in the same change rather than leaving CI provisioning as a follow-up. This also conflicts with AGENTS.md's requirement that “A change must also build and pass on Linux.”

AGENTS.md reference: AGENTS.md:L65-L69

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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.

1 participant