-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add libstd Cargo feature "panic_immediate_abort" #55011
Conversation
r? @KodrAus (rust_highfive has picked a reviewer for you, use r? to override) |
I suspect that if you're willing to compile std etc yourself using |
This is the next step after Even with For info: stripped file size of a {simple program that checks password against sha512 hash and executes supplied program on success} after each step, for
|
☔ The latest upstream changes (presumably #54951) made this pull request unmergeable. Please resolve the merge conflicts. |
Sidenote: @vi do not merge master when merge conflicts arise, rebase against master on your PRs. |
44b0e23
to
d48a11a
Compare
Thanks for your patience @vi! Hmm, am I reading right that the case you've got is where you've been careful not to interact with the formatting machinery at all because it's heavy, but it's still finding its way in through On the surface adding a knob to patch up this case seems like it would be brittle, but I don't work in environments where this is really important so don't really understand your workflow.
This seems a little surprising to me. Is that what we expect? cc @alexcrichton @japaric who would understand this much better than I do. |
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thanks for the PR here! I think, though, that for this problem we probably want to tackle this a slightly different way. I've been thinking that if we want to avoid panicking/formatting infrastructure then we should generate binaries that, at the codegen level, never emit the information. As written this still relies on LLVM's LTO to get rid of formatting infrastructure, although this does get rid of the panicking infrastructure. Is there a way we could perhaps guarantee both get eliminated? |
Ping from triage |
Shall I try doing something myself? Shall the patch change more things, but avoid relying on I also expect formatting to be still available if one explicitly uses some Also simple and easy-ish approach like this patch can be made available now, with proper solution available someday. |
I added this label last week, IIRC mainly because I had seen @alexcrichton's question in his last comment. |
I would personally either prefer a solution which adds this feature at the source, not even passing panic information into libstd, or one which is a little less invasive than sprinkling a few For the former solution I think it's more work to get done because it would require changing the definition of the For the latter solution I think this can probably get by with: if cfg!(feature = "panic_immediate_abort") {
unsafe { ::intrinsics::abort() }
} in a few locations. |
Ping from triage, @alexcrichton @vi what's the status on this? |
Idling, not sure what to do next. I though about changing |
src/libstd/panicking.rs
Outdated
reason = "used by the panic! macro", | ||
issue = "0")] | ||
#[cfg(feature="panic_immediate_abort")] | ||
#[inline(never)] #[cold] // avoid code bloat at the call sites as much as possible |
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.
Shouldn't this be #[inline]
. A call may be longer than ud2
.
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.
Probably. Inline line is just a copy-paste from the other variant of the function.
Its in libcore. |
I've already outlined my thoughts on this. @vi do you have questions about my thinking? |
Is it worth to do the second, easier approach first, postponing the first, complexier approach to possible further pull requests?
Isn't it what this pull request attempts to do? Or do you mean the pull request should be changed to use
Or maybe I got those locations wrong and |
I think it's fine to start here, but yes I would prefer to switch to |
Patching But |
d48a11a
to
aae24d4
Compare
@alexcrichton Prepared second version of the easy approach.
Currently recommended [dependencies]
std = {default-features=false, features=["panic_immediate_abort"]}
core = {default-features=false, features=["panic_immediate_abort"]} and Question: should there be non-default |
Yeah, seems to be an issue with the test.
No idea why it wasn't caught in the many tests I ran. |
let's retry @bors |
cc @dlrobertson this failure looks like there may be a spurious bug in the va_list tests added maybe? |
@alexcrichton Thanks, I've got some tests running just to make sure it is a issue with the tests. If it is, I'll have a fix up shortly. |
…chton Add libstd Cargo feature "panic_immediate_abort" It stop asserts and panics from libstd to automatically include string output and formatting code. Use case: developing static executables smaller than 50 kilobytes, where usual formatting code is excessive while keeping debuggability in debug mode. May resolve rust-lang#54981.
Rollup of 19 pull requests Successful merges: - #55011 (Add libstd Cargo feature "panic_immediate_abort") - #55821 (Use sort_by_cached_key when the key function is not trivial/free) - #56014 (add test for issue #21335) - #56131 (Assorted tweaks) - #56214 (Implement chalk unification routines) - #56216 (Add TryFrom<&[T]> for [T; $N] where T: Copy) - #56268 (Reuse the `P` in `InvocationCollector::fold_{,opt_}expr`.) - #56324 (Use raw_entry for more efficient interning) - #56336 (Clean up and streamline the pretty-printer) - #56337 (Fix const_fn ICE with non-const function pointer) - #56339 (Remove not used option) - #56341 (Rename conversion util; remove duplicate util in librustc_codegen_llvm.) - #56349 (rustc 1.30.0's linker flavor inference is a non-backwards compat change to -Clinker) - #56355 (Add inline attributes and add unit to CommonTypes) - #56360 (Optimize local linkchecker program) - #56364 (Fix panic with outlives in existential type) - #56365 (Stabilize self_struct_ctor feature.) - #56367 (Moved some feature gate tests to correct location) - #56373 (Update books)
tests: Simplify VaList run-make test The va_list tests were too complex and were causing some spurious test failures on Windows. Example: #55011 (comment)
@vi / @alexcrichton Is there an example somewhere that shows how to use |
@johnthagen I don't know of examples myself, but yeah Xargo would be needed and would be used to enable this feature |
@johnthagen, See this comment and this trivial example. |
Sorry if I overlooked the answer to the following question somewhere: Why are the arguments not optimized out, if I don't use the |
@MauriceKayser , "panic means abort" is easy and simple to explain and is relatively reliable. Previous version of this pull request used some hackery in |
This is fine, if the user wishes for this behaviour. I do not, and I do not understand how that answers my question of optimizing out unused arguments. Is this optimization not possible because of the |
… r=joshtriplett Make certain panicky stdlib functions behave better under panic_immediate_abort The stdlib has a `panic_immediate_abort` feature that turns panics into immediate aborts, without any formatting/display logic. This feature was [introduced](rust-lang#55011) primarily for codesize-constrained situations. Unfortunately, this win doesn't quite propagate to `Result::expect()` and `Result::unwrap()`, while the formatting machinery is reduced, `expect()` and `unwrap()` both call `unwrap_failed("msg", &err)` which has a signature of `fn unwrap_failed(msg: &str, error: &dyn fmt::Debug)` and is `#[inline(never)]`. This means that `unwrap_failed` will unconditionally construct a `dyn Debug` trait object even though the object is never used in the function. Constructing a trait object (even if you never call a method on it!) forces rust to include the vtable and any dependencies. This means that in `panic_immediate_abort` mode, calling expect/unwrap on a Result will pull in a whole bunch of formatting code for the error type even if it's completely unused. This PR swaps out the function with one that won't require a trait object such that it won't force the inclusion of vtables in the code. It also gates off `#[inline(never)]` in a bunch of other places where allowing the inlining of an abort may be useful (this kind of thing is already done elsewhere in the stdlib). I don't know how to write a test for this; we don't really seem to have any tests for `panic_immediate_abort` anyway so perhaps it's fine as is.
Builds with `-Z build-std-features=panic_immediate_abort` to ensure the `core::panicking` plumbing is stripped. See: rust-lang/rust#55011 Adds `-Cpanic=abort` to RUSTFLAGS so that build profiles do not need to specify `panic = "abort"` in Cargo.toml. This can potentially allow simulator builds to customize panics. (Maybe printing to the console and stopping the event loop, for instance. But this work is TBD.) Fixes pd-rs/crankstart#66
It stop asserts and panics from libstd to automatically
include string output and formatting code.
Use case: developing static executables smaller than 50 kilobytes,
where usual formatting code is excessive while keeping debuggability
in debug mode.
May resolve #54981.