about summary refs log tree commit diff
path: root/src/libstd/sys_common/backtrace.rs
AgeCommit message (Collapse)AuthorLines
2020-07-27mv std libs to library/mark-215/+0
2020-07-22Revert "std: Switch from libbacktrace to gimli"Mark Rousskov-1/+2
This reverts commit 13db3cc1e8d2fd4b8e7c74d91002274d7b62801b.
2020-07-17std: Switch from libbacktrace to gimliAlex Crichton-2/+1
This commit is a proof-of-concept for switching the standard library's backtrace symbolication mechanism on most platforms from libbacktrace to gimli. The standard library's support for `RUST_BACKTRACE=1` requires in-process parsing of object files and DWARF debug information to interpret it and print the filename/line number of stack frames as part of a backtrace. Historically this support in the standard library has come from a library called "libbacktrace". The libbacktrace library seems to have been extracted from gcc at some point and is written in C. We've had a lot of issues with libbacktrace over time, unfortunately, though. The library does not appear to be actively maintained since we've had patches sit for months-to-years without comments. We have discovered a good number of soundness issues with the library itself, both when parsing valid DWARF as well as invalid DWARF. This is enough of an issue that the libs team has previously decided that we cannot feed untrusted inputs to libbacktrace. This also doesn't take into account the portability of libbacktrace which has been difficult to manage and maintain over time. While possible there are lots of exceptions and it's the main C dependency of the standard library right now. For years it's been the desire to switch over to a Rust-based solution for symbolicating backtraces. It's been assumed that we'll be using the Gimli family of crates for this purpose, which are targeted at safely and efficiently parsing DWARF debug information. I've been working recently to shore up the Gimli support in the `backtrace` crate. As of a few weeks ago the `backtrace` crate, by default, uses Gimli when loaded from crates.io. This transition has gone well enough that I figured it was time to start talking seriously about this change to the standard library. This commit is a preview of what's probably the best way to integrate the `backtrace` crate into the standard library with the Gimli feature turned on. While today it's used as a crates.io dependency, this commit switches the `backtrace` crate to a submodule of this repository which will need to be updated manually. This is not done lightly, but is thought to be the best solution. The primary reason for this is that the `backtrace` crate needs to do some pretty nontrivial filesystem interactions to locate debug information. Working without `std::fs` is not an option, and while it might be possible to do some sort of trait-based solution when prototyped it was found to be too unergonomic. Using a submodule allows the `backtrace` crate to build as a submodule of the `std` crate itself, enabling it to use `std::fs` and such. Otherwise this adds new dependencies to the standard library. This step requires extra attention because this means that these crates are now going to be included with all Rust programs by default. It's important to note, however, that we're already shipping libbacktrace with all Rust programs by default and it has a bunch of C code implementing all of this internally anyway, so we're basically already switching already-shipping functionality to Rust from C. * `object` - this crate is used to parse object file headers and contents. Very low-level support is used from this crate and almost all of it is disabled. Largely we're just using struct definitions as well as convenience methods internally to read bytes and such. * `addr2line` - this is the main meat of the implementation for symbolication. This crate depends on `gimli` for DWARF parsing and then provides interfaces needed by the `backtrace` crate to turn an address into a filename / line number. This crate is actually pretty small (fits in a single file almost!) and mirrors most of what `dwarf.c` does for libbacktrace. * `miniz_oxide` - the libbacktrace crate transparently handles compressed debug information which is compressed with zlib. This crate is used to decompress compressed debug sections. * `gimli` - not actually used directly, but a dependency of `addr2line`. * `adler32`- not used directly either, but a dependency of `miniz_oxide`. The goal of this change is to improve the safety of backtrace symbolication in the standard library, especially in the face of possibly malformed DWARF debug information. Even to this day we're still seeing segfaults in libbacktrace which could possibly become security vulnerabilities. This change should almost entirely eliminate this possibility whilc also paving the way forward to adding more features like split debug information. Some references for those interested are: * Original addition of libbacktrace - #12602 * OOM with libbacktrace - #24231 * Backtrace failure due to use of uninitialized value - #28447 * Possibility to feed untrusted data to libbacktrace - #21889 * Soundness fix for libbacktrace - #33729 * Crash in libbacktrace - #39468 * Support for macOS, never merged - ianlancetaylor/libbacktrace#2 * Performance issues with libbacktrace - #29293, #37477 * Update procedure is quite complicated due to how many patches we need to carry - #50955 * Libbacktrace doesn't work on MinGW with dynamic libs - #71060 * Segfault in libbacktrace on macOS - #71397 Switching to Rust will not make us immune to all of these issues. The crashes are expected to go away, but correctness and performance may still have bugs arise. The gimli and `backtrace` crates, however, are actively maintained unlike libbacktrace, so this should enable us to at least efficiently apply fixes as situations come up.
2020-03-20remove redundant returns (clippy::needless_return)Matthias Krüger-1/+1
2020-03-07Use writeln!(fmt, "word") instead of write!(fmt, "word\n") ↵Matthias Krüger-1/+1
(clippy::write_with_newline)
2020-02-11Fix failing backtrace ui testsJane Lusby-0/+1
2019-12-22Format the worldMark Rousskov-13/+4
2019-11-11Don't attempt to get cwd when printing backtrace under MiriAaron Hill-1/+8
This allows Miri to print backtraces in isolation mode
2019-09-25std: Reduce checks for `feature = "backtrace"`Alex Crichton-25/+35
This is a stylistic change to libstd to reduce the number of checks of `feature = "backtrace"` now that we unconditionally depend on the `backtrace` crate and rely on it having an empty implementation. otherwise.
2019-09-16avoid #[cfg] in favor of cfg!Ralf Jung-2/+0
2019-09-14rename the crate, not the featureRalf Jung-5/+5
2019-09-14std: always depend on backtrace, but only enable its features on demandRalf Jung-1/+4
2019-09-11Auto merge of #64154 - alexcrichton:std-backtrace, r=sfacklerbors-54/+65
std: Add a `backtrace` module This commit adds a `backtrace` module to the standard library, as designed in [RFC 2504]. The `Backtrace` type is intentionally very conservative, effectively only allowing capturing it and printing it. Additionally this commit also adds a `backtrace` method to the `Error` trait which defaults to returning `None`, as specified in [RFC 2504]. More information about the design here can be found in [RFC 2504] and in the [tracking issue]. Implementation-wise this is all based on the `backtrace` crate and very closely mirrors the `backtrace::Backtrace` type on crates.io. Otherwise it's pretty standard in how it handles everything internally. [RFC 2504]: https://github.com/rust-lang/rfcs/blob/master/text/2504-fix-error.md [tracking issue]: https://github.com/rust-lang/rust/issues/53487 cc #53487
2019-09-09Always show backtrace on FuchsiaTaylor Cramer-0/+6
2019-09-09std: Add a `backtrace` moduleAlex Crichton-54/+65
This commit adds a `backtrace` module to the standard library, as designed in [RFC 2504]. The `Backtrace` type is intentionally very conservative, effectively only allowing capturing it and printing it. Additionally this commit also adds a `backtrace` method to the `Error` trait which defaults to returning `None`, as specified in [RFC 2504]. More information about the design here can be found in [RFC 2504] and in the [tracking issue]. Implementation-wise this is all based on the `backtrace` crate and very closely mirrors the `backtrace::Backtrace` type on crates.io. Otherwise it's pretty standard in how it handles everything internally. [RFC 2504]: https://github.com/rust-lang/rfcs/blob/master/text/2504-fix-error.md [tracking issue]: https://github.com/rust-lang/rust/issues/53487 cc #53487
2019-09-04Use backtrace formatting from the backtrace crateTaylor Cramer-146/+89
2019-06-05Aggregation of drive-by cosmetic changes.Alexander Regueiro-1/+1
2019-05-25std: Depend on `backtrace` crate from crates.ioAlex Crichton-151/+153
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.
2019-04-22Remove double trailing newlinesvarkor-1/+0
2019-02-28libstd => 2018Taiki Endo-9/+10
2019-02-10libs: doc commentsAlexander Regueiro-2/+2
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-24std: Use backtrace-sys from crates.ioAlex Crichton-0/+8
This commit switches the standard library to using the `backtrace-sys` crate from crates.io instead of duplicating the logic here in the Rust repositor with the `backtrace-sys`'s crate's logic. Eventually this will hopefully be a good step towards using the `backtrace` crate directly from crates.io itself, but we're not quite there yet! Hopefully this is a small incremental first step we can take.
2018-12-14std: Use `rustc_demangle` from crates.ioAlex Crichton-228/+11
No more need to duplicate the demangling routine between crates.io and the standard library, we can use the exact same one!
2018-07-27Auto merge of #52336 - ishitatsuyuki:dyn-rollup, r=Mark-Simulacrumbors-5/+5
Rollup of bare_trait_objects PRs All deny attributes were moved into bootstrap so they can be disabled with a line of config. Warnings for external tools are allowed and it's up to the tool's maintainer to keep it warnings free. r? @Mark-Simulacrum cc @ljedrz @kennytm
2018-07-23libstd: Prefer `Option::map`/etc over `match` where applicableColin Wallace-5/+4
2018-07-10Deny bare trait objects in `src/libstd`.ljedrz-5/+5
2018-06-26migrate codebase to `..=` inclusive range patternsZack M. Davis-1/+1
These were stabilized in March 2018's #47813, and are the Preferred Way to Do It going forward (q.v. #51043).
2018-04-13std: Minimize size of panicking on wasmAlex Crichton-7/+6
This commit applies a few code size optimizations for the wasm target to the standard library, namely around panics. We notably know that in most configurations it's impossible for us to print anything in wasm32-unknown-unknown so we can skip larger portions of panicking that are otherwise simply informative. This allows us to get quite a nice size reduction. Finally we can also tweak where the allocation happens for the `Box<Any>` that we panic with. By only allocating once unwinding starts we can reduce the size of a panicking wasm module from 44k to 350 bytes.
2018-02-17fix more typos found by codespell.Matthias Krüger-1/+1
2018-01-26Print inlined functions on WindowsJohn Kåre Alsaker-0/+3
2017-12-26Change name of `lang_start_real` to `lang_start_internal`Bastian Köcher-1/+1
Also remove `'static` from `__rust_begin_short_backtrace`
2017-11-30rustc: Prepare to enable ThinLTO by defaultAlex Crichton-2/+20
This commit prepares to enable ThinLTO and multiple codegen units in release mode by default. We've still got a debuginfo bug or two to sort out before actually turning it on by default.
2017-11-09std: Avoid use of `libc` in portable modulesAlex Crichton-5/+6
This commit removes usage of the `libc` crate in "portable" modules like those at the top level and `sys_common`. Instead common types like `*mut u8` or `u32` are used instead of `*mut c_void` or `c_int` as well as switching to platform-specific functions like `sys::strlen` instead of `libc::strlen`.
2017-10-05Remove nacl from libstdest31-2/+0
2017-05-09Don't show the std frames before user code on unwinding.Yamakaky-4/+40
When `RUST_BACKTRACE=1`, remove all frames after `__rust_maybe_catch_panic`. Tested on `main`, threads, tests and benches. Cleaning of the top of the stacktrace is let to a future PR. Fixes #40201 See #41815
2017-04-18std: Back out backtrace pruning logicAlex Crichton-80/+4
It was discovered #40264 that this backtrace pruning logic is a little too aggressive, so while we figure how out to handle #40264 this commit backs out the changes to prune frames. Note that other cosmetic changes, such as better path printing and such remain.
2017-03-30Replace hardcoded forward slash with path::MAIN_SEPARATORThomas Jespersen-2/+2
Fixes #40149
2017-02-26Also ignore std::panicYamakaky-0/+3
2017-02-26Fix tests on Windows in Debug configuration (#4)Vadim Petrochenkov-0/+6
2017-02-25Fix tests on ARM Linux (#3)Vadim Petrochenkov-0/+1
2017-02-23rposition() -> rev().position() (#2)Vadim Petrochenkov-1/+1
2017-02-23Fix tests on Windows (#1)Vadim Petrochenkov-40/+56
2017-02-15Improve backtrace formating while panicking.Yamakaky-26/+227
- `RUST_BACKTRACE=full` prints all the informations (old behaviour) - `RUST_BACKTRACE=(0|no)` disables the backtrace. - `RUST_BACKTRACE=<everything else>` (including `1`) shows a simplified backtrace, without the function addresses and with cleaned filenames and symbols. Also removes some unneded frames at the beginning and the end. Fixes #37783. PR is #38165.
2016-11-01std: Move sys_common to libstd/sys_commonBrian Anderson-0/+257
Make the directory structure reflect the module structure. I've always found the existing structure confusing.