Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAllow asserts and panics to abort process quietly. #54981
Comments
This comment has been minimized.
This comment has been minimized.
|
Looks like making Is a pull request about this welcome? |
Havvy
added
the
C-feature-request
label
Oct 11, 2018
vi
added a commit
to vi/rust
that referenced
this issue
Oct 12, 2018
vi
referenced this issue
Oct 12, 2018
Merged
Add libstd Cargo feature "panic_immediate_abort" #55011
vi
added a commit
to vi/rust
that referenced
this issue
Oct 15, 2018
vi
added a commit
to vi/rust
that referenced
this issue
Nov 23, 2018
vi
added a commit
to vi/rust
that referenced
this issue
Nov 29, 2018
bors
added a commit
that referenced
this issue
Nov 30, 2018
kennytm
added a commit
to kennytm/rust
that referenced
this issue
Nov 30, 2018
bors
closed this
in
#55011
Nov 30, 2018
This comment has been minimized.
This comment has been minimized.
|
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. |
RReverser
referenced this issue
Dec 4, 2018
Open
It is way too hard to avoid including panicking and formatting infrastructure code #19
This comment has been minimized.
This comment has been minimized.
rhendric
commented
Dec 9, 2018
|
Hey @vi, I'm so glad you got this in! I followed your instructions above and my binaries are getting smaller. However, |
This comment has been minimized.
This comment has been minimized.
|
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 = falseCommands:
Is it the same for you? |
This comment has been minimized.
This comment has been minimized.
rhendric
commented
Dec 9, 2018
|
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! |
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
|
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);
} |
This comment has been minimized.
This comment has been minimized.
rhendric
commented
Dec 10, 2018
|
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 |
This comment has been minimized.
This comment has been minimized.
|
@vi In your tiny example, is there a reason you used |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
That's the only thing I've heard of. The Cargo reference just says:
|
This comment has been minimized.
This comment has been minimized.
|
@vi Looks like the latest https://travis-ci.org/johnthagen/min-sized-rust/jobs/467982878#L498 |
This comment has been minimized.
This comment has been minimized.
|
@johnthagen , Indeed: #56092
Fortunately, something like a fix seems to be already available: japaric/xargo#229 japaric/xargo#228. |
vi commentedOct 11, 2018
•
edited
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.tomlthat makes all panics just do plain raw abort without trying to collect backtrace or print anything at all?