Skip to content

Commit 9d6d2ef

Browse files
committed
Auto merge of rust-lang#74682 - alexcrichton:backtrace-gimli-round-2, r=Mark-Simulacrum
std: Switch from libbacktrace to gimli (take 2) This is the second attempt to land rust-lang#73441 after being reverted in rust-lang#74613. Will be gathering precise perf numbers here in this take. Closes rust-lang#71060
2 parents 8431cfe + 45721d1 commit 9d6d2ef

File tree

7 files changed

+32
-23
lines changed

7 files changed

+32
-23
lines changed

backtrace

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 4083a90168d605b682ba166a0c01f86b3384e474

std/Cargo.toml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ profiler_builtins = { path = "../profiler_builtins", optional = true }
2222
unwind = { path = "../unwind" }
2323
hashbrown = { version = "0.6.2", default-features = false, features = ['rustc-dep-of-std'] }
2424

25-
[dependencies.backtrace_rs]
26-
package = "backtrace"
27-
version = "0.3.46"
28-
default-features = false # without the libstd `backtrace` feature, stub out everything
29-
features = [ "rustc-dep-of-std" ] # enable build support for integrating into libstd
25+
# Dependencies of the `backtrace` crate
26+
addr2line = { version = "0.13.0", optional = true, default-features = false }
27+
rustc-demangle = { version = "0.1.4", features = ['rustc-dep-of-std'] }
28+
miniz_oxide = { version = "0.4.0", optional = true, default-features = false }
29+
[dependencies.object]
30+
version = "0.20"
31+
optional = true
32+
default-features = false
33+
features = ['read_core', 'elf', 'macho', 'pe']
3034

3135
[dev-dependencies]
3236
rand = "0.7"
@@ -45,11 +49,12 @@ wasi = { version = "0.9.0", features = ['rustc-dep-of-std'], default-features =
4549

4650
[features]
4751
backtrace = [
48-
"backtrace_rs/dbghelp", # backtrace/symbolize on MSVC
49-
"backtrace_rs/libbacktrace", # symbolize on most platforms
50-
"backtrace_rs/libunwind", # backtrace on most platforms
51-
"backtrace_rs/dladdr", # symbolize on platforms w/o libbacktrace
52+
"gimli-symbolize",
53+
'addr2line/rustc-dep-of-std',
54+
'object/rustc-dep-of-std',
55+
'miniz_oxide/rustc-dep-of-std',
5256
]
57+
gimli-symbolize = []
5358

5459
panic-unwind = ["panic_unwind"]
5560
profiler = ["profiler_builtins"]

std/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,5 @@ fn main() {
8888
println!("cargo:rustc-cfg=feature=\"restricted-std\"");
8989
}
9090
println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
91+
println!("cargo:rustc-cfg=backtrace_in_libstd");
9192
}

std/src/backtrace.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,14 @@
9191
// `Backtrace`, but that's a relatively small price to pay relative to capturing
9292
// a backtrace or actually symbolizing it.
9393

94+
use crate::backtrace_rs::{self, BytesOrWideString};
9495
use crate::env;
9596
use crate::ffi::c_void;
9697
use crate::fmt;
9798
use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst};
9899
use crate::sync::Mutex;
99100
use crate::sys_common::backtrace::{lock, output_filename};
100101
use crate::vec::Vec;
101-
use backtrace::BytesOrWideString;
102-
use backtrace_rs as backtrace;
103102

104103
/// A captured OS thread stack backtrace.
105104
///
@@ -150,7 +149,7 @@ struct BacktraceFrame {
150149
}
151150

152151
enum RawFrame {
153-
Actual(backtrace::Frame),
152+
Actual(backtrace_rs::Frame),
154153
#[cfg(test)]
155154
Fake,
156155
}
@@ -197,7 +196,7 @@ impl fmt::Debug for BacktraceSymbol {
197196
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
198197
write!(fmt, "{{ ")?;
199198

200-
if let Some(fn_name) = self.name.as_ref().map(|b| backtrace::SymbolName::new(b)) {
199+
if let Some(fn_name) = self.name.as_ref().map(|b| backtrace_rs::SymbolName::new(b)) {
201200
write!(fmt, "fn: \"{:#}\"", fn_name)?;
202201
} else {
203202
write!(fmt, "fn: <unknown>")?;
@@ -223,7 +222,7 @@ impl fmt::Debug for BytesOrWide {
223222
BytesOrWide::Bytes(w) => BytesOrWideString::Bytes(w),
224223
BytesOrWide::Wide(w) => BytesOrWideString::Wide(w),
225224
},
226-
backtrace::PrintFmt::Short,
225+
backtrace_rs::PrintFmt::Short,
227226
crate::env::current_dir().as_ref().ok(),
228227
)
229228
}
@@ -305,7 +304,7 @@ impl Backtrace {
305304
let mut frames = Vec::new();
306305
let mut actual_start = None;
307306
unsafe {
308-
backtrace::trace_unsynchronized(|frame| {
307+
backtrace_rs::trace_unsynchronized(|frame| {
309308
frames.push(BacktraceFrame {
310309
frame: RawFrame::Actual(frame.clone()),
311310
symbols: Vec::new(),
@@ -356,9 +355,9 @@ impl fmt::Display for Backtrace {
356355

357356
let full = fmt.alternate();
358357
let (frames, style) = if full {
359-
(&capture.frames[..], backtrace::PrintFmt::Full)
358+
(&capture.frames[..], backtrace_rs::PrintFmt::Full)
360359
} else {
361-
(&capture.frames[capture.actual_start..], backtrace::PrintFmt::Short)
360+
(&capture.frames[capture.actual_start..], backtrace_rs::PrintFmt::Short)
362361
};
363362

364363
// When printing paths we try to strip the cwd if it exists, otherwise
@@ -370,7 +369,7 @@ impl fmt::Display for Backtrace {
370369
output_filename(fmt, path, style, cwd.as_ref().ok())
371370
};
372371

373-
let mut f = backtrace::BacktraceFmt::new(fmt, style, &mut print_path);
372+
let mut f = backtrace_rs::BacktraceFmt::new(fmt, style, &mut print_path);
374373
f.add_context()?;
375374
for frame in frames {
376375
let mut f = f.frame();
@@ -380,7 +379,7 @@ impl fmt::Display for Backtrace {
380379
for symbol in frame.symbols.iter() {
381380
f.print_raw(
382381
frame.frame.ip(),
383-
symbol.name.as_ref().map(|b| backtrace::SymbolName::new(b)),
382+
symbol.name.as_ref().map(|b| backtrace_rs::SymbolName::new(b)),
384383
symbol.filename.as_ref().map(|b| match b {
385384
BytesOrWide::Bytes(w) => BytesOrWideString::Bytes(w),
386385
BytesOrWide::Wide(w) => BytesOrWideString::Wide(w),
@@ -415,7 +414,7 @@ impl Capture {
415414
RawFrame::Fake => unimplemented!(),
416415
};
417416
unsafe {
418-
backtrace::resolve_frame_unsynchronized(frame, |symbol| {
417+
backtrace_rs::resolve_frame_unsynchronized(frame, |symbol| {
419418
symbols.push(BacktraceSymbol {
420419
name: symbol.name().map(|m| m.as_bytes().to_vec()),
421420
filename: symbol.filename_raw().map(|b| match b {

std/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ mod panicking;
511511
// compiler
512512
pub mod rt;
513513

514+
#[path = "../../backtrace/src/lib.rs"]
515+
#[allow(dead_code, unused_attributes)]
516+
mod backtrace_rs;
517+
514518
// Pull in the `std_detect` crate directly into libstd. The contents of
515519
// `std_detect` are in a different repository: rust-lang/stdarch.
516520
//

std/src/panicking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn default_hook(info: &PanicInfo<'_>) {
171171
// If this is a double panic, make sure that we print a backtrace
172172
// for this panic. Otherwise only print it if logging is enabled.
173173
let backtrace_env = if panic_count::get() >= 2 {
174-
RustBacktrace::Print(backtrace_rs::PrintFmt::Full)
174+
RustBacktrace::Print(crate::backtrace_rs::PrintFmt::Full)
175175
} else {
176176
backtrace::rust_backtrace_env()
177177
};

std/src/sys_common/backtrace.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::backtrace_rs::{self, BacktraceFmt, BytesOrWideString, PrintFmt};
12
use crate::borrow::Cow;
23
/// Common code for printing the backtrace in the same way across the different
34
/// supported platforms.
@@ -9,8 +10,6 @@ use crate::path::{self, Path, PathBuf};
910
use crate::sync::atomic::{self, Ordering};
1011
use crate::sys::mutex::Mutex;
1112

12-
use backtrace_rs::{BacktraceFmt, BytesOrWideString, PrintFmt};
13-
1413
/// Max number of frames to print.
1514
const MAX_NB_FRAMES: usize = 100;
1615

0 commit comments

Comments
 (0)