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.
This commit is contained in:
Thomas Lively 2019-10-18 14:47:54 -07:00
parent 23f890f102
commit 62c3443e96
53 changed files with 62 additions and 68 deletions

View file

@ -534,6 +534,10 @@ impl Step for TestHelpers {
builder.info("Building test helpers");
t!(fs::create_dir_all(&dst));
let mut cfg = cc::Build::new();
// FIXME: Workaround for https://github.com/emscripten-core/emscripten/issues/9013
if target.contains("emscripten") {
cfg.pic(false);
}
// We may have found various cross-compilers a little differently due to our
// extra configuration, so inform gcc of these compilers. Note, though, that

View file

@ -3,7 +3,7 @@ use crate::llvm;
use syntax_pos::symbol::Symbol;
use rustc::session::Session;
use rustc::session::config::PrintRequest;
use rustc_target::spec::MergeFunctions;
use rustc_target::spec::{MergeFunctions, PanicStrategy};
use libc::c_int;
use std::ffi::CString;
use syntax::feature_gate::UnstableFeatures;
@ -73,6 +73,10 @@ unsafe fn configure_llvm(sess: &Session) {
}
}
if sess.target.target.target_os == "emscripten" && sess.panic_strategy() == PanicStrategy::Unwind {
add("-enable-emscripten-cxx-exceptions");
}
// HACK(eddyb) LLVM inserts `llvm.assume` calls to preserve align attributes
// during inlining. Unfortunately these may block other optimizations.
add("-preserve-alignment-assumptions-during-inlining=false");

View file

@ -364,8 +364,9 @@ fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel
codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
if is_extern && !std_internal {
// Emscripten cannot export statics, so reduce their export level here
if tcx.sess.target.target.options.is_like_emscripten {
let target = &tcx.sess.target.target.llvm_target;
// WebAssembly cannot export data symbols, so reduce their export level
if target.contains("wasm32") || target.contains("emscripten") {
if let Some(Node::Item(&hir::Item {
kind: hir::ItemKind::Static(..),
..

View file

@ -9,12 +9,8 @@ pub fn target() -> Result<Target, String> {
"-s".to_string(),
"ASSERTIONS=1".to_string(),
"-s".to_string(),
"DISABLE_EXCEPTION_CATCHING=1".to_string(),
"-s".to_string(),
"ABORTING_MALLOC=0".to_string(),
// FIXME(tlively): Enable this linker option once libc type errors
// are resolved. See https://github.com/rust-lang/libc/pull/1478.
// "-Wl,--fatal-warnings".to_string(),
"-Wl,--fatal-warnings".to_string(),
]);
let opts = TargetOptions {
@ -24,10 +20,7 @@ pub fn target() -> Result<Target, String> {
linker: None,
linker_is_gnu: true,
is_like_emscripten: true,
// FIXME(tlively): Emscripten supports unwinding, but we would have to pass
// -enable-emscripten-cxx-exceptions to LLVM at codegen time and merge
// https://reviews.llvm.org/rG5c3cdef84b82464756bb571c13c31cf7773860c3to use it.
panic_strategy: PanicStrategy::Abort,
panic_strategy: PanicStrategy::Unwind,
post_link_args,
target_family: Some("unix".to_string()),
.. wasm32_base::options()

View file

@ -441,9 +441,9 @@ pub fn run_test(
) {
let TestDescAndFn { desc, testfn } = test;
// FIXME: Re-enable emscripten once it can catch panics again
// Emscripten can catch panics but other wasm targets cannot
let ignore_because_no_process_support = desc.should_panic != ShouldPanic::No
&& (cfg!(target_arch = "wasm32") || cfg!(target_os = "emscripten"));
&& cfg!(target_arch = "wasm32") && !cfg!(target_os = "emscripten");
if force_ignore || desc.ignore || ignore_because_no_process_support {
let message = CompletedTest::new(desc, TrIgnored, None, Vec::new());

View file

@ -1,4 +1,4 @@
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -C no-prepopulate-passes
// ignore-tidy-linelength

View file

@ -1,4 +1,4 @@
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -C no-prepopulate-passes
#![crate_type = "lib"]

View file

@ -1,5 +1,5 @@
// ignore-msvc
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -O -C no-prepopulate-passes

View file

@ -1,5 +1,5 @@
// compile-flags: -C opt-level=0
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![crate_type = "lib"]
#![feature(unwind_attributes)]

View file

@ -1,5 +1,5 @@
// compile-flags: -C no-prepopulate-passes
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![crate_type = "lib"]
#![feature(unwind_attributes)]

View file

@ -1,7 +1,7 @@
// Test that we detect changes to the `dep_kind` query. If the change is not
// detected then -Zincremental-verify-ich will trigger an assertion.
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// revisions:cfail1 cfail2
// compile-flags: -Z query-dep-graph -Cpanic=unwind
// build-pass (FIXME(62277): could be check-pass?)

View file

@ -1,4 +1,4 @@
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(box_syntax)]

View file

@ -1,4 +1,4 @@
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// Test that we generate StorageDead on unwind paths for generators.
//

View file

@ -1,4 +1,4 @@
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// check that we don't emit multiple drop flags when they are not needed.

View file

@ -1,7 +1,7 @@
// check that we don't forget to drop the Box if we early return before
// initializing it
// ignore-tidy-linelength
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(box_syntax)]

View file

@ -1,4 +1,4 @@
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// Test that after the call to `std::mem::drop` we do not generate a
// MIR drop of the argument. (We used to have a `DROP(_2)` in the code

View file

@ -1,4 +1,4 @@
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
fn main() {
let mut x = Packed(Aligned(Droppy(0)));

View file

@ -1,6 +1,6 @@
// Test that the fake borrows for matches are removed after borrow checking.
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
fn match_guard(x: Option<&&i32>, c: bool) -> i32 {
match x {

View file

@ -1,4 +1,4 @@
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// ignore-tidy-linelength
// compile-flags: -Z mir-emit-retag -Z mir-opt-level=0 -Z span_free_formats

View file

@ -5,10 +5,6 @@
// ignore-wasm32-bare no libc to test ffi with
// FIXME: This will work on emscripten once libc is updated to include
// rust-lang/libc/#1478
// ignore-emscripten libc type mismatch
#![feature(rustc_private)]
extern crate libc;

View file

@ -2,7 +2,7 @@
// Check that partially moved from function parameters are dropped after the
// named bindings that move from them.
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
use std::{panic, cell::RefCell};

View file

@ -2,7 +2,7 @@
#![allow(unused_variables)]
#![allow(unused_imports)]
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// Test that builtin implementations of `Clone` cleanup everything
// in case of unwinding.

View file

@ -1,5 +1,5 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
fn worker() -> ! {
panic!()

View file

@ -5,7 +5,7 @@
// run-pass
// edition:2018
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(slice_patterns)]
#![allow(unused)]

View file

@ -2,7 +2,7 @@
#![allow(unused_assignments)]
#![allow(unused_variables)]
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(generators, generator_trait, untagged_unions)]
#![feature(slice_patterns)]

View file

@ -1,4 +1,4 @@
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -C no-prepopulate-passes -Cpasses=name-anon-globals
#![crate_type = "lib"]

View file

@ -1,6 +1,6 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(generators, generator_trait)]

View file

@ -1,6 +1,6 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(generators, generator_trait)]

View file

@ -1,6 +1,6 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(generators, generator_trait)]

View file

@ -1,5 +1,5 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// Check that values are not leaked when a dtor panics (#14875)

View file

@ -1,5 +1,5 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
use std::panic;

View file

@ -1,5 +1,5 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
use std::panic;

View file

@ -1,7 +1,7 @@
// run-pass
// compile-flags:--test -O
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#[test]
#[should_panic(expected = "creating inhabited type")]

View file

@ -1,6 +1,6 @@
// run-pass
// only-32bit too impatient for 2⁶⁴ items
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -C debug_assertions=yes -C opt-level=3
use std::panic;

View file

@ -1,6 +1,6 @@
// run-pass
// only-32bit too impatient for 2⁶⁴ items
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -C debug_assertions=yes -C opt-level=3
use std::panic;

View file

@ -1,5 +1,5 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -C debug_assertions=yes
use std::panic;

View file

@ -1,5 +1,5 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -C debug_assertions=yes
use std::panic;

View file

@ -1,5 +1,5 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -C overflow-checks
use std::panic;

View file

@ -13,7 +13,7 @@
// compile-flags: --test -C debug_assertions=yes
// revisions: std core
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![cfg_attr(core, no_std)]

View file

@ -1,5 +1,5 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(fn_traits)]
#![feature(never_type)]

View file

@ -1,5 +1,5 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
use std::cell::RefCell;
use std::panic;

View file

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

View file

@ -1,6 +1,6 @@
// run-pass
// compile-flags: -C debug_assertions=yes
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// ignore-emscripten dies with an LLVM error
use std::panic;

View file

@ -4,7 +4,7 @@
// aux-build:wants-panic-runtime-abort.rs
// aux-build:panic-runtime-lang-items.rs
// error-pattern: is not compiled with this crate's panic strategy `unwind`
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![no_std]
#![no_main]

View file

@ -1,7 +1,7 @@
// error-pattern:is incompatible with this crate's strategy of `unwind`
// aux-build:panic-runtime-abort.rs
// aux-build:panic-runtime-lang-items.rs
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![no_std]
#![no_main]

View file

@ -2,7 +2,7 @@
// aux-build:panic-runtime-abort.rs
// aux-build:wants-panic-runtime-abort.rs
// aux-build:panic-runtime-lang-items.rs
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![no_std]
#![no_main]

View file

@ -1,7 +1,7 @@
// run-pass
// aux-build:expand-with-a-macro.rs
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![deny(warnings)]

View file

@ -1,5 +1,5 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// aux-build:reachable-unnameable-items.rs
extern crate reachable_unnameable_items;

View file

@ -1,7 +1,7 @@
// compile-flags: --test
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(test)]

View file

@ -1,5 +1,5 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
#![allow(dead_code, unreachable_code)]

View file

@ -1,5 +1,5 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: --test
#![feature(allow_fail)]

View file

@ -1,5 +1,5 @@
// run-pass
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: --test
#[test]
#[should_panic(expected = "foo")]

View file

@ -141,10 +141,6 @@ impl EarlyProps {
if config.target == "wasm32-unknown-unknown" && config.parse_check_run_results(ln) {
props.ignore = Ignore::Ignore;
}
// FIXME: Re-enable run-fail once panics are handled correctly
if config.target.contains("emscripten") && config.mode == common::RunFail {
props.ignore = Ignore::Ignore;
}
}
if (config.mode == common::DebugInfoGdb || config.mode == common::DebugInfoGdbLldb) &&