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

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

+4
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

+6-1
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

+3-2
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

+2-9
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

+2-2
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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)]

src/test/incremental/change_crate_dep_kind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Test that we detect changes to the `dep_kind` query. If the change is not
22
// detected then -Zincremental-verify-ich will trigger an assertion.
33

4-
// ignore-emscripten compiled with panic=abort by default
4+
// ignore-wasm32-bare compiled with panic=abort by default
55
// revisions:cfail1 cfail2
66
// compile-flags: -Z query-dep-graph -Cpanic=unwind
77
// build-pass (FIXME(62277): could be check-pass?)

src/test/mir-opt/box_expr.rs

+1-1
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

33
#![feature(box_syntax)]
44

src/test/mir-opt/generator-storage-dead-unwind.rs

+1-1
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

33
// Test that we generate StorageDead on unwind paths for generators.
44
//

src/test/mir-opt/issue-41110.rs

+1-1
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

33
// check that we don't emit multiple drop flags when they are not needed.
44

src/test/mir-opt/issue-62289.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// check that we don't forget to drop the Box if we early return before
22
// initializing it
33
// ignore-tidy-linelength
4-
// ignore-emscripten compiled with panic=abort by default
4+
// ignore-wasm32-bare compiled with panic=abort by default
55

66
#![feature(box_syntax)]
77

src/test/mir-opt/no-spurious-drop-after-call.rs

+1-1
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

33
// Test that after the call to `std::mem::drop` we do not generate a
44
// MIR drop of the argument. (We used to have a `DROP(_2)` in the code

src/test/mir-opt/packed-struct-drop-aligned.rs

+1-1
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

33
fn main() {
44
let mut x = Packed(Aligned(Droppy(0)));

src/test/mir-opt/remove_fake_borrows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test that the fake borrows for matches are removed after borrow checking.
22

3-
// ignore-emscripten compiled with panic=abort by default
3+
// ignore-wasm32-bare compiled with panic=abort by default
44

55
fn match_guard(x: Option<&&i32>, c: bool) -> i32 {
66
match x {

src/test/mir-opt/retag.rs

+1-1
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
// ignore-tidy-linelength
33
// compile-flags: -Z mir-emit-retag -Z mir-opt-level=0 -Z span_free_formats
44

src/test/ui/abi/statics/static-mut-foreign.rs

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55

66
// ignore-wasm32-bare no libc to test ffi with
77

8-
// FIXME: This will work on emscripten once libc is updated to include
9-
// rust-lang/libc/#1478
10-
// ignore-emscripten libc type mismatch
11-
128
#![feature(rustc_private)]
139

1410
extern crate libc;

src/test/ui/binding/fn-arg-incomplete-pattern-drop-order.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Check that partially moved from function parameters are dropped after the
33
// named bindings that move from them.
44

5-
// ignore-emscripten compiled with panic=abort by default
5+
// ignore-wasm32-bare compiled with panic=abort by default
66

77
use std::{panic, cell::RefCell};
88

src/test/ui/builtin-clone-unwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#![allow(unused_variables)]
44
#![allow(unused_imports)]
5-
// ignore-emscripten compiled with panic=abort by default
5+
// ignore-wasm32-bare compiled with panic=abort by default
66

77
// Test that builtin implementations of `Clone` cleanup everything
88
// in case of unwinding.

src/test/ui/catch-unwind-bang.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// ignore-emscripten compiled with panic=abort by default
2+
// ignore-wasm32-bare compiled with panic=abort by default
33

44
fn worker() -> ! {
55
panic!()

src/test/ui/drop/dynamic-drop-async.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// run-pass
77
// edition:2018
8-
// ignore-emscripten compiled with panic=abort by default
8+
// ignore-wasm32-bare compiled with panic=abort by default
99

1010
#![feature(slice_patterns)]
1111
#![allow(unused)]

src/test/ui/drop/dynamic-drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(unused_assignments)]
33
#![allow(unused_variables)]
44

5-
// ignore-emscripten compiled with panic=abort by default
5+
// ignore-wasm32-bare compiled with panic=abort by default
66

77
#![feature(generators, generator_trait, untagged_unions)]
88
#![feature(slice_patterns)]

src/test/ui/feature-gates/feature-gate-unwind-attributes.rs

+1-1
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 -Cpasses=name-anon-globals
33

44
#![crate_type = "lib"]

src/test/ui/generator/panic-drops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
22

3-
// ignore-emscripten compiled with panic=abort by default
3+
// ignore-wasm32-bare compiled with panic=abort by default
44

55
#![feature(generators, generator_trait)]
66

src/test/ui/generator/panic-safe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
22

3-
// ignore-emscripten compiled with panic=abort by default
3+
// ignore-wasm32-bare compiled with panic=abort by default
44

55
#![feature(generators, generator_trait)]
66

src/test/ui/generator/resume-after-return.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
22

3-
// ignore-emscripten compiled with panic=abort by default
3+
// ignore-wasm32-bare compiled with panic=abort by default
44

55
#![feature(generators, generator_trait)]
66

src/test/ui/issues/issue-14875.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// ignore-emscripten compiled with panic=abort by default
2+
// ignore-wasm32-bare compiled with panic=abort by default
33

44
// Check that values are not leaked when a dtor panics (#14875)
55

src/test/ui/issues/issue-29948.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// ignore-emscripten compiled with panic=abort by default
2+
// ignore-wasm32-bare compiled with panic=abort by default
33

44
use std::panic;
55

src/test/ui/issues/issue-43853.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// ignore-emscripten compiled with panic=abort by default
2+
// ignore-wasm32-bare compiled with panic=abort by default
33

44
use std::panic;
55

src/test/ui/issues/issue-46519.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// run-pass
22
// compile-flags:--test -O
33

4-
// ignore-emscripten compiled with panic=abort by default
4+
// ignore-wasm32-bare compiled with panic=abort by default
55

66
#[test]
77
#[should_panic(expected = "creating inhabited type")]

src/test/ui/iterators/iter-count-overflow-debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
22
// only-32bit too impatient for 2⁶⁴ items
3-
// ignore-emscripten compiled with panic=abort by default
3+
// ignore-wasm32-bare compiled with panic=abort by default
44
// compile-flags: -C debug_assertions=yes -C opt-level=3
55

66
use std::panic;

src/test/ui/iterators/iter-position-overflow-debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
22
// only-32bit too impatient for 2⁶⁴ items
3-
// ignore-emscripten compiled with panic=abort by default
3+
// ignore-wasm32-bare compiled with panic=abort by default
44
// compile-flags: -C debug_assertions=yes -C opt-level=3
55

66
use std::panic;

src/test/ui/iterators/iter-step-overflow-debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// ignore-emscripten compiled with panic=abort by default
2+
// ignore-wasm32-bare compiled with panic=abort by default
33
// compile-flags: -C debug_assertions=yes
44

55
use std::panic;

src/test/ui/iterators/iter-sum-overflow-debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// ignore-emscripten compiled with panic=abort by default
2+
// ignore-wasm32-bare compiled with panic=abort by default
33
// compile-flags: -C debug_assertions=yes
44

55
use std::panic;

src/test/ui/iterators/iter-sum-overflow-overflow-checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// ignore-emscripten compiled with panic=abort by default
2+
// ignore-wasm32-bare compiled with panic=abort by default
33
// compile-flags: -C overflow-checks
44

55
use std::panic;

src/test/ui/macros/macro-comma-behavior-rpass.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// compile-flags: --test -C debug_assertions=yes
1414
// revisions: std core
1515

16-
// ignore-emscripten compiled with panic=abort by default
16+
// ignore-wasm32-bare compiled with panic=abort by default
1717

1818
#![cfg_attr(core, no_std)]
1919

src/test/ui/mir/mir_calls_to_shims.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// ignore-emscripten compiled with panic=abort by default
2+
// ignore-wasm32-bare compiled with panic=abort by default
33

44
#![feature(fn_traits)]
55
#![feature(never_type)]

src/test/ui/mir/mir_drop_order.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// ignore-emscripten compiled with panic=abort by default
2+
// ignore-wasm32-bare compiled with panic=abort by default
33

44
use std::cell::RefCell;
55
use std::panic;

src/test/ui/never_type/panic-uninitialized-zeroed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// ignore-emscripten compiled with panic=abort by default
2+
// ignore-wasm32-bare compiled with panic=abort by default
33
// This test checks that instantiating an uninhabited type via `mem::{uninitialized,zeroed}` results
44
// in a runtime panic.
55

src/test/ui/numbers-arithmetic/next-power-of-two-overflow-debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
22
// compile-flags: -C debug_assertions=yes
3-
// ignore-emscripten compiled with panic=abort by default
3+
// ignore-wasm32-bare compiled with panic=abort by default
44
// ignore-emscripten dies with an LLVM error
55

66
use std::panic;

src/test/ui/panic-runtime/transitive-link-a-bunch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// aux-build:wants-panic-runtime-abort.rs
55
// aux-build:panic-runtime-lang-items.rs
66
// error-pattern: is not compiled with this crate's panic strategy `unwind`
7-
// ignore-emscripten compiled with panic=abort by default
7+
// ignore-wasm32-bare compiled with panic=abort by default
88

99
#![no_std]
1010
#![no_main]

src/test/ui/panic-runtime/want-unwind-got-abort.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// error-pattern:is incompatible with this crate's strategy of `unwind`
22
// aux-build:panic-runtime-abort.rs
33
// aux-build:panic-runtime-lang-items.rs
4-
// ignore-emscripten compiled with panic=abort by default
4+
// ignore-wasm32-bare compiled with panic=abort by default
55

66
#![no_std]
77
#![no_main]

src/test/ui/panic-runtime/want-unwind-got-abort2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// aux-build:panic-runtime-abort.rs
33
// aux-build:wants-panic-runtime-abort.rs
44
// aux-build:panic-runtime-lang-items.rs
5-
// ignore-emscripten compiled with panic=abort by default
5+
// ignore-wasm32-bare compiled with panic=abort by default
66

77
#![no_std]
88
#![no_main]

0 commit comments

Comments
 (0)