Skip to content

Commit 114a707

Browse files
committed
Pass wasm exception model to TargetOptions
1 parent 39eb20c commit 114a707

File tree

5 files changed

+11
-2
lines changed

5 files changed

+11
-2
lines changed

compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl OwnedTargetMachine {
3939
debug_info_compression: &CStr,
4040
use_emulated_tls: bool,
4141
args_cstr_buff: &[u8],
42+
use_wasm_eh: bool,
4243
) -> Result<Self, LlvmError<'static>> {
4344
assert!(args_cstr_buff.len() > 0);
4445
assert!(
@@ -72,6 +73,7 @@ impl OwnedTargetMachine {
7273
use_emulated_tls,
7374
args_cstr_buff.as_ptr() as *const c_char,
7475
args_cstr_buff.len(),
76+
use_wasm_eh,
7577
)
7678
};
7779

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_codegen_ssa::back::write::{
1515
BitcodeSection, CodegenContext, EmitObj, ModuleConfig, TargetMachineFactoryConfig,
1616
TargetMachineFactoryFn,
1717
};
18+
use rustc_codegen_ssa::base::wants_wasm_eh;
1819
use rustc_codegen_ssa::traits::*;
1920
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen, ModuleKind};
2021
use rustc_data_structures::profiling::SelfProfilerRef;
@@ -285,6 +286,8 @@ pub(crate) fn target_machine_factory(
285286
let file_name_display_preference =
286287
sess.filename_display_preference(RemapPathScopeComponents::DEBUGINFO);
287288

289+
let use_wasm_eh = wants_wasm_eh(sess);
290+
288291
Arc::new(move |config: TargetMachineFactoryConfig| {
289292
let path_to_cstring_helper = |path: Option<PathBuf>| -> CString {
290293
let path = path.unwrap_or_default();
@@ -321,6 +324,7 @@ pub(crate) fn target_machine_factory(
321324
&debuginfo_compression,
322325
use_emulated_tls,
323326
&args_cstr_buff,
327+
use_wasm_eh,
324328
)
325329
})
326330
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,7 @@ unsafe extern "C" {
24252425
UseEmulatedTls: bool,
24262426
ArgsCstrBuff: *const c_char,
24272427
ArgsCstrBuffLen: usize,
2428+
UseWasmEH: bool,
24282429
) -> *mut TargetMachine;
24292430

24302431
pub(crate) fn LLVMRustDisposeTargetMachine(T: *mut TargetMachine);

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
396396
bool EmitStackSizeSection, bool RelaxELFRelocations, bool UseInitArray,
397397
const char *SplitDwarfFile, const char *OutputObjFile,
398398
const char *DebugInfoCompression, bool UseEmulatedTls,
399-
const char *ArgsCstrBuff, size_t ArgsCstrBuffLen) {
399+
const char *ArgsCstrBuff, size_t ArgsCstrBuffLen, bool UseWasmEH) {
400400

401401
auto OptLevel = fromRust(RustOptLevel);
402402
auto RM = fromRust(RustReloc);
@@ -462,6 +462,9 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
462462
Options.ThreadModel = ThreadModel::Single;
463463
}
464464

465+
if (UseWasmEH)
466+
Options.ExceptionModel = ExceptionHandling::Wasm;
467+
465468
Options.EmitStackSizeSection = EmitStackSizeSection;
466469

467470
if (ArgsCstrBuff != nullptr) {

tests/assembly/wasm_exceptions.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//@ assembly-output: emit-asm
33
//@ compile-flags: -C target-feature=+exception-handling
44
//@ compile-flags: -C panic=unwind
5-
//@ compile-flags: -C llvm-args=-wasm-enable-eh
65

76
#![crate_type = "lib"]
87
#![feature(core_intrinsics)]

0 commit comments

Comments
 (0)