You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsC-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.
A short backtrace for this panic would ideally include only std::panicking::begin_panic and foo::main. And, indeed, the implementing PR has a test for this output:
rustc -O -C debuginfo=1 (release mode with debuginfo)
0: std::panicking::begin_panic
at ./.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:505
1: foo::main
at ./foo.rs:2
2: core::ops::function::FnOnce::call_once
at ./.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227
So I think the __rust_begin_short_backtrace implementation needs to account for this extra stack frame when it isn't optimized out by release mode. The test mentioned above only passes because it's compiled with -O:
We were aware that the invoking closure is inlined on some platforms but not on others — see #75048 (comment) and subsequent comments. Not sure that there's much value in overriding optimisations to force consistency on this minor point? Cc @michaelwoerister
I reported this since it was a bit confusing that the Rust announcement post itself included the irrelevant (to the end user) call_once line. It seems unfortunate to me that debug mode has the more confusing backtrace in this case — I probably use backtraces most often during development, without optimizations.
This would go away if lang_start would be generic over main's type as F: FnOnce() -> R instead of taking a fn pointer, right? If you use -Z symbol-mangling-version=v0, you can see that the "inlined sometimes" call_once is <fn() as core::ops::function::FnOnce<()>>::call_once, i.e. the shim for calling a fn pointer via FnOnce.
One nice thing would that is we could theoretically allow varying not just main's return type, but also argument counts/types (which frankly I don't know why it hasn't come up before?).
LeSeulArtichaut
added
A-runtime
Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
labels
Oct 9, 2020
Enselic
changed the title
Implementation detail exposed in short backtrace (RUST_BACKTRACE=1)
Short backtrace sometimes includes unnecessary core::ops::function::FnOnce::call_once line
Dec 16, 2023
A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsC-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.
Given this file
foo.rs
:A short backtrace for this panic would ideally include only
std::panicking::begin_panic
andfoo::main
. And, indeed, the implementing PR has a test for this output:rust/src/test/ui/panics/issue-47429-short-backtraces.run.stderr
Lines 1 to 5 in 5792840
However, this is how the backtrace actually looks with various flags:
rustc
(no flags; debug mode)rustc -O
(release mode)rustc -O -C debuginfo=1
(release mode with debuginfo)So I think the
__rust_begin_short_backtrace
implementation needs to account for this extra stack frame when it isn't optimized out by release mode. The test mentioned above only passes because it's compiled with-O
:rust/src/test/ui/panics/issue-47429-short-backtraces.rs
Line 3 in 5792840
I tested this on 1.47.0 stable and a nightly version:
rustc --version --verbose
ref #75048
cc @eggyal
The text was updated successfully, but these errors were encountered: