Skip to content

Commit

Permalink
Build with -Cpanic=unwind by default
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
bjorn3 committed Mar 31, 2021
1 parent 5417278 commit afe74d7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build_sysroot/build_sysroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 6 additions & 1 deletion example/alloc_example.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions scripts/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion src/bin/cg_clif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion src/bin/cg_clif_build_sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit afe74d7

Please sign in to comment.