Skip to content

Commit 12784c3

Browse files
committed
Add -Zuse-sync-unwind
This flag specifies whether LLVM generates async unwind or sync unwind.
1 parent fcfe05a commit 12784c3

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

compiler/rustc_codegen_llvm/src/allocator.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ fn create_wrapper_function(
134134
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
135135
}
136136
if tcx.sess.must_emit_unwind_tables() {
137-
let uwtable = attributes::uwtable_attr(llcx);
137+
let uwtable =
138+
attributes::uwtable_attr(llcx, tcx.sess.opts.unstable_opts.use_sync_unwind);
138139
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &[uwtable]);
139140
}
140141

compiler/rustc_codegen_llvm/src/attributes.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ pub fn sanitize_attrs<'ll>(
9595

9696
/// Tell LLVM to emit or not emit the information necessary to unwind the stack for the function.
9797
#[inline]
98-
pub fn uwtable_attr(llcx: &llvm::Context) -> &Attribute {
98+
pub fn uwtable_attr(llcx: &llvm::Context, use_sync_unwind: Option<bool>) -> &Attribute {
9999
// NOTE: We should determine if we even need async unwind tables, as they
100100
// take have more overhead and if we can use sync unwind tables we
101101
// probably should.
102-
llvm::CreateUWTableAttr(llcx, true)
102+
let async_unwind = !use_sync_unwind.unwrap_or(false);
103+
llvm::CreateUWTableAttr(llcx, async_unwind)
103104
}
104105

105106
pub fn frame_pointer_type_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
@@ -333,7 +334,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
333334
// You can also find more info on why Windows always requires uwtables here:
334335
// https://bugzilla.mozilla.org/show_bug.cgi?id=1302078
335336
if cx.sess().must_emit_unwind_tables() {
336-
to_add.push(uwtable_attr(cx.llcx));
337+
to_add.push(uwtable_attr(cx.llcx, cx.sess().opts.unstable_opts.use_sync_unwind));
337338
}
338339

339340
if cx.sess().opts.unstable_opts.profile_sample_use.is_some() {

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1991,6 +1991,8 @@ written to standard error output)"),
19911991
"adds unstable command line options to rustc interface (default: no)"),
19921992
use_ctors_section: Option<bool> = (None, parse_opt_bool, [TRACKED],
19931993
"use legacy .ctors section for initializers rather than .init_array"),
1994+
use_sync_unwind: Option<bool> = (None, parse_opt_bool, [TRACKED],
1995+
"Generate sync unwind tables instead of async unwind tables (default: no)"),
19941996
validate_mir: bool = (false, parse_bool, [UNTRACKED],
19951997
"validate MIR after each transformation"),
19961998
#[rustc_lint_opt_deny_field_access("use `Session::verbose_internals` instead of this field")]

0 commit comments

Comments
 (0)