Skip to content

Commit c572326

Browse files
authored
Rollup merge of rust-lang#117744 - quininer:add-z-sync-uw, r=bjorn3
Add -Zuse-sync-unwind Currently Rust uses async unwind by default, but async unwind will bring non-negligible size overhead. it would be nice to allow users to choose this. In addition, async unwind currently prevents LLVM from generate compact unwind for MachO, if one wishes to generate compact unwind for MachO, then also needs this flag.
2 parents ca663b0 + 12784c3 commit c572326

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
@@ -1960,6 +1960,8 @@ written to standard error output)"),
19601960
"adds unstable command line options to rustc interface (default: no)"),
19611961
use_ctors_section: Option<bool> = (None, parse_opt_bool, [TRACKED],
19621962
"use legacy .ctors section for initializers rather than .init_array"),
1963+
use_sync_unwind: Option<bool> = (None, parse_opt_bool, [TRACKED],
1964+
"Generate sync unwind tables instead of async unwind tables (default: no)"),
19631965
validate_mir: bool = (false, parse_bool, [UNTRACKED],
19641966
"validate MIR after each transformation"),
19651967
#[rustc_lint_opt_deny_field_access("use `Session::verbose_internals` instead of this field")]

0 commit comments

Comments
 (0)