Skip to content

build: pin the build-std feature set and disallow std::backtrace - #39425

Merged
Jarred-Sumner merged 1 commit into
mainfrom
farm/ed29f7c7/build-std-no-backtrace-lint
Aug 17, 2026
Merged

Jarred-Sumner merged 1 commit into
mainfrom
farm/ed29f7c7/build-std-no-backtrace-lint

Conversation

@robobun

@robobun robobun commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #39326, where @alii asked how we make sure building std without its backtrace feature stays safe. The verification itself is written up in #39326 (comment); this PR turns the two invariants it rests on into checks.

Problem

  • build rust std without the backtrace symbolizer #39326 passes -Zbuild-std-features=panic-unwind,default to release builds, so std::backtrace::Backtrace now captures frames it cannot symbolize on the unix targets (std's vendored backtrace crate selects its noop symbolizer when the feature is off), and RUST_BACKTRACE no longer does anything.
  • That is fine today because nothing in the workspace uses std::backtrace (the last use, a FileSink probe, went away in FileSink: remove Windows UAF diagnostic probes #32474), but nothing stopped a new use from coming back and quietly printing bare addresses.
  • Nothing pinned which build configurations get the flag; the cfg.release && !cfg.asan gate in scripts/build/rust.ts:429 was untested.

Fix

  • clippy.toml: add std::backtrace::Backtrace to disallowed-types. The workspace sets disallowed_types = "deny" and the rust-lints workflow runs clippy on every PR touching src/**/*.rs or clippy.toml, so a new use fails CI with a message pointing at the build flag and at bun_core::dump_current_stack_trace.
  • test/internal/source-lints/build-rust.test.ts: assert the exact -Zbuild-std* args per configuration. Release gets -Zbuild-std=... -Zbuild-std-features=panic-unwind,default on linux gnu/musl/android, darwin, windows, freebsd x64 and the tier 3 freebsd aarch64; release-asan, debug-asan and tier 3 debug get bare -Zbuild-std; plain debug gets neither.
  • Verified:
    • bun test test/internal/source-lints/ (the documented way to run this directory; it never touches the built binary): 172 pass. Also ran build-rust.test.ts through bun bd test.
    • With scripts/build/rust.ts taken from the commit before build rust std without the backtrace symbolizer #39326, the first new test fails; with the !cfg.asan guard removed, the second one fails.
    • The clippy entry was checked against a scratch crate containing std::backtrace::Backtrace::force_capture() inline (the shape the FileSink probe had), use std::backtrace::Backtrace;, the type in a signature and Backtrace::capture(): all four are reported as errors. Scratch code not included.
    • cargo clippy -p bun_core -p bun_ptr -p bun_crash_handler --no-deps is clean with the new entry locally, and the rust-lints workflow's full-workspace cargo clippy passed on this PR, so the entry does not fire on any existing code.
  • Nothing under src/ changes. The test pins scripts/build/rust.ts and the clippy entry is checked by the rust-lints workflow, so the fail/pass evidence for this PR is the pre-build rust std without the backtrace symbolizer #39326 rust.ts run above, not a src diff. The comments at src/bun_core/Global.rs:155 and src/ptr/ref_count.rs:24 still describe a "std::backtrace fallback" that is not in the tree; left for a separate cleanup to keep this PR to the checks.

Background

  • -Zbuild-std makes cargo compile std from source as part of the build; -Zbuild-std-features chooses std's cargo features. Cargo's default set is panic-unwind,backtrace,default, and backtrace is what compiles the in-process symbolizer (gimli, addr2line, object, miniz_oxide) into std for std::backtrace and the default panic hook's RUST_BACKTRACE output.
  • bun never relies on either: bun_crash_handler::init() installs its own panic hook as the first thing main does, and that hook captures frames with a frame pointer walk and emits a trace string that bun.report symbolizes out of process.
  • clippy's disallowed-types is the repo's existing mechanism for banning specific std items (std::fs::File, std::sync::Mutex, ...); disallowed_types is set to deny in the workspace lints, so an entry there is a CI failure, not a warning.

[stamp-90s] gate passed · iteration 2 · 2 files touched

passes on PR (with fix)
Test-only change.

Debug/ASAN (expected pass):
$ bun bd test 'test/internal/source-lints/build-rust.test.ts'
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test test/internal/source-lints/build-rust.test.ts
bun test v1.4.0 (8326d1bd3)

test/internal/source-lints/build-rust.test.ts:
(pass) allRustTargets > is exactly the set of triples .buildkite/ci.mjs builds [31.94ms]
(pass) allRustTargets > rust-toolchain.toml preinstalls std for exactly the triples that have a prebuilt one [10.30ms]
(pass) allRustTargets > a Tier 3 target builds std from source with the flag rust:check-all shares [101.89ms]
(pass) build-std feature set > release builds drop std's `backtrace` feature on every shipped platform family [183.79ms]
(pass) build-std feature set > builds that rebuild std for other reasons keep cargo's default feature set [77.06ms]
(pass) CPU baseline > arm64 linux, freebsd and windows assume armv8-a+crc tuned for Ampere, like the C++ side [71.72ms]
(pass) CPU baseline > arm64 android assumes armv8-a+crc tuned for Cortex-A78, like the C++ side [23.69ms]
(pass) CPU baseline > darwin arm64 and x64 name the C++ side's CPU model directly [62.14ms]

 8 pass
 0 fail
 29 expect() calls
Ran 8 tests across 1 file. [4.10s]
Exit: 0
diff hotspot
clippy.toml                                   |  1 +
 test/internal/source-lints/build-rust.test.ts | 38 +++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

gate history · 1 passed · 1 rejected · iteration 2

evidence per changed file
file                                           reads  edits  tests
clippy.toml                                        1      1      0
test/internal/source-lints/build-rust.test.ts      2      2      0

@coderabbitai

coderabbitai Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 52cb084b-5d3c-41d5-91e3-09262780443d

📥 Commits

Reviewing files that changed from the base of the PR and between 1dd66af and 826d289.

📒 Files selected for processing (2)
  • clippy.toml
  • test/internal/source-lints/build-rust.test.ts

Included review availability: Your plan includes up to 5 reviews per rolling hour; 0 remain after this review.


Walkthrough

Changes

Backtrace configuration safeguards

Layer / File(s) Summary
Cargo build-std feature validation
test/internal/source-lints/build-rust.test.ts
Tests verify Cargo -Zbuild-std feature selection across shipped platforms and special build modes.
Backtrace API restriction
clippy.toml
Disallows std::backtrace::Backtrace and directs code to bun_core::dump_current_stack_trace.

Suggested reviewers: jarred-sumner

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the two main safeguards: pinning build-std features and banning std::backtrace usage.
Description check ✅ Passed The description explains the problem, fix, verification steps, affected configurations, and implementation details in sufficient depth.

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — one clippy disallowed-types entry, two comment corrections, and configure-time tests that pin the -Zbuild-std* args.

What was reviewed:

  • Confirmed no std::backtrace usages remain under src/, and disallowed_types = "deny" in the workspace lints, so the new clippy entry is a hard error and won't break existing code.
  • Checked the new test cases against scripts/build/rust.ts:417-436: the tier3 || cfg.release || cfg.asan and cfg.release && !cfg.asan gates match every asserted case (release, release-asan, debug-asan, tier3-debug, plain-debug).
  • Verified the two rewritten comments now describe what dump_stack_trace / dump_current_stack_trace and the ref_count hook actually do; no code changed in either file.
Extended reasoning...

Overview

Follow-up to #39326 that turns two invariants into checks. Four files touched:

  • clippy.toml: adds std::backtrace::Backtrace to disallowed-types with a reason pointing at the build flag and bun_core::dump_current_stack_trace.
  • src/bun_core/Global.rs, src/ptr/ref_count.rs: doc-comment rewrites only. The old text referenced a "std::backtrace fallback" that isn't in the tree; the new text describes the actual behavior (raw addresses for stored traces, bun_crash_handler for current-stack).
  • test/internal/source-lints/build-rust.test.ts: adds a describe("build-std feature set") block asserting the exact -Zbuild-std* args per configuration.

Security risks

None. No runtime code paths change — the two .rs edits are comments only, the clippy entry is a lint-time check, and the tests exercise scripts/build/rust.ts configure logic without spawning cargo.

Level of scrutiny

Low. This is a mechanical hardening PR: one lint entry following the exact pattern of the ten existing disallowed-types entries, comment corrections, and pure configure-time test assertions in an existing source-lints file. The PR description documents that the tests were verified to fail against the pre-#39326 rust.ts and against a version with the !cfg.asan guard removed, and that the clippy entry was checked against the four shapes a std::backtrace use can take.

Other factors

  • Grep confirms zero occurrences of std::backtrace in src/**/*.rs, so the new deny-level lint won't fire on existing code.
  • Cargo.toml:295 sets disallowed_types = "deny", so the entry is a CI failure, not a warning — matches the PR's claim.
  • The new tests reuse resolve, withAbi, cargoBuildInvocation, and cargoBuildStdArg, all already imported/defined in the file. The .startsWith("-Zbuild-std") filter correctly captures both -Zbuild-std=... and -Zbuild-std-features=... in order, and cargoBuildInvocation returns only the main build args (not the separate shim invocation at rust.ts:821).
  • No CODEOWNERS entries cover these paths. No prior review comments to address.

Release builds compile std without its `backtrace` feature (#39326), which
only holds up while nothing in the workspace uses std::backtrace. Add the
type to clippy.toml's disallowed-types so a future use fails the rust-lints
workflow instead of silently producing unsymbolized frames, and assert in
build-rust.test.ts which configurations get -Zbuild-std-features and which
keep cargo's default set.
@robobun
robobun force-pushed the farm/ed29f7c7/build-std-no-backtrace-lint branch from c145d6b to 826d289 Compare August 17, 2026 09:28

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — additive lint config and configure-time test, no runtime code touched.

What was reviewed:

  • clippy.toml entry follows the existing disallowed-types pattern; bun_core::dump_current_stack_trace referenced in the reason exists.
  • Test assertions match the tier3 || cfg.release || cfg.asan / cfg.release && !cfg.asan gates at scripts/build/rust.ts:417-436 exactly, and cargoBuildStdArg is exported.
  • The -Zbuild-std prefix filter also matches the shim's -Zbuild-std=core,compiler_builtins args, but those come from a separate function (not cargoBuildInvocation), so they don't leak into these assertions.
Extended reasoning...

Overview

Two files, both additive: one line appended to clippy.toml's disallowed-types list banning std::backtrace::Backtrace, and a new describe("build-std feature set") block in test/internal/source-lints/build-rust.test.ts with two tests pinning the exact -Zbuild-std* args cargoBuildInvocation emits per (buildType, asan, tier) combination. No src/ changes.

Security risks

None. This is a lint-config entry and a configure-time test that reads scripts/build/rust.ts output without spawning cargo or touching the network/filesystem beyond the repo checkout.

Level of scrutiny

Low. The clippy entry is mechanically identical to the ten entries above it (std::fs::File, std::sync::Mutex, …), and the workspace already denies disallowed_types, so a typo in the path or a false positive on existing code would have failed the rust-lints workflow the PR description reports as green. The test additions reuse the file's existing resolve / withAbi / mockToolchain scaffolding verbatim and mirror the neighboring describe("CPU baseline") block's structure.

Other factors

I cross-checked the assertions against scripts/build/rust.ts: cargoBuildStdArg is exported at line 120, and the branch at lines 417-436 (if (tier3 || cfg.release || cfg.asan) { push(cargoBuildStdArg); if (cfg.release && !cfg.asan) push("-Zbuild-std-features=panic-unwind,default") }) produces exactly the four shapes the tests assert — release → both args, release+asan / debug+asan / tier3-debug → bare cargoBuildStdArg, plain debug → neither. The resolve helper spreads { buildType: "Release", ...partial } so the explicit buildType: "Debug" overrides land as intended. The startsWith("-Zbuild-std") filter would also catch the shim's -Zbuild-std=core,compiler_builtins args, but those are emitted by a separate shim-build path rather than cargoBuildInvocation, so there's no cross-contamination. The PR description documents fail-first verification (pre-#39326 rust.ts fails test 1; removing !cfg.asan fails test 2), satisfying the "prove the test fails for the right reason" bar. No outstanding reviewer comments.

@Jarred-Sumner
Jarred-Sumner merged commit 8d9cbbd into main Aug 17, 2026
11 checks passed
@Jarred-Sumner
Jarred-Sumner deleted the farm/ed29f7c7/build-std-no-backtrace-lint branch August 17, 2026 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants