Skip to content

Commit 77d74da

Browse files
alexcrichtonbrson
authored andcommitted
rustbuild: Don't enable debuginfo in rustc
In #37280 we enabled line number debugging information in release artifacts, primarily to close out #36452 where debugging information was critical for MSVC builds of Rust to be useful in production. This commit, however, apparently had some unfortunate side effects. Namely it was noticed in #37477 that if `RUST_BACKTRACE=1` was set then any compiler error would take a very long time for the compiler to exit. The cause of the problem here was somewhat deep: * For all compiler errors, the compiler will `panic!` with a known value. This tears down the main compiler thread and allows cleaning up all the various resources. By default, however, this panic output is suppressed for "normal" compiler errors. * When `RUST_BACKTRACE=1` was set this caused every compiler error to generate a backtrace. * The libbacktrace library hits a pathological case where it spends a very long time in its custom allocation function, `backtrace_alloc`, because the compiler has so much debugging information. More information about this can be found in #29293 with a summary at the end of #37477. To solve this problem this commit simply removes debuginfo from the compiler but not from the standard library. This should allow us to keep #36452 closed while also closing #37477. I've measured the difference to be orders of magnitude faster than it was before, so we should see a much quicker time-to-exit after a compile error when `RUST_BACKTRACE=1` is set. Closes #37477 Closes #37571
1 parent d81140a commit 77d74da

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

configure

+9-4
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ opt_nosave debug-assertions 0 "build with debugging assertions"
647647
opt_nosave llvm-release-debuginfo 0 "build LLVM with debugger metadata"
648648
opt_nosave debuginfo 0 "build with debugger metadata"
649649
opt_nosave debuginfo-lines 0 "build with line number debugger metadata"
650+
opt_nosave debuginfo-only-std 0 "build only libstd with debugging information"
650651
opt_nosave debug-jemalloc 0 "build jemalloc with --enable-debug --enable-fill"
651652

652653
valopt localstatedir "/var/lib" "local state directory"
@@ -732,23 +733,26 @@ case "$CFG_RELEASE_CHANNEL" in
732733
nightly )
733734
msg "overriding settings for $CFG_RELEASE_CHANNEL"
734735
CFG_ENABLE_LLVM_ASSERTIONS=1
735-
736-
# FIXME(#37364) shouldn't have to disable this on windows-gnu
736+
# FIXME(stage0) re-enable this on the next stage0 now that #35566 is
737+
# fixed
737738
case "$CFG_BUILD" in
738739
*-pc-windows-gnu)
739740
;;
740741
*)
741-
CFG_ENABLE_DEBUGINFO_LINES=1
742+
CFG_ENABLE_DEBUGINFO_LINES=1
743+
CFG_ENABLE_DEBUGINFO_ONLY_STD=1
742744
;;
743745
esac
746+
744747
;;
745748
beta | stable)
746749
msg "overriding settings for $CFG_RELEASE_CHANNEL"
747750
case "$CFG_BUILD" in
748751
*-pc-windows-gnu)
749752
;;
750753
*)
751-
CFG_ENABLE_DEBUGINFO_LINES=1
754+
CFG_ENABLE_DEBUGINFO_LINES=1
755+
CFG_ENABLE_DEBUGINFO_ONLY_STD=1
752756
;;
753757
esac
754758
;;
@@ -784,6 +788,7 @@ if [ -n "$CFG_ENABLE_DEBUG_ASSERTIONS" ]; then putvar CFG_ENABLE_DEBUG_ASSERTION
784788
if [ -n "$CFG_ENABLE_LLVM_RELEASE_DEBUGINFO" ]; then putvar CFG_ENABLE_LLVM_RELEASE_DEBUGINFO; fi
785789
if [ -n "$CFG_ENABLE_DEBUGINFO" ]; then putvar CFG_ENABLE_DEBUGINFO; fi
786790
if [ -n "$CFG_ENABLE_DEBUGINFO_LINES" ]; then putvar CFG_ENABLE_DEBUGINFO_LINES; fi
791+
if [ -n "$CFG_ENABLE_DEBUGINFO_ONLY_STD" ]; then putvar CFG_ENABLE_DEBUGINFO_ONLY_STD; fi
787792
if [ -n "$CFG_ENABLE_DEBUG_JEMALLOC" ]; then putvar CFG_ENABLE_DEBUG_JEMALLOC; fi
788793

789794
step_msg "looking for build programs"

src/bootstrap/compile.rs

+7
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ pub fn rustc<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
190190
.env("CFG_PREFIX", build.config.prefix.clone().unwrap_or(String::new()))
191191
.env("CFG_LIBDIR_RELATIVE", "lib");
192192

193+
// If we're not building a compiler with debugging information then remove
194+
// these two env vars which would be set otherwise.
195+
if build.config.rust_debuginfo_only_std {
196+
cargo.env_remove("RUSTC_DEBUGINFO");
197+
cargo.env_remove("RUSTC_DEBUGINFO_LINES");
198+
}
199+
193200
if let Some(ref ver_date) = build.ver_date {
194201
cargo.env("CFG_VER_DATE", ver_date);
195202
}

src/bootstrap/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub struct Config {
6161
pub rust_debug_assertions: bool,
6262
pub rust_debuginfo: bool,
6363
pub rust_debuginfo_lines: bool,
64+
pub rust_debuginfo_only_std: bool,
6465
pub rust_rpath: bool,
6566
pub rustc_default_linker: Option<String>,
6667
pub rustc_default_ar: Option<String>,
@@ -167,6 +168,7 @@ struct Rust {
167168
debug_assertions: Option<bool>,
168169
debuginfo: Option<bool>,
169170
debuginfo_lines: Option<bool>,
171+
debuginfo_only_std: Option<bool>,
170172
debug_jemalloc: Option<bool>,
171173
use_jemalloc: Option<bool>,
172174
backtrace: Option<bool>,
@@ -279,6 +281,7 @@ impl Config {
279281
set(&mut config.rust_debug_assertions, rust.debug_assertions);
280282
set(&mut config.rust_debuginfo, rust.debuginfo);
281283
set(&mut config.rust_debuginfo_lines, rust.debuginfo_lines);
284+
set(&mut config.rust_debuginfo_only_std, rust.debuginfo_only_std);
282285
set(&mut config.rust_optimize, rust.optimize);
283286
set(&mut config.rust_optimize_tests, rust.optimize_tests);
284287
set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
@@ -371,6 +374,7 @@ impl Config {
371374
("DEBUG_ASSERTIONS", self.rust_debug_assertions),
372375
("DEBUGINFO", self.rust_debuginfo),
373376
("DEBUGINFO_LINES", self.rust_debuginfo_lines),
377+
("DEBUGINFO_ONLY_STD", self.rust_debuginfo_only_std),
374378
("JEMALLOC", self.use_jemalloc),
375379
("DEBUG_JEMALLOC", self.debug_jemalloc),
376380
("RPATH", self.rust_rpath),

src/bootstrap/config.toml.example

+5
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@
123123
# Whether or not line number debug information is emitted
124124
#debuginfo-lines = false
125125

126+
# Whether or not to only build debuginfo for the standard library if enabled.
127+
# If enabled, this will not compile the compiler with debuginfo, just the
128+
# standard library.
129+
#debuginfo-only-std = false
130+
126131
# Whether or not jemalloc is built and enabled
127132
#use-jemalloc = true
128133

0 commit comments

Comments
 (0)