Skip to content

Commit 8aa2312

Browse files
authored
Rollup merge of rust-lang#65832 - tlively:emscripten-exception-handling, r=alexcrichton
Re-enable Emscripten's exception handling support Passes LLVM codegen and Emscripten link-time flags for exception handling if and only if the panic strategy is `unwind`. Sets the default panic strategy for Emscripten targets to `unwind`. Re-enables tests that depend on unwinding support for Emscripten, including `should_panic` tests. r? @alexcrichton
2 parents c4960c2 + 92c049b commit 8aa2312

File tree

53 files changed

+63
-68
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+63
-68
lines changed

src/bootstrap/native.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ impl Step for TestHelpers {
534534
builder.info("Building test helpers");
535535
t!(fs::create_dir_all(&dst));
536536
let mut cfg = cc::Build::new();
537+
// FIXME: Workaround for https://github.com/emscripten-core/emscripten/issues/9013
538+
if target.contains("emscripten") {
539+
cfg.pic(false);
540+
}
537541

538542
// We may have found various cross-compilers a little differently due to our
539543
// extra configuration, so inform gcc of these compilers. Note, though, that

src/librustc_codegen_llvm/llvm_util.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::llvm;
33
use syntax_pos::symbol::Symbol;
44
use rustc::session::Session;
55
use rustc::session::config::PrintRequest;
6-
use rustc_target::spec::MergeFunctions;
6+
use rustc_target::spec::{MergeFunctions, PanicStrategy};
77
use libc::c_int;
88
use std::ffi::CString;
99
use syntax::feature_gate::UnstableFeatures;
@@ -73,6 +73,11 @@ unsafe fn configure_llvm(sess: &Session) {
7373
}
7474
}
7575

76+
if sess.target.target.target_os == "emscripten" &&
77+
sess.panic_strategy() == PanicStrategy::Unwind {
78+
add("-enable-emscripten-cxx-exceptions");
79+
}
80+
7681
// HACK(eddyb) LLVM inserts `llvm.assume` calls to preserve align attributes
7782
// during inlining. Unfortunately these may block other optimizations.
7883
add("-preserve-alignment-assumptions-during-inlining=false");

src/librustc_codegen_ssa/back/symbol_export.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,9 @@ fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel
364364
codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
365365

366366
if is_extern && !std_internal {
367-
// Emscripten cannot export statics, so reduce their export level here
368-
if tcx.sess.target.target.options.is_like_emscripten {
367+
let target = &tcx.sess.target.target.llvm_target;
368+
// WebAssembly cannot export data symbols, so reduce their export level
369+
if target.contains("wasm32") || target.contains("emscripten") {
369370
if let Some(Node::Item(&hir::Item {
370371
kind: hir::ItemKind::Static(..),
371372
..

src/librustc_target/spec/wasm32_unknown_emscripten.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ pub fn target() -> Result<Target, String> {
99
"-s".to_string(),
1010
"ASSERTIONS=1".to_string(),
1111
"-s".to_string(),
12-
"DISABLE_EXCEPTION_CATCHING=1".to_string(),
13-
"-s".to_string(),
1412
"ABORTING_MALLOC=0".to_string(),
15-
// FIXME(tlively): Enable this linker option once libc type errors
16-
// are resolved. See https://github.com/rust-lang/libc/pull/1478.
17-
// "-Wl,--fatal-warnings".to_string(),
13+
"-Wl,--fatal-warnings".to_string(),
1814
]);
1915

2016
let opts = TargetOptions {
@@ -24,10 +20,7 @@ pub fn target() -> Result<Target, String> {
2420
linker: None,
2521
linker_is_gnu: true,
2622
is_like_emscripten: true,
27-
// FIXME(tlively): Emscripten supports unwinding, but we would have to pass
28-
// -enable-emscripten-cxx-exceptions to LLVM at codegen time and merge
29-
// https://reviews.llvm.org/rG5c3cdef84b82464756bb571c13c31cf7773860c3to use it.
30-
panic_strategy: PanicStrategy::Abort,
23+
panic_strategy: PanicStrategy::Unwind,
3124
post_link_args,
3225
target_family: Some("unix".to_string()),
3326
.. wasm32_base::options()

src/libtest/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,9 @@ pub fn run_test(
441441
) {
442442
let TestDescAndFn { desc, testfn } = test;
443443

444-
// FIXME: Re-enable emscripten once it can catch panics again
444+
// Emscripten can catch panics but other wasm targets cannot
445445
let ignore_because_no_process_support = desc.should_panic != ShouldPanic::No
446-
&& (cfg!(target_arch = "wasm32") || cfg!(target_os = "emscripten"));
446+
&& cfg!(target_arch = "wasm32") && !cfg!(target_os = "emscripten");
447447

448448
if force_ignore || desc.ignore || ignore_because_no_process_support {
449449
let message = CompletedTest::new(desc, TrIgnored, None, Vec::new());

src/test/codegen/c-variadic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ignore-emscripten compiled with panic=abort by default
1+
// ignore-wasm32-bare compiled with panic=abort by default
22
// compile-flags: -C no-prepopulate-passes
33
// ignore-tidy-linelength
44

src/test/codegen/drop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ignore-emscripten compiled with panic=abort by default
1+
// ignore-wasm32-bare compiled with panic=abort by default
22
// compile-flags: -C no-prepopulate-passes
33

44
#![crate_type = "lib"]

src/test/codegen/personality_lifetimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-msvc
2-
// ignore-emscripten compiled with panic=abort by default
2+
// ignore-wasm32-bare compiled with panic=abort by default
33

44
// compile-flags: -O -C no-prepopulate-passes
55

src/test/codegen/unwind-extern-exports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// compile-flags: -C opt-level=0
2-
// ignore-emscripten compiled with panic=abort by default
2+
// ignore-wasm32-bare compiled with panic=abort by default
33

44
#![crate_type = "lib"]
55
#![feature(unwind_attributes)]

src/test/codegen/unwind-extern-imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// compile-flags: -C no-prepopulate-passes
2-
// ignore-emscripten compiled with panic=abort by default
2+
// ignore-wasm32-bare compiled with panic=abort by default
33

44
#![crate_type = "lib"]
55
#![feature(unwind_attributes)]

0 commit comments

Comments
 (0)