-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Remove libstd's calls to C-unwind
foreign functions
#97033
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
Conversation
This ensures that there are no calls to `C-unwind` function in libunwind.
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
(rust-highfive has picked a reviewer for you, use r? to override) |
These all depend on the rust abi happening to match up with the abi rustc expects for the respective functions. Rustc generates shim functions calling or defining them which don't go through the standard abi handling code. |
Well, given rustc_codegen_llvm/allocator.rs actually uses the same LLVM type for the function definition and the call, we already require and expect the ABI to match up anyway. |
r? @Amanieu perhaps? This seems OK, but I'd like another set of eyes on it at least. In general the restrictions / unsoundness from mixing panic={abort,unwind} and extern "C" and "C-unwind" feel pretty worrisome to me, but it may be non-avoidable unfortunately. It sounds like in practice this comes down to std being wrongly compiled in panic=unwind mode when used by panic=abort crates, so it may be that we should be investing in making that not the case -- it seems like it shouldn't be impossible for us to distribute two copies of std, though it would come at unfortunate increase in Rust install sizes probably. So maybe this approach is best. I do think we need the lints referenced in the description to make it viable, though. |
What about |
The |
On its own this change is fine. Whether it is sufficient will be clearer once the followup PR is ready. @bors r+ |
📌 Commit fbb3c19 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (50872bd): comparison url. Summary: Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression Footnotes |
The follow-up is ready at #97235 |
Remove all libstd and its dependencies' usage of
extern "C-unwind"
.This is a prerequiste of a WIP PR which will forbid libraries calling
extern "C-unwind"
functions to be compiled in-Cpanic=unwind
and linked againstpanic_abort
(this restriction is necessary to address soundness bug #96926).Cargo will ensure all crates are compiled with the same
-Cpanic
but the std is only compiled-Cpanic=unwind
but needs the ability to be linked into-Cpanic=abort
.Currently there are two places where
C-unwind
is used in libstd:__rust_start_panic
is used for interfacing to the panic runtime. This could beextern "Rust"
_{rdl,rg}_oom
: a shim__rust_alloc_error_handler
will be generated by codegen to call into one of these; they can also beextern "Rust"
(in fact, the generated shim is used asextern "Rust"
, so I am not even sure why these are not, probably because they used toextern "C"
and was changed toextern "C-unwind"
when we allow alloc error hooks to unwind, but they really should just be using Rust ABI).For dependencies, there is only one
extern "C-unwind"
function call, inunwind
crate. This can be expressed as a re-export.More dicussions can be seen in the Zulip thread: https://rust-lang.zulipchat.com/#narrow/stream/210922-project-ffi-unwind/topic/soundness.20in.20mixed.20panic.20mode
@rustbot label: T-libs F-c_unwind