about summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xbuild_sysroot/build_sysroot.sh2
-rw-r--r--example/alloc_example.rs7
-rwxr-xr-xscripts/tests.sh4
-rw-r--r--src/bin/cg_clif.rs11
-rw-r--r--src/bin/cg_clif_build_sysroot.rs6
5 files changed, 24 insertions, 6 deletions
diff --git a/build_sysroot/build_sysroot.sh b/build_sysroot/build_sysroot.sh
index 0354304e55b..cc1cbf1abc2 100755
--- a/build_sysroot/build_sysroot.sh
+++ b/build_sysroot/build_sysroot.sh
@@ -23,7 +23,7 @@ rm -r target/*/{debug,release}/{build,deps,examples,libsysroot*,native} 2>/dev/n
 export CARGO_TARGET_DIR=target
 
 # Build libs
-export RUSTFLAGS="$RUSTFLAGS -Zforce-unstable-if-unmarked -Cpanic=abort"
+export RUSTFLAGS="$RUSTFLAGS -Zforce-unstable-if-unmarked"
 export __CARGO_DEFAULT_LIB_METADATA="cg_clif"
 if [[ "$1" != "--debug" ]]; then
     sysroot_channel='release'
diff --git a/example/alloc_example.rs b/example/alloc_example.rs
index 71e93e87b6c..b58d90cb5ae 100644
--- a/example/alloc_example.rs
+++ b/example/alloc_example.rs
@@ -1,4 +1,4 @@
-#![feature(start, box_syntax, core_intrinsics, alloc_prelude, alloc_error_handler)]
+#![feature(start, box_syntax, core_intrinsics, alloc_prelude, alloc_error_handler, lang_items)]
 #![no_std]
 
 extern crate alloc;
@@ -27,6 +27,11 @@ fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
     core::intrinsics::abort();
 }
 
+#[lang = "eh_personality"]
+fn eh_personality() -> ! {
+    loop {}
+}
+
 #[start]
 fn main(_argc: isize, _argv: *const *const u8) -> isize {
     let world: Box<&str> = box "Hello World!\0";
diff --git a/scripts/tests.sh b/scripts/tests.sh
index 3afcea8f06b..05139c185f2 100755
--- a/scripts/tests.sh
+++ b/scripts/tests.sh
@@ -61,11 +61,11 @@ function base_sysroot_tests() {
     $RUN_WRAPPER ./target/out/std_example arg
 
     echo "[AOT] subslice-patterns-const-eval"
-    $MY_RUSTC example/subslice-patterns-const-eval.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
+    $MY_RUSTC example/subslice-patterns-const-eval.rs --crate-type bin --target "$TARGET_TRIPLE"
     $RUN_WRAPPER ./target/out/subslice-patterns-const-eval
 
     echo "[AOT] track-caller-attribute"
-    $MY_RUSTC example/track-caller-attribute.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
+    $MY_RUSTC example/track-caller-attribute.rs --crate-type bin --target "$TARGET_TRIPLE"
     $RUN_WRAPPER ./target/out/track-caller-attribute
 
     echo "[AOT] mod_bench"
diff --git a/src/bin/cg_clif.rs b/src/bin/cg_clif.rs
index 983839d48d2..0d73834f165 100644
--- a/src/bin/cg_clif.rs
+++ b/src/bin/cg_clif.rs
@@ -24,7 +24,16 @@ impl rustc_driver::Callbacks for CraneliftPassesCallbacks {
         self.time_passes = config.opts.prints.is_empty()
             && (config.opts.debugging_opts.time_passes || config.opts.debugging_opts.time);
 
-        config.opts.cg.panic = Some(PanicStrategy::Abort);
+        if config.opts.test {
+            // Unwinding is not yet supported by cg_clif. `-Cpanic=abort` in combination with
+            // `-Zpanic-abort-tests` ensures that tests are run in a subprocess. This avoids
+            // crashing the test driver on panics, thereby allowing it to report the error and
+            // continue with other tests.
+            config.opts.cg.panic = Some(PanicStrategy::Abort);
+            // Avoid `-Cprefer-dynamic` in case of `-Cpanic=abort` as that will cause a dynamically
+            // linked libstd with `-Cpanic=unwind` to be linked in, which isn't allowed.
+            config.opts.cg.prefer_dynamic = false;
+        }
         config.opts.debugging_opts.panic_abort_tests = true;
         config.opts.maybe_sysroot = Some(config.opts.maybe_sysroot.clone().unwrap_or_else(|| {
             std::env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_owned()
diff --git a/src/bin/cg_clif_build_sysroot.rs b/src/bin/cg_clif_build_sysroot.rs
index e7cd5edbbf6..70e41f9997e 100644
--- a/src/bin/cg_clif_build_sysroot.rs
+++ b/src/bin/cg_clif_build_sysroot.rs
@@ -44,7 +44,11 @@ impl rustc_driver::Callbacks for CraneliftPassesCallbacks {
             return;
         }
 
-        config.opts.cg.panic = Some(PanicStrategy::Abort);
+        if config.opts.crate_name.as_deref() == Some("panic_abort") {
+            // panic_abort must always be built with `-Cpanic=abort`
+            config.opts.cg.panic = Some(PanicStrategy::Abort);
+        }
+
         config.opts.debugging_opts.panic_abort_tests = true;
         config.opts.maybe_sysroot =
             Some(std::env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_owned());