Skip to content

Commit aab6bbf

Browse files
committedMay 25, 2019
Auto merge of #60852 - alexcrichton:std-backtrace, r=sfackler
std: Depend on `backtrace` crate from crates.io This commit removes all in-tree support for generating backtraces in favor of depending on the `backtrace` crate on crates.io. This resolves a very longstanding piece of duplication where the standard library has long contained the ability to generate a backtrace on panics, but the code was later extracted and duplicated on crates.io with the `backtrace` crate. Since that fork each implementation has seen various improvements one way or another, but typically `backtrace`-the-crate has lagged behind libstd in one way or another. The goal here is to remove this duplication of a fairly critical piece of code and ensure that there's only one source of truth for generating backtraces between the standard library and the crate on crates.io. Recently I've been working to bring the `backtrace` crate on crates.io up to speed with the support in the standard library which includes: * Support for `StackWalkEx` on MSVC to recover inline frames with debuginfo. * Using `libbacktrace` by default on MinGW targets. * Supporting `libbacktrace` on OSX as an option. * Ensuring all the requisite support in `backtrace`-the-crate compiles with `#![no_std]`. * Updating the `libbacktrace` implementation in `backtrace`-the-crate to initialize the global state with the correct filename where necessary. After reviewing the code in libstd the `backtrace` crate should be at exact feature parity with libstd today. The backtraces generated should have the same symbols and same number of frames in general, and there's not known divergence from libstd currently. Note that one major difference between libstd's backtrace support and the `backtrace` crate is that on OSX the crates.io crate enables the `coresymbolication` feature by default. This feature, however, uses private internal APIs that aren't published for OSX. While they provide more accurate backtraces this isn't appropriate for libstd distributed as a binary, so libstd's dependency on the `backtrace` crate explicitly disables this feature and forces OSX to use `libbacktrace` as a symbolication strategy. The long-term goal of this refactoring is to eventually move us towards a world where we can drop `libbacktrace` entirely and simply use Gimli and the surrounding crates for backtrace support. That's still aways off but hopefully will much more easily enabled by having the source of truth for backtraces live in crates.io! Procedurally if we go forward with this I'd like to transfer the `backtrace-rs` crate to the rust-lang GitHub organization as well, but I figured I'd hold off on that until we get closer to merging.
2 parents f492693 + 083cc82 commit aab6bbf

34 files changed

+206
-2162
lines changed
 

‎Cargo.lock

+39-28
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,23 @@ dependencies = [
105105
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
106106
]
107107

108+
[[package]]
109+
name = "autocfg"
110+
version = "0.1.4"
111+
source = "registry+https://github.com/rust-lang/crates.io-index"
112+
108113
[[package]]
109114
name = "backtrace"
110-
version = "0.3.11"
115+
version = "0.3.25"
111116
source = "registry+https://github.com/rust-lang/crates.io-index"
112117
dependencies = [
118+
"autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
113119
"backtrace-sys 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
114-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
120+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
121+
"compiler_builtins 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
115122
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
116123
"rustc-demangle 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
117-
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
124+
"rustc-std-workspace-core 1.0.0",
118125
]
119126

120127
[[package]]
@@ -335,8 +342,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
335342

336343
[[package]]
337344
name = "cfg-if"
338-
version = "0.1.6"
345+
version = "0.1.8"
339346
source = "registry+https://github.com/rust-lang/crates.io-index"
347+
dependencies = [
348+
"compiler_builtins 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
349+
"rustc-std-workspace-core 1.0.0",
350+
]
340351

341352
[[package]]
342353
name = "chalk-engine"
@@ -562,7 +573,7 @@ name = "crc32fast"
562573
version = "1.1.2"
563574
source = "registry+https://github.com/rust-lang/crates.io-index"
564575
dependencies = [
565-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
576+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
566577
]
567578

568579
[[package]]
@@ -598,7 +609,7 @@ version = "0.3.1"
598609
source = "registry+https://github.com/rust-lang/crates.io-index"
599610
dependencies = [
600611
"arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
601-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
612+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
602613
"crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
603614
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
604615
"memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -612,7 +623,7 @@ version = "0.7.0"
612623
source = "registry+https://github.com/rust-lang/crates.io-index"
613624
dependencies = [
614625
"arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
615-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
626+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
616627
"crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
617628
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
618629
"memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -624,15 +635,15 @@ name = "crossbeam-utils"
624635
version = "0.2.2"
625636
source = "registry+https://github.com/rust-lang/crates.io-index"
626637
dependencies = [
627-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
638+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
628639
]
629640

630641
[[package]]
631642
name = "crossbeam-utils"
632643
version = "0.6.5"
633644
source = "registry+https://github.com/rust-lang/crates.io-index"
634645
dependencies = [
635-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
646+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
636647
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
637648
]
638649

@@ -814,15 +825,15 @@ name = "error-chain"
814825
version = "0.11.0"
815826
source = "registry+https://github.com/rust-lang/crates.io-index"
816827
dependencies = [
817-
"backtrace 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
828+
"backtrace 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
818829
]
819830

820831
[[package]]
821832
name = "error-chain"
822833
version = "0.12.0"
823834
source = "registry+https://github.com/rust-lang/crates.io-index"
824835
dependencies = [
825-
"backtrace 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
836+
"backtrace 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
826837
]
827838

828839
[[package]]
@@ -837,7 +848,7 @@ name = "failure"
837848
version = "0.1.5"
838849
source = "registry+https://github.com/rust-lang/crates.io-index"
839850
dependencies = [
840-
"backtrace 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
851+
"backtrace 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
841852
"failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
842853
]
843854

@@ -862,7 +873,7 @@ name = "filetime"
862873
version = "0.2.4"
863874
source = "registry+https://github.com/rust-lang/crates.io-index"
864875
dependencies = [
865-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
876+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
866877
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
867878
"redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
868879
]
@@ -1356,7 +1367,7 @@ name = "log"
13561367
version = "0.4.6"
13571368
source = "registry+https://github.com/rust-lang/crates.io-index"
13581369
dependencies = [
1359-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
1370+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
13601371
]
13611372

13621373
[[package]]
@@ -1642,7 +1653,7 @@ name = "net2"
16421653
version = "0.2.33"
16431654
source = "registry+https://github.com/rust-lang/crates.io-index"
16441655
dependencies = [
1645-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
1656+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
16461657
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
16471658
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
16481659
]
@@ -1711,7 +1722,7 @@ version = "0.10.16"
17111722
source = "registry+https://github.com/rust-lang/crates.io-index"
17121723
dependencies = [
17131724
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
1714-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
1725+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
17151726
"foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
17161727
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
17171728
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1767,7 +1778,7 @@ name = "packed_simd"
17671778
version = "0.3.1"
17681779
source = "registry+https://github.com/rust-lang/crates.io-index"
17691780
dependencies = [
1770-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
1781+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
17711782
]
17721783

17731784
[[package]]
@@ -2351,7 +2362,7 @@ name = "rustc"
23512362
version = "0.0.0"
23522363
dependencies = [
23532364
"arena 0.0.0",
2354-
"backtrace 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
2365+
"backtrace 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
23552366
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
23562367
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
23572368
"chalk-engine 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2409,7 +2420,7 @@ name = "rustc-ap-rustc_data_structures"
24092420
version = "407.0.0"
24102421
source = "registry+https://github.com/rust-lang/crates.io-index"
24112422
dependencies = [
2412-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
2423+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
24132424
"ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
24142425
"jobserver 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
24152426
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2481,7 +2492,7 @@ name = "rustc-ap-syntax_pos"
24812492
version = "407.0.0"
24822493
source = "registry+https://github.com/rust-lang/crates.io-index"
24832494
dependencies = [
2484-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
2495+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
24852496
"rustc-ap-arena 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
24862497
"rustc-ap-rustc_data_structures 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
24872498
"rustc-ap-serialize 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2708,7 +2719,7 @@ dependencies = [
27082719
name = "rustc_data_structures"
27092720
version = "0.0.0"
27102721
dependencies = [
2711-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
2722+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
27122723
"ena 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
27132724
"graphviz 0.0.0",
27142725
"jobserver 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3291,7 +3302,7 @@ name = "socket2"
32913302
version = "0.3.8"
32923303
source = "registry+https://github.com/rust-lang/crates.io-index"
32933304
dependencies = [
3294-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
3305+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
32953306
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
32963307
"redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
32973308
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3307,7 +3318,7 @@ name = "std"
33073318
version = "0.0.0"
33083319
dependencies = [
33093320
"alloc 0.0.0",
3310-
"backtrace-sys 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
3321+
"backtrace 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
33113322
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
33123323
"compiler_builtins 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
33133324
"core 0.0.0",
@@ -3319,7 +3330,6 @@ dependencies = [
33193330
"panic_unwind 0.0.0",
33203331
"profiler_builtins 0.0.0",
33213332
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
3322-
"rustc-demangle 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
33233333
"rustc_asan 0.0.0",
33243334
"rustc_lsan 0.0.0",
33253335
"rustc_msan 0.0.0",
@@ -3462,7 +3472,7 @@ name = "syntax_pos"
34623472
version = "0.0.0"
34633473
dependencies = [
34643474
"arena 0.0.0",
3465-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
3475+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
34663476
"rustc_data_structures 0.0.0",
34673477
"rustc_macros 0.1.0",
34683478
"scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3486,7 +3496,7 @@ name = "tempfile"
34863496
version = "3.0.5"
34873497
source = "registry+https://github.com/rust-lang/crates.io-index"
34883498
dependencies = [
3489-
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
3499+
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
34903500
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
34913501
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
34923502
"redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -4091,7 +4101,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
40914101
"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee"
40924102
"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef"
40934103
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
4094-
"checksum backtrace 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "18b65ea1161bfb2dd6da6fade5edd4dbd08fba85012123dd333d2fd1b90b2782"
4104+
"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf"
4105+
"checksum backtrace 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)" = "1c50b4cb6d852a8567d98bb11c03f91ccec4dfbd88778bc1b92789c624081283"
40954106
"checksum backtrace-sys 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)" = "6ea90dd7b012b3d1a2cb6bec16670a0db2c95d4e931e84f4047e0460c1b34c8d"
40964107
"checksum bit-set 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6f1efcc46c18245a69c38fcc5cc650f16d3a59d034f3106e9ed63748f695730a"
40974108
"checksum bit-vec 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4440d5cb623bb7390ae27fec0bb6c61111969860f8e3ae198bfa0663645e67cf"
@@ -4109,7 +4120,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
41094120
"checksum bytesize 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "716960a18f978640f25101b5cbf1c6f6b0d3192fab36a2d98ca96f0ecbe41010"
41104121
"checksum cargo_metadata 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "585784cac9b05c93a53b17a0b24a5cdd1dfdda5256f030e089b549d2390cc720"
41114122
"checksum cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "5e5f3fee5eeb60324c2781f1e41286bdee933850fff9b3c672587fed5ec58c83"
4112-
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
4123+
"checksum cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "89431bba4e6b7092fb5fcd00a6f6ca596c55cc26b2f1e6dcdd08a1f4933f66b2"
41134124
"checksum chalk-engine 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17ec698a6f053a23bfbe646d9f2fde4b02abc19125595270a99e6f44ae0bdd1a"
41144125
"checksum chalk-macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "295635afd6853aa9f20baeb7f0204862440c0fe994c5a253d5f479dac41d047e"
41154126
"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878"

‎src/libstd/Cargo.toml

+12-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,18 @@ compiler_builtins = { version = "0.1.15" }
2323
profiler_builtins = { path = "../libprofiler_builtins", optional = true }
2424
unwind = { path = "../libunwind" }
2525
hashbrown = { version = "0.3.0", features = ['rustc-dep-of-std'] }
26-
rustc-demangle = { version = "0.1.10", features = ['rustc-dep-of-std'] }
27-
backtrace-sys = { version = "0.1.24", features = ["rustc-dep-of-std"], optional = true }
26+
27+
[dependencies.backtrace]
28+
version = "0.3.25"
29+
default-features = false # don't use coresymbolication on OSX
30+
features = [
31+
"rustc-dep-of-std", # enable build support for integrating into libstd
32+
"dbghelp", # backtrace/symbolize on MSVC
33+
"libbacktrace", # symbolize on most platforms
34+
"libunwind", # backtrace on most platforms
35+
"dladdr", # symbolize on platforms w/o libbacktrace
36+
]
37+
optional = true
2838

2939
[dev-dependencies]
3040
rand = "0.6.1"
@@ -51,7 +61,6 @@ cc = "1.0"
5161
[features]
5262
default = ["std_detect_file_io", "std_detect_dlsym_getauxval"]
5363

54-
backtrace = ["backtrace-sys"]
5564
panic-unwind = ["panic_unwind"]
5665
profiler = ["profiler_builtins"]
5766
compiler-builtins-c = ["alloc/compiler-builtins-c"]

0 commit comments

Comments
 (0)