Use debuginfo for short backtrace printing #818
Labels
final-comment-period
The FCP has started, most (if not all) team members are in agreement
major-change
A proposal to make a major change to rustc
T-compiler
Add this label so rfcbot knows to poll the compiler team
to-announce
Announce this issue on triage meeting
Proposal
The problem
This MCP is intended to solve rust-lang/rust#124586 in an extensible way.
Currently, short backtrace printing (the part of the default panic handler in std that hides frames like
lang_start
andstd::panicking
) works like this:__rust_{start,end}_short_backtrace
which are marked withinline(never)
.start
frame is encountered.This has two drawbacks:
inline(never)
, they form an optimization barrier, because most of LLVM's optimizations are hamstrung when they can't do inlining.both of these make me reluctant to add more start/end function pairs, because it will hurt performance for everyone using rust and also it's hard to be sure that the panic state machine is working as expected.
Note these drawbacks only to new
__rust_{start,end}
frames. in std itself we only call these functions once, so we don't care about performance, and we are reasonably confident the existing state machine is correct for those two frames.My proposed solution
#[rustc_{start,end}_short_backtrace]
attributes. Use them everywhere except the two existing functions.rustc_{start,end}_backtrace
pairs with debuginfo instead of frames. In other words, any callgraph that goes A -> start_short_backtrace -> B will now go directly A -> B, and B will be annotated with debuginfo marking it appropriately.Additionally, expose a new
#[rustc_skip_short_backtrace]
attribute. When applied to a function, this generates debuginfo that says to skip that frame only, but not to change the state of the panic handler state machine. When applied to a module, this generates debuginfo that says to skip any function defined in that module (e.g. DWARF will useDW_TAG_namespace
).Note that this allows other languages besides Rust to read and write functions marked as skippable, as long as their compiler understands the format we use for the debuginfo.
Drawbacks
Alternatives
__rust_start_short_backtrace
altogether and only use the new attributes. This will regress anyone who was using those frames outside std. It also will break if debuginfo is disabled.#[rustc_skip_short_backtrace]
attribute is represented with debuginfo; start/end attributes are still represented asinline(never)
frames. This avoids missing start/end frames when debuginfo is disabled, but has a slight performance hit anywhere a start/end pair appears.#[rustc_skip_short_backtrace]
to a static injected intostd
that contains a slice of function names (or addresses). Continue using frames for start/end pairs. This is platform independent, but prevents the new attribute from being used anywhere outside std(/alloc/core). Has a small performance hit for start/end pairs. Does not allow other languages to mark frames as skippable, or to read the list of skippable frames.#[global_allocator]
works today.Future work
Mentors or Reviewers
@bjorn3, @saethlin
cc @rust-lang/libs
Process
The main points of the Major Change Process are as follows:
@rustbot second
.-C flag
, then full team check-off is required.@rfcbot fcp merge
on either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
The text was updated successfully, but these errors were encountered: