-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add experimental backtrace-trace-only
std feature
#143910
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
Conversation
f7963bb
to
1dccc65
Compare
A quick test on an empty bin project does shows a fairly substantial difference in final binary size (exact numbers may vary of course):
|
Two comments then r=me
Any idea why we don't have a |
@@ -92,6 +92,7 @@ backtrace = [ | |||
'object/rustc-dep-of-std', | |||
'miniz_oxide/rustc-dep-of-std', | |||
] | |||
backtrace-trace-only = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will still compile addr2line, gimli and object. Maybe instead have a feature to enable just backtraces and then another feature which enables this feature and in addition enables backtrace symbolication.
Edit: You already suggested that in the PR description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, doing this fully will require making changes to backtrace-rs, which I'm trying to avoid for the initial implementation. Also, although it's unstable, I don't want to break people currently using build-std-features
just yet.
if cfg!(feature = "backtrace-trace-only") { | ||
const HEX_WIDTH: usize = 2 + 2 * core::mem::size_of::<usize>(); | ||
let frame_ip = frame.ip(); | ||
res = writeln!(bt_fmt.formatter(), "{idx:4}: {frame_ip:HEX_WIDTH$?}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be able to actually symbolize the backtraces this would need to print both the path of the DSO (executable or dylib) and the offset within this DSO. It could be a dylib loaded at runtime and thanks to ASLR the exact location of DSOs can't be determined anymore after the fact unless we print it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could take inspiration on what backtrace-rs does on Fuchsia which unconditionally does backtrace symbolication out of process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work normally when symbols aren't available? The backtrace is just unusable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't think the backtraces are all that usable without symbols when ASLR is disabled. I guess it still shows symbol names for system libraries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'm going to punt on doing the hard thing again 🙂. This is (arguably) a pre-existing issue and at least somewhat platform specific so would be much better fixed in backtrace-rs than std. This feature can then use whatever backtrace-rs has once that's written.
cc #139209 |
1dccc65
to
9fd3886
Compare
I've no idea tbh. I'd note that designing a |
@bors r=tgross35 rollup |
…ross35 Add experimental `backtrace-trace-only` std feature This experimentally allows building std with backtrace but without symbolisation. It does not affect stable and requires build-std to use. This doesn't change the backtrace crate itself so relies on the optimizer to remove the unused parts. Example usage: ```toml # .cargo/config.toml [unstable] build-std = ["core", "alloc", "panic_unwind", "std"] build-std-features = ["backtrace", "backtrace-trace-only", "panic-unwind"] ``` ```toml # Cargo.toml [profile.release] opt-level = 3 lto = "thin" codegen-units = 1 ``` Ideally we should split the backtrace feature into `backtrace-trace` and `backtrace-symbolize` (with the latter dependent on the former) because Cargo features tend to work better when they're positive rather than negative. But I'm keen for this experiment not to break existing users. cc `@joshtriplett`
…ross35 Add experimental `backtrace-trace-only` std feature This experimentally allows building std with backtrace but without symbolisation. It does not affect stable and requires build-std to use. This doesn't change the backtrace crate itself so relies on the optimizer to remove the unused parts. Example usage: ```toml # .cargo/config.toml [unstable] build-std = ["core", "alloc", "panic_unwind", "std"] build-std-features = ["backtrace", "backtrace-trace-only", "panic-unwind"] ``` ```toml # Cargo.toml [profile.release] opt-level = 3 lto = "thin" codegen-units = 1 ``` Ideally we should split the backtrace feature into `backtrace-trace` and `backtrace-symbolize` (with the latter dependent on the former) because Cargo features tend to work better when they're positive rather than negative. But I'm keen for this experiment not to break existing users. cc ``@joshtriplett``
Rollup of 16 pull requests Successful merges: - #142301 (tests: Fix duplicated-path-in-error fail with musl) - #142936 (rustdoc-json: Structured attributes) - #143355 (wrapping shift: remove first bitmask and table) - #143630 (Drop `./x suggest`) - #143738 (Move several float tests to floats/mod.rs) - #143752 (Don't panic if WASI_SDK_PATH not set when detecting compiler) - #143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets) - #143837 (Adjust `run_make_support::symbols` helpers) - #143878 (Port `#[pointee]` to the new attribute parsing infrastructure) - #143907 (core: make `str::split_at_unchecked()` inline) - #143910 (Add experimental `backtrace-trace-only` std feature) - #143927 (Preserve constness in trait objects up to hir ty lowering) - #143935 (rustc_type_ir/walk: move docstring to `TypeWalker` itself) - #143938 (Update books) - #143941 (update `cfg_select!` documentation) - #143948 (Update mdbook to 0.4.52) Failed merges: - #143926 (Remove deprecated fields in bootstrap) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 16 pull requests Successful merges: - #142301 (tests: Fix duplicated-path-in-error fail with musl) - #142936 (rustdoc-json: Structured attributes) - #143355 (wrapping shift: remove first bitmask and table) - #143630 (Drop `./x suggest`) - #143738 (Move several float tests to floats/mod.rs) - #143752 (Don't panic if WASI_SDK_PATH not set when detecting compiler) - #143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets) - #143837 (Adjust `run_make_support::symbols` helpers) - #143878 (Port `#[pointee]` to the new attribute parsing infrastructure) - #143907 (core: make `str::split_at_unchecked()` inline) - #143910 (Add experimental `backtrace-trace-only` std feature) - #143927 (Preserve constness in trait objects up to hir ty lowering) - #143935 (rustc_type_ir/walk: move docstring to `TypeWalker` itself) - #143938 (Update books) - #143941 (update `cfg_select!` documentation) - #143948 (Update mdbook to 0.4.52) Failed merges: - #143926 (Remove deprecated fields in bootstrap) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 13 pull requests Successful merges: - #142301 (tests: Fix duplicated-path-in-error fail with musl) - #143630 (Drop `./x suggest`) - #143736 (Give all bytes of TypeId provenance) - #143752 (Don't panic if WASI_SDK_PATH not set when detecting compiler) - #143837 (Adjust `run_make_support::symbols` helpers) - #143878 (Port `#[pointee]` to the new attribute parsing infrastructure) - #143905 (Recover and suggest to use `;` to construct array type) - #143907 (core: make `str::split_at_unchecked()` inline) - #143910 (Add experimental `backtrace-trace-only` std feature) - #143927 (Preserve constness in trait objects up to hir ty lowering) - #143935 (rustc_type_ir/walk: move docstring to `TypeWalker` itself) - #143938 (Update books) - #143941 (update `cfg_select!` documentation) Failed merges: - #143926 (Remove deprecated fields in bootstrap) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #143910 - ChrisDenton:no-symbolization, r=tgross35 Add experimental `backtrace-trace-only` std feature This experimentally allows building std with backtrace but without symbolisation. It does not affect stable and requires build-std to use. This doesn't change the backtrace crate itself so relies on the optimizer to remove the unused parts. Example usage: ```toml # .cargo/config.toml [unstable] build-std = ["core", "alloc", "panic_unwind", "std"] build-std-features = ["backtrace", "backtrace-trace-only", "panic-unwind"] ``` ```toml # Cargo.toml [profile.release] opt-level = 3 lto = "thin" codegen-units = 1 ``` Ideally we should split the backtrace feature into `backtrace-trace` and `backtrace-symbolize` (with the latter dependent on the former) because Cargo features tend to work better when they're positive rather than negative. But I'm keen for this experiment not to break existing users. cc ``@joshtriplett``
This experimentally allows building std with backtrace but without symbolisation. It does not affect stable and requires build-std to use. This doesn't change the backtrace crate itself so relies on the optimizer to remove the unused parts.
Example usage:
Ideally we should split the backtrace feature into
backtrace-trace
andbacktrace-symbolize
(with the latter dependent on the former) because Cargo features tend to work better when they're positive rather than negative. But I'm keen for this experiment not to break existing users.cc @joshtriplett