-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use gimli instead of libbacktrace by default #189
Comments
Note that
Regarding |
cc @philipc |
Oh sorry to be clear I think it's worse ergonomics and usability-wise to use raw APIs, but I was hoping to head off pain of crates trying to be For |
Fix build error when using the 'webgl_backtrace' feature This patch fixes a build error that happens when building with `--features webgl_backtrace`. However, while working on this I've noticed that calling `Backtrace::new()` instantly causes a segmentation fault. This didn't happen with the example code of [the package](https://crates.io/crates/backtrace) though, so I wasn't sure where to report this (maybe related: [backtrace-rs/#150](rust-lang/backtrace-rs#150), [backtrace-rs/#189](rust-lang/backtrace-rs#189)). cc @alexcrichton @jdm --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ - [x] These changes fix an issue that happens with a compile time feature not tested by the CI <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23966) <!-- Reviewable:end -->
I think I've mentioned this elsewhere but |
I guess this crate already has an implementation of roughly the same thing backtrace-rs/src/symbolize/gimli.rs Line 295 in b5cc5b1
|
The `gimli` crate is an optional alternative backend for the `backtrace` crate based on a pure-Rust DWARF parser as opposed to `libbacktrace`, which is written in C. The long-term plan is to make `gimli` the default backend for the `backtrace` crate (which will eventually be include in `std` and is presently available on `nightly`). For more information, see: rust-lang/backtrace-rs#189 This adds considerably to Cargo.toml as `gimli` has quite a few dependencies, and because of that, it's left off-by-default, but with a commented-out option to activate it in the template's Cargo.toml.
I've recently gotten my once-every-six-months burst of motivation to work on this again. I've sent what's probably a-bit-to-intense flurry of activity to various crates. My goal has been reducing the dependency tree of the
After all that we're only left with With three trivial changes to these crates: and a tiny diff to libstd: diff --git a/Cargo.toml b/Cargo.toml
index 7b5e0fa1c28..3af8f542cb0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -65,5 +65,12 @@ rustc-std-workspace-core = { path = 'src/tools/rustc-std-workspace-core' }
rustc-std-workspace-alloc = { path = 'src/tools/rustc-std-workspace-alloc' }
rustc-std-workspace-std = { path = 'src/tools/rustc-std-workspace-std' }
+backtrace = { path = "../backtrace-rs" }
+object = { git = 'https://github.com/alexcrichton/object', branch = 'dep-of-std' }
+addr2line = { git = 'https://github.com/alexcrichton/addr2line', branch = 'dep-of-std' }
+gimli = { git = 'https://github.com/alexcrichton/gimli', branch = 'dep-of-std' }
+
[patch."https://github.com/rust-lang/rust-clippy"]
clippy_lints = { path = "src/tools/clippy/clippy_lints" }
diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml
index 923d5fa8cac..d36ac35e3fd 100644
--- a/src/libstd/Cargo.toml
+++ b/src/libstd/Cargo.toml
@@ -51,6 +51,7 @@ default = ["std_detect_file_io", "std_detect_dlsym_getauxval", "panic-unwind"]
backtrace = [
"backtrace_rs/dbghelp", # backtrace/symbolize on MSVC
+ "backtrace_rs/gimli-symbolize", # symbolize on most platforms
"backtrace_rs/libbacktrace", # symbolize on most platforms
"backtrace_rs/libunwind", # backtrace on most platforms
"backtrace_rs/dladdr", # symbolize on platforms w/o libbacktrace I've got gimli almost building inside of libstd. The last major remaining work item to actually hook all this up is to figure out how to get all the filesystem-related probing to work in the I tried today to hand-code everything in this crate, but it very quickly gets out of hand. While it's possible to duplicate much of Basically the tl;dr; is that dependencies are no longer a problem. The only problem is how to give the |
Some solutions:
|
I poked at this a while ago and might have a half-baked patch laying around, it wasn't pretty but it was tractable. |
Here's what I had been hacking on: I made a |
When I tried to vendor everything inside of this crate there's basically two reasons that it got out of hand pretty quickly:
This also isn't even starting down the road of "what about split debuginfo?" which is even more gnarly in terms of filesystem traversals. I don't really think there's a great solution to this problem today. A The only halfway-feasible solution I can think of is to make a |
You can also do dyn traits, although they limit you in what you can do (no types, etc) and are slower, but most I/O should be a one time thing anyways. |
My current plan is to first handle all active PRs and get everything settled. I'd like to do a final round of auditing to ensure that gimli doesn't have any obvious or major portability holes. After that I plan to update the crates.io version of this crate to enable gimli-symbolize by default, turning off libbacktrace by default. That'll probably have a back-and-forth for a bit while further bugs are weeded out. After that I'll open a separate issue on this repository for inclusion into the standard library and the issues related with that. |
This commit switches this crate to using `gimli` by default for parsing DWARF debug information. This is a long time coming and brings a number of benefits: * Primarily, Rust is safe. The libbacktrace library has been plagued with segfaults ever since we first started using it. Gimli, however, is almost entirely safe code. This should make us much more resilient in the face of buggy debuginfo. * Secondarily, it means this library no longer needs a C compiler. Being an all-Rust crate generally makes it much easier to cross-compile, port, etc. * Finally, this paves the road for future improvements such as split-debuginfo support by default. The libbacktrace library hasn't really changed since we started using it years ago, and this gives us more control over what's used and how now. Closes #189
This commit switches this crate to using `gimli` by default for parsing DWARF debug information. This is a long time coming and brings a number of benefits: * Primarily, Rust is safe. The libbacktrace library has been plagued with segfaults ever since we first started using it. Gimli, however, is almost entirely safe code. This should make us much more resilient in the face of buggy debuginfo. * Secondarily, it means this library no longer needs a C compiler. Being an all-Rust crate generally makes it much easier to cross-compile, port, etc. * Finally, this paves the road for future improvements such as split-debuginfo support by default. The libbacktrace library hasn't really changed since we started using it years ago, and this gives us more control over what's used and how now. Closes #189
This commit switches this crate to using `gimli` by default for parsing DWARF debug information. This is a long time coming and brings a number of benefits: * Primarily, Rust is safe. The libbacktrace library has been plagued with segfaults ever since we first started using it. Gimli, however, is almost entirely safe code. This should make us much more resilient in the face of buggy debuginfo. * Secondarily, it means this library no longer needs a C compiler. Being an all-Rust crate generally makes it much easier to cross-compile, port, etc. * Finally, this paves the road for future improvements such as split-debuginfo support by default. The libbacktrace library hasn't really changed since we started using it years ago, and this gives us more control over what's used and how now. Closes #189
This commit switches this crate to using `gimli` by default for parsing DWARF debug information. This is a long time coming and brings a number of benefits: * Primarily, Rust is safe. The libbacktrace library has been plagued with segfaults ever since we first started using it. Gimli, however, is almost entirely safe code. This should make us much more resilient in the face of buggy debuginfo. * Secondarily, it means this library no longer needs a C compiler. Being an all-Rust crate generally makes it much easier to cross-compile, port, etc. * Finally, this paves the road for future improvements such as split-debuginfo support by default. The libbacktrace library hasn't really changed since we started using it years ago, and this gives us more control over what's used and how now. Closes #189
This commit switches this crate to using `gimli` by default for parsing DWARF debug information. This is a long time coming and brings a number of benefits: * Primarily, Rust is safe. The libbacktrace library has been plagued with segfaults ever since we first started using it. Gimli, however, is almost entirely safe code. This should make us much more resilient in the face of buggy debuginfo. * Secondarily, it means this library no longer needs a C compiler. Being an all-Rust crate generally makes it much easier to cross-compile, port, etc. * Finally, this paves the road for future improvements such as split-debuginfo support by default. The libbacktrace library hasn't really changed since we started using it years ago, and this gives us more control over what's used and how now. Closes #189
With this now done and shipped, I've opened a dedicated issue to including gimli support in libstd by default. |
This issue is intended to track the switch from the C library libbacktrace by default on many platforms to using Gimli by default on these platforms to symbolicate a backtrace. The rationale for this is that the C library libbacktrace has had a number of security issues historically and we're including it in every single Rust binary by default on relevant platforms (in libstd), so correctness is quite important to us.
Platforms that use libbacktrace by default are:
cfg(unix)
targets.The usage of libbacktrace is relatively simple. We're either consulting the debuginfo, if available, what the symbol name for an address is or we're consulting the dynamic symbol table (aka
dladdr
on Unix, but I don't think this is exactly how libbacktrace gets its).There's one caveat in our usage of libbacktrace in that we have to manually feed in a filename for the current executable to libbacktrace for macOS/Windows platforms. For other Unix platforms I think it finds it through the dynamic library iteration APIs in libc.
Another final caveat is that to fully replace libbacktrace all of the support we use for gimli must be
#![no_std]
. That way it can be included into the standard library, and the standard library can't depend on itself!Today the
gimli-symbolize
feature of this crate actually doesn't depend on gimli at all but rather goes through external crates likeaddr2line
,findshlibs
, andmemmap
. I suspect that we'll probably need to drop the dependencies onfindshlibs
andmemmap
in favor of manually calling the libc APIs here, but if we can work around that it would be great! Note, though, that we don't need full featured platform support in these crates.I think the best thing to do is to probably read up on how libbacktrace acquires debug information to parse. I think it's quite different for Windows/Mac/Linux but I suspect it's relatively straightforward and shouldn't really require that much of libstd/crates.io.
The text was updated successfully, but these errors were encountered: