Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable Emscripten's exception handling support #65832

Merged
merged 4 commits into from
Oct 29, 2019
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
4 changes: 4 additions & 0 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/librustc_codegen_llvm/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,6 +73,11 @@ 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");
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_codegen_ssa/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..),
..
Expand Down
11 changes: 2 additions & 9 deletions src/librustc_target/spec/wasm32_unknown_emscripten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/c-variadic.rs
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/drop.rs
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/personality_lifetimes.rs
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/unwind-extern-exports.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/unwind-extern-imports.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/incremental/change_crate_dep_kind.rs
Original file line number Diff line number Diff line change
@@ -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?)
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/box_expr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore-emscripten compiled with panic=abort by default
// ignore-wasm32-bare compiled with panic=abort by default

#![feature(box_syntax)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/generator-storage-dead-unwind.rs
Original file line number Diff line number Diff line change
@@ -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.
//
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/issue-41110.rs
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/issue-62289.rs
Original file line number Diff line number Diff line change
@@ -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)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/no-spurious-drop-after-call.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/packed-struct-drop-aligned.rs
Original file line number Diff line number Diff line change
@@ -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)));
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/remove_fake_borrows.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/retag.rs
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/abi/statics/static-mut-foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/builtin-clone-unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/catch-unwind-bang.rs
Original file line number Diff line number Diff line change
@@ -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!()
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/drop/dynamic-drop-async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/drop/dynamic-drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/generator/panic-drops.rs
Original file line number Diff line number Diff line change
@@ -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)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/generator/panic-safe.rs
Original file line number Diff line number Diff line change
@@ -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)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/generator/resume-after-return.rs
Original file line number Diff line number Diff line change
@@ -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)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-14875.rs
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-29948.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-43853.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-46519.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/iterators/iter-count-overflow-debug.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/iterators/iter-position-overflow-debug.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/iterators/iter-step-overflow-debug.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/iterators/iter-sum-overflow-debug.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/iterators/iter-sum-overflow-overflow-checks.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/macros/macro-comma-behavior-rpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/mir/mir_calls_to_shims.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/mir/mir_drop_order.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/never_type/panic-uninitialized-zeroed.rs
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/panic-runtime/transitive-link-a-bunch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/panic-runtime/want-unwind-got-abort.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/panic-runtime/want-unwind-got-abort2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading