-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Allow asserts and panics to abort process quietly. #54981
Comments
Looks like making Is a pull request about this welcome? |
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.
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 #54981.
…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.
With the new feature merged in, one can opt out formatting and panic handling using You need to
All panics and failed asserts will just cause Illegal Instruction. |
Hey @vi, I'm so glad you got this in! I followed your instructions above and my binaries are getting smaller. However, |
Try the minimal example:
#![no_main]
#[no_mangle]
pub fn main() {
}
[dependencies]
std = {default-features=false, features=["panic_immediate_abort"]}
[package]
name = "tiny"
version = "0.1.0"
authors = []
edition = "2018"
[profile.release]
opt-level = "s"
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
panic = 'abort'
incremental = false Commands:
Is it the same for you? |
You're right, I get the same as you. But trying that helped me figure out that adding the libc crate seems to be what adds the libpthread dependency, so thanks! |
Strange. #![no_main]
#[no_mangle]
pub unsafe fn main() {
libc::_exit(0);
} does not include pthread, but #![no_main]
#[no_mangle]
pub unsafe fn main() {
libc::write(1, b"Hello, world\n\0" as *const u8 as *const libc::c_void, 14);
libc::_exit(0);
} does... |
This one again does not include pthread: #![no_main]
#[no_mangle]
pub unsafe fn main() {
libc::syscall(libc::SYS_write, 1, b"Hello, world\n\0" as *const u8 as *const libc::c_void, 14);
libc::_exit(0);
} |
I got rid of pthread by depending on libc with Before that, I noticed that the libc crate functions that led to libpthread being linked in (besides |
@vi In your tiny example, is there a reason you used |
@johnthagen , I don't think Also the example was investigation of when it links to libpthread and when not, so small size wasn't a focus. |
That's the only thing I've heard of. The Cargo reference just says:
|
@vi Looks like the latest https://travis-ci.org/johnthagen/min-sized-rust/jobs/467982878#L498 |
@johnthagen , Indeed: #56092
Fortunately, something like a fix seems to be already available: japaric/xargo#229 japaric/xargo#228. |
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.
@vi Do you know if |
After playing around a bit with this myself, I was able to get this to work by using
|
Is there an issue tracking stabilizing |
I'm also really interested in this but didn't find any just by searching where can we read about progress on that or even if it's planned to stable |
It requires rebuilding the standard library, which means it depends on build-std. |
Currently assertions cause executable to be bloated up by various formatting-related symbols like
, causing executables that carefully choose functions to call in order to stay under X kilobytes to suddenly grow by about 40-150 kilobytes. Additionally,
pthread_*
symbols appear in otherwise single-threaded module. Symbol count may jump by about 800.Shall there be some mode (like
panic = "really-abort"
) or a libstd feature settable inXargo.toml
that makes all panics just do plain raw abort without trying to collect backtrace or print anything at all?The text was updated successfully, but these errors were encountered: