Skip to content

Commit c058a8b

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

File tree

14 files changed

+130
-56
lines changed

14 files changed

+130
-56
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@
4444
[submodule "src/tools/rust-analyzer"]
4545
path = src/tools/rust-analyzer
4646
url = https://github.com./rust-analyzer/rust-analyzer.git
47+
[submodule "library/backtrace"]
48+
path = library/backtrace
49+
url = https://github.com./rust-lang/backtrace-rs.git

Cargo.lock

+59-29
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
# This file is automatically @generated by Cargo.
22
# It is not intended for manual editing.
33
[[package]]
4-
name = "adler32"
5-
version = "1.0.3"
4+
name = "addr2line"
5+
version = "0.13.0"
66
source = "registry+https://github.com./rust-lang/crates.io-index"
7-
checksum = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c"
7+
checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072"
8+
dependencies = [
9+
"compiler_builtins",
10+
"gimli",
11+
"rustc-std-workspace-alloc",
12+
"rustc-std-workspace-core",
13+
]
14+
15+
[[package]]
16+
name = "adler"
17+
version = "0.2.3"
18+
source = "registry+https://github.com./rust-lang/crates.io-index"
19+
checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e"
20+
dependencies = [
21+
"compiler_builtins",
22+
"rustc-std-workspace-core",
23+
]
824

925
[[package]]
1026
name = "aho-corasick"
@@ -125,28 +141,14 @@ checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
125141

126142
[[package]]
127143
name = "backtrace"
128-
version = "0.3.46"
129-
source = "registry+https://github.com./rust-lang/crates.io-index"
130-
checksum = "b1e692897359247cc6bb902933361652380af0f1b7651ae5c5013407f30e109e"
144+
version = "0.3.50"
131145
dependencies = [
132-
"backtrace-sys",
146+
"addr2line",
133147
"cfg-if",
134-
"compiler_builtins",
135148
"libc",
149+
"miniz_oxide",
150+
"object",
136151
"rustc-demangle",
137-
"rustc-std-workspace-core",
138-
]
139-
140-
[[package]]
141-
name = "backtrace-sys"
142-
version = "0.1.37"
143-
source = "registry+https://github.com./rust-lang/crates.io-index"
144-
checksum = "18fbebbe1c9d1f383a9cc7e8ccdb471b91c8d024ee9c2ca5b5346121fe8b4399"
145-
dependencies = [
146-
"cc",
147-
"compiler_builtins",
148-
"libc",
149-
"rustc-std-workspace-core",
150152
]
151153

152154
[[package]]
@@ -689,9 +691,9 @@ dependencies = [
689691

690692
[[package]]
691693
name = "crc32fast"
692-
version = "1.1.2"
694+
version = "1.2.0"
693695
source = "registry+https://github.com./rust-lang/crates.io-index"
694-
checksum = "e91d5240c6975ef33aeb5f148f35275c25eda8e8a5f95abe421978b05b8bf192"
696+
checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1"
695697
dependencies = [
696698
"cfg-if",
697699
]
@@ -1024,9 +1026,9 @@ checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d"
10241026

10251027
[[package]]
10261028
name = "flate2"
1027-
version = "1.0.12"
1029+
version = "1.0.16"
10281030
source = "registry+https://github.com./rust-lang/crates.io-index"
1029-
checksum = "ad3c5233c9a940c8719031b423d7e6c16af66e031cb0420b0896f5245bf181d3"
1031+
checksum = "68c90b0fc46cf89d227cc78b40e494ff81287a92dd07631e5af0d06fe3cf885e"
10301032
dependencies = [
10311033
"cfg-if",
10321034
"crc32fast",
@@ -1160,6 +1162,17 @@ dependencies = [
11601162
"wasi",
11611163
]
11621164

1165+
[[package]]
1166+
name = "gimli"
1167+
version = "0.22.0"
1168+
source = "registry+https://github.com./rust-lang/crates.io-index"
1169+
checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724"
1170+
dependencies = [
1171+
"compiler_builtins",
1172+
"rustc-std-workspace-alloc",
1173+
"rustc-std-workspace-core",
1174+
]
1175+
11631176
[[package]]
11641177
name = "git2"
11651178
version = "0.13.5"
@@ -1820,11 +1833,14 @@ dependencies = [
18201833

18211834
[[package]]
18221835
name = "miniz_oxide"
1823-
version = "0.3.5"
1836+
version = "0.4.0"
18241837
source = "registry+https://github.com./rust-lang/crates.io-index"
1825-
checksum = "6f3f74f726ae935c3f514300cc6773a0c9492abc5e972d42ba0c0ebb88757625"
1838+
checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f"
18261839
dependencies = [
1827-
"adler32",
1840+
"adler",
1841+
"compiler_builtins",
1842+
"rustc-std-workspace-alloc",
1843+
"rustc-std-workspace-core",
18281844
]
18291845

18301846
[[package]]
@@ -1956,6 +1972,17 @@ dependencies = [
19561972
"libc",
19571973
]
19581974

1975+
[[package]]
1976+
name = "object"
1977+
version = "0.20.0"
1978+
source = "registry+https://github.com./rust-lang/crates.io-index"
1979+
checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5"
1980+
dependencies = [
1981+
"compiler_builtins",
1982+
"rustc-std-workspace-alloc",
1983+
"rustc-std-workspace-core",
1984+
]
1985+
19591986
[[package]]
19601987
name = "once_cell"
19611988
version = "1.1.0"
@@ -4348,8 +4375,8 @@ dependencies = [
43484375
name = "std"
43494376
version = "0.0.0"
43504377
dependencies = [
4378+
"addr2line",
43514379
"alloc",
4352-
"backtrace",
43534380
"cfg-if",
43544381
"compiler_builtins",
43554382
"core",
@@ -4358,10 +4385,13 @@ dependencies = [
43584385
"hashbrown",
43594386
"hermit-abi",
43604387
"libc",
4388+
"miniz_oxide",
4389+
"object",
43614390
"panic_abort",
43624391
"panic_unwind",
43634392
"profiler_builtins",
43644393
"rand 0.7.3",
4394+
"rustc-demangle",
43654395
"unwind",
43664396
"wasi",
43674397
]

Cargo.toml

+18
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ overflow-checks = false
5656
# per-crate configuration isn't specifiable in the environment.
5757
codegen-units = 10000
5858

59+
# These dependencies of the standard library implement symbolication for
60+
# backtraces on most platforms. Their debuginfo causes both linking to be slower
61+
# (more data to chew through) and binaries to be larger without really all that
62+
# much benefit. This section turns them all to down to have no debuginfo which
63+
# helps to improve link times a little bit.
64+
[profile.release.package]
65+
addr2line.debug = 0
66+
adler.debug = 0
67+
gimli.debug = 0
68+
miniz_oxide.debug = 0
69+
object.debug = 0
70+
5971
# We want the RLS to use the version of Cargo that we've got vendored in this
6072
# repository to ensure that the same exact version of Cargo is used by both the
6173
# RLS and the Cargo binary itself. The RLS depends on Cargo as a git repository
@@ -80,5 +92,11 @@ rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' }
8092
rustc-std-workspace-alloc = { path = 'library/rustc-std-workspace-alloc' }
8193
rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' }
8294

95+
# This crate's integration with libstd is a bit wonky, so we use a submodule
96+
# instead of a crates.io dependency. Make sure everything else in the repo is
97+
# also using the submodule, however, so we can avoid duplicate copies of the
98+
# source code for this crate.
99+
backtrace = { path = "library/backtrace" }
100+
83101
[patch."https://github.com/rust-lang/rust-clippy"]
84102
clippy_lints = { path = "src/tools/clippy/clippy_lints" }

library/backtrace

Submodule backtrace added at 4083a90

library/std/Cargo.toml

+14-9
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"]

library/std/build.rs

+1
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
}

library/std/src/backtrace.rs

+10-11
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 {

library/std/src/lib.rs

+4
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
//

library/std/src/panicking.rs

+1-1
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
};

library/std/src/sys_common/backtrace.rs

+1-2
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

rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ignore = [
1414
"src/test",
1515

1616
# do not format submodules
17+
"library/backtrace",
1718
"library/stdarch",
1819
"src/doc/book",
1920
"src/doc/edition-guide",

0 commit comments

Comments
 (0)