Skip to content

Commit 099e7cb

Browse files
committedJan 11, 2017
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 e4fee52 commit 099e7cb

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"
@@ -733,23 +734,26 @@ case "$CFG_RELEASE_CHANNEL" in
733734
nightly )
734735
msg "overriding settings for $CFG_RELEASE_CHANNEL"
735736
CFG_ENABLE_LLVM_ASSERTIONS=1
736-
737-
# FIXME(#37364) shouldn't have to disable this on windows-gnu
737+
# FIXME(stage0) re-enable this on the next stage0 now that #35566 is
738+
# fixed
738739
case "$CFG_BUILD" in
739740
*-pc-windows-gnu)
740741
;;
741742
*)
742-
CFG_ENABLE_DEBUGINFO_LINES=1
743+
CFG_ENABLE_DEBUGINFO_LINES=1
744+
CFG_ENABLE_DEBUGINFO_ONLY_STD=1
743745
;;
744746
esac
747+
745748
;;
746749
beta | stable)
747750
msg "overriding settings for $CFG_RELEASE_CHANNEL"
748751
case "$CFG_BUILD" in
749752
*-pc-windows-gnu)
750753
;;
751754
*)
752-
CFG_ENABLE_DEBUGINFO_LINES=1
755+
CFG_ENABLE_DEBUGINFO_LINES=1
756+
CFG_ENABLE_DEBUGINFO_ONLY_STD=1
753757
;;
754758
esac
755759
;;
@@ -785,6 +789,7 @@ if [ -n "$CFG_ENABLE_DEBUG_ASSERTIONS" ]; then putvar CFG_ENABLE_DEBUG_ASSERTION
785789
if [ -n "$CFG_ENABLE_LLVM_RELEASE_DEBUGINFO" ]; then putvar CFG_ENABLE_LLVM_RELEASE_DEBUGINFO; fi
786790
if [ -n "$CFG_ENABLE_DEBUGINFO" ]; then putvar CFG_ENABLE_DEBUGINFO; fi
787791
if [ -n "$CFG_ENABLE_DEBUGINFO_LINES" ]; then putvar CFG_ENABLE_DEBUGINFO_LINES; fi
792+
if [ -n "$CFG_ENABLE_DEBUGINFO_ONLY_STD" ]; then putvar CFG_ENABLE_DEBUGINFO_ONLY_STD; fi
788793
if [ -n "$CFG_ENABLE_DEBUG_JEMALLOC" ]; then putvar CFG_ENABLE_DEBUG_JEMALLOC; fi
789794

790795
step_msg "looking for build programs"

‎src/bootstrap/compile.rs

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

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

‎src/bootstrap/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub struct Config {
6363
pub rust_debug_assertions: bool,
6464
pub rust_debuginfo: bool,
6565
pub rust_debuginfo_lines: bool,
66+
pub rust_debuginfo_only_std: bool,
6667
pub rust_rpath: bool,
6768
pub rustc_default_linker: Option<String>,
6869
pub rustc_default_ar: Option<String>,
@@ -179,6 +180,7 @@ struct Rust {
179180
debug_assertions: Option<bool>,
180181
debuginfo: Option<bool>,
181182
debuginfo_lines: Option<bool>,
183+
debuginfo_only_std: Option<bool>,
182184
debug_jemalloc: Option<bool>,
183185
use_jemalloc: Option<bool>,
184186
backtrace: Option<bool>,
@@ -298,6 +300,7 @@ impl Config {
298300
set(&mut config.rust_debug_assertions, rust.debug_assertions);
299301
set(&mut config.rust_debuginfo, rust.debuginfo);
300302
set(&mut config.rust_debuginfo_lines, rust.debuginfo_lines);
303+
set(&mut config.rust_debuginfo_only_std, rust.debuginfo_only_std);
301304
set(&mut config.rust_optimize, rust.optimize);
302305
set(&mut config.rust_optimize_tests, rust.optimize_tests);
303306
set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
@@ -390,6 +393,7 @@ impl Config {
390393
("DEBUG_ASSERTIONS", self.rust_debug_assertions),
391394
("DEBUGINFO", self.rust_debuginfo),
392395
("DEBUGINFO_LINES", self.rust_debuginfo_lines),
396+
("DEBUGINFO_ONLY_STD", self.rust_debuginfo_only_std),
393397
("JEMALLOC", self.use_jemalloc),
394398
("DEBUG_JEMALLOC", self.debug_jemalloc),
395399
("RPATH", self.rust_rpath),

‎src/bootstrap/config.toml.example

+5
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@
149149
# Whether or not line number debug information is emitted
150150
#debuginfo-lines = false
151151

152+
# Whether or not to only build debuginfo for the standard library if enabled.
153+
# If enabled, this will not compile the compiler with debuginfo, just the
154+
# standard library.
155+
#debuginfo-only-std = false
156+
152157
# Whether or not jemalloc is built and enabled
153158
#use-jemalloc = true
154159

0 commit comments

Comments
 (0)
Please sign in to comment.