Repository navigation
build: pin the build-std feature set and disallow std::backtrace - #39425
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan includes up to 5 reviews per rolling hour; 0 remain after this review. WalkthroughChangesBacktrace configuration safeguards
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
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::backtraceusages remain undersrc/, anddisallowed_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: thetier3 || cfg.release || cfg.asanandcfg.release && !cfg.asangates 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_traceand theref_counthook 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: addsstd::backtrace::Backtracetodisallowed-typeswith a reason pointing at the build flag andbun_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_handlerfor current-stack).test/internal/source-lints/build-rust.test.ts: adds adescribe("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::backtraceinsrc/**/*.rs, so the new deny-level lint won't fire on existing code. Cargo.toml:295setsdisallowed_types = "deny", so the entry is a CI failure, not a warning — matches the PR's claim.- The new tests reuse
resolve,withAbi,cargoBuildInvocation, andcargoBuildStdArg, all already imported/defined in the file. The.startsWith("-Zbuild-std")filter correctly captures both-Zbuild-std=...and-Zbuild-std-features=...in order, andcargoBuildInvocationreturns 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.
c145d6b to
826d289
Compare
There was a problem hiding this comment.
LGTM — additive lint config and configure-time test, no runtime code touched.
What was reviewed:
- clippy.toml entry follows the existing
disallowed-typespattern;bun_core::dump_current_stack_tracereferenced in the reason exists. - Test assertions match the
tier3 || cfg.release || cfg.asan/cfg.release && !cfg.asangates at scripts/build/rust.ts:417-436 exactly, andcargoBuildStdArgis exported. - The
-Zbuild-stdprefix filter also matches the shim's-Zbuild-std=core,compiler_builtinsargs, but those come from a separate function (notcargoBuildInvocation), 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.
Follow-up to #39326, where @alii asked how we make sure building std without its
backtracefeature stays safe. The verification itself is written up in #39326 (comment); this PR turns the two invariants it rests on into checks.Problem
-Zbuild-std-features=panic-unwind,defaultto release builds, sostd::backtrace::Backtracenow captures frames it cannot symbolize on the unix targets (std's vendored backtrace crate selects its noop symbolizer when the feature is off), andRUST_BACKTRACEno longer does anything.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.cfg.release && !cfg.asangate in scripts/build/rust.ts:429 was untested.Fix
std::backtrace::Backtracetodisallowed-types. The workspace setsdisallowed_types = "deny"and the rust-lints workflow runs clippy on every PR touchingsrc/**/*.rsor clippy.toml, so a new use fails CI with a message pointing at the build flag and atbun_core::dump_current_stack_trace.-Zbuild-std*args per configuration. Release gets-Zbuild-std=... -Zbuild-std-features=panic-unwind,defaulton 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.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 throughbun bd test.!cfg.asanguard removed, the second one fails.std::backtrace::Backtrace::force_capture()inline (the shape the FileSink probe had),use std::backtrace::Backtrace;, the type in a signature andBacktrace::capture(): all four are reported as errors. Scratch code not included.cargo clippy -p bun_core -p bun_ptr -p bun_crash_handler --no-depsis clean with the new entry locally, and the rust-lints workflow's full-workspacecargo clippypassed on this PR, so the entry does not fire on any existing code.Background
-Zbuild-stdmakes cargo compile std from source as part of the build;-Zbuild-std-featureschooses std's cargo features. Cargo's default set ispanic-unwind,backtrace,default, andbacktraceis what compiles the in-process symbolizer (gimli, addr2line, object, miniz_oxide) into std forstd::backtraceand the default panic hook'sRUST_BACKTRACEoutput.bun_crash_handler::init()installs its own panic hook as the first thingmaindoes, and that hook captures frames with a frame pointer walk and emits a trace string that bun.report symbolizes out of process.disallowed-typesis the repo's existing mechanism for banning specific std items (std::fs::File,std::sync::Mutex, ...);disallowed_typesis set todenyin 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)
diff hotspot
gate history · 1 passed · 1 rejected · iteration 2
evidence per changed file