Skip to content

Commit afe74d7

Browse files
committed
Build with -Cpanic=unwind by default
This doesn't enable unwinding as cg_clif doesn't support it yet. It does allow for linking to a cg_llvm compiled libstd.so, which uses `-Cpanic=unwind`.
1 parent 5417278 commit afe74d7

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

build_sysroot/build_sysroot.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ rm -r target/*/{debug,release}/{build,deps,examples,libsysroot*,native} 2>/dev/n
2323
export CARGO_TARGET_DIR=target
2424

2525
# Build libs
26-
export RUSTFLAGS="$RUSTFLAGS -Zforce-unstable-if-unmarked -Cpanic=abort"
26+
export RUSTFLAGS="$RUSTFLAGS -Zforce-unstable-if-unmarked"
2727
export __CARGO_DEFAULT_LIB_METADATA="cg_clif"
2828
if [[ "$1" != "--debug" ]]; then
2929
sysroot_channel='release'

example/alloc_example.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(start, box_syntax, core_intrinsics, alloc_prelude, alloc_error_handler)]
1+
#![feature(start, box_syntax, core_intrinsics, alloc_prelude, alloc_error_handler, lang_items)]
22
#![no_std]
33

44
extern crate alloc;
@@ -27,6 +27,11 @@ fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
2727
core::intrinsics::abort();
2828
}
2929

30+
#[lang = "eh_personality"]
31+
fn eh_personality() -> ! {
32+
loop {}
33+
}
34+
3035
#[start]
3136
fn main(_argc: isize, _argv: *const *const u8) -> isize {
3237
let world: Box<&str> = box "Hello World!\0";

scripts/tests.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ function base_sysroot_tests() {
6161
$RUN_WRAPPER ./target/out/std_example arg
6262

6363
echo "[AOT] subslice-patterns-const-eval"
64-
$MY_RUSTC example/subslice-patterns-const-eval.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
64+
$MY_RUSTC example/subslice-patterns-const-eval.rs --crate-type bin --target "$TARGET_TRIPLE"
6565
$RUN_WRAPPER ./target/out/subslice-patterns-const-eval
6666

6767
echo "[AOT] track-caller-attribute"
68-
$MY_RUSTC example/track-caller-attribute.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
68+
$MY_RUSTC example/track-caller-attribute.rs --crate-type bin --target "$TARGET_TRIPLE"
6969
$RUN_WRAPPER ./target/out/track-caller-attribute
7070

7171
echo "[AOT] mod_bench"

src/bin/cg_clif.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ impl rustc_driver::Callbacks for CraneliftPassesCallbacks {
2424
self.time_passes = config.opts.prints.is_empty()
2525
&& (config.opts.debugging_opts.time_passes || config.opts.debugging_opts.time);
2626

27-
config.opts.cg.panic = Some(PanicStrategy::Abort);
27+
if config.opts.test {
28+
// Unwinding is not yet supported by cg_clif. `-Cpanic=abort` in combination with
29+
// `-Zpanic-abort-tests` ensures that tests are run in a subprocess. This avoids
30+
// crashing the test driver on panics, thereby allowing it to report the error and
31+
// continue with other tests.
32+
config.opts.cg.panic = Some(PanicStrategy::Abort);
33+
// Avoid `-Cprefer-dynamic` in case of `-Cpanic=abort` as that will cause a dynamically
34+
// linked libstd with `-Cpanic=unwind` to be linked in, which isn't allowed.
35+
config.opts.cg.prefer_dynamic = false;
36+
}
2837
config.opts.debugging_opts.panic_abort_tests = true;
2938
config.opts.maybe_sysroot = Some(config.opts.maybe_sysroot.clone().unwrap_or_else(|| {
3039
std::env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_owned()

src/bin/cg_clif_build_sysroot.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ impl rustc_driver::Callbacks for CraneliftPassesCallbacks {
4444
return;
4545
}
4646

47-
config.opts.cg.panic = Some(PanicStrategy::Abort);
47+
if config.opts.crate_name.as_deref() == Some("panic_abort") {
48+
// panic_abort must always be built with `-Cpanic=abort`
49+
config.opts.cg.panic = Some(PanicStrategy::Abort);
50+
}
51+
4852
config.opts.debugging_opts.panic_abort_tests = true;
4953
config.opts.maybe_sysroot =
5054
Some(std::env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_owned());

0 commit comments

Comments
 (0)