Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ pub(crate) fn uwtable_attr(llcx: &llvm::Context, use_sync_unwind: Option<bool>)
// NOTE: We should determine if we even need async unwind tables, as they
// take have more overhead and if we can use sync unwind tables we
// probably should.
//
// Similar logic exists for the per-module uwtable annotation in `context.rs`.
let async_unwind = !use_sync_unwind.unwrap_or(false);
llvm::CreateUWTableAttr(llcx, async_unwind)
}
Expand Down
19 changes: 19 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,25 @@ pub(crate) unsafe fn create_module<'ll>(
);
}

if sess.must_emit_unwind_tables() {
// This assertion checks that Max is the correct merge behavior.
// Async unwind tables are strictly more useful than sync uwtables.
const {
assert!((llvm::UWTableKind::None as u32) < (llvm::UWTableKind::Sync as u32));
assert!((llvm::UWTableKind::Sync as u32) < (llvm::UWTableKind::Async as u32));
}

llvm::add_module_flag_u32(
llmod,
llvm::ModuleFlagMergeBehavior::Max,
"uwtable",
match sess.opts.unstable_opts.use_sync_unwind {
Some(true) => llvm::UWTableKind::Sync as u32,
Some(false) | None => llvm::UWTableKind::Async as u32,
},
);
}

// Add "kcfi" module flag if KCFI is enabled. (See https://reviews.llvm.org/D119296.)
if sess.is_sanitizer_kcfi_enabled() {
llvm::add_module_flag_u32(llmod, llvm::ModuleFlagMergeBehavior::Override, "kcfi", 1);
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@ pub(crate) enum DLLStorageClass {
DllExport = 2, // Function to be accessible from DLL.
}

/// Must match the layout of `llvm::UWTableKind`.
#[derive(Copy, Clone)]
#[repr(C)]
pub(crate) enum UWTableKind {
/// No unwind table requested
None = 0,
/// "Synchronous" unwind tables
Sync = 1,
/// "Asynchronous" unwind tables (instr precise)
Async = 2,
}

/// Must match the layout of `LLVMRustAttributeKind`.
/// Semantically a subset of the C++ enum llvm::Attribute::AttrKind,
/// though it is not ABI compatible (since it's a C++ enum)
Expand Down
2 changes: 2 additions & 0 deletions tests/codegen-llvm/force-no-unwind-tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
fn foo() {
panic!();
}

// CHECK-NOT: !"uwtable"
2 changes: 2 additions & 0 deletions tests/codegen-llvm/force-unwind-tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

// CHECK: attributes #{{.*}} uwtable
pub fn foo() {}

// CHECK: !{{[0-9]+}} = !{i32 7, !"uwtable", i32 2}
Loading