From d9531a0d93f63a8e67e56419e0aadf25a0edd43a Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Wed, 7 Jun 2023 21:00:56 +0100 Subject: [PATCH] Remove wrongly emitted `.eh_frame` in `-Cpanic=abort` --- compiler/rustc_mir_transform/src/check_alignment.rs | 7 ++++++- tests/run-make/panic-abort-eh_frame/Makefile | 10 ++++++++++ tests/run-make/panic-abort-eh_frame/foo.rs | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/run-make/panic-abort-eh_frame/Makefile create mode 100644 tests/run-make/panic-abort-eh_frame/foo.rs diff --git a/compiler/rustc_mir_transform/src/check_alignment.rs b/compiler/rustc_mir_transform/src/check_alignment.rs index 1fe8ea0789286..ef64f70fdf349 100644 --- a/compiler/rustc_mir_transform/src/check_alignment.rs +++ b/compiler/rustc_mir_transform/src/check_alignment.rs @@ -9,6 +9,7 @@ use rustc_middle::mir::{ }; use rustc_middle::ty::{Ty, TyCtxt, TypeAndMut}; use rustc_session::Session; +use rustc_target::spec::PanicStrategy; pub struct CheckAlignment; @@ -236,7 +237,11 @@ fn insert_alignment_check<'tcx>( required: Operand::Copy(alignment), found: Operand::Copy(addr), }), - unwind: UnwindAction::Terminate, + unwind: if tcx.sess.panic_strategy() == PanicStrategy::Unwind { + UnwindAction::Terminate + } else { + UnwindAction::Unreachable + }, }, }); } diff --git a/tests/run-make/panic-abort-eh_frame/Makefile b/tests/run-make/panic-abort-eh_frame/Makefile new file mode 100644 index 0000000000000..1cb7bf575cbdf --- /dev/null +++ b/tests/run-make/panic-abort-eh_frame/Makefile @@ -0,0 +1,10 @@ +# only-linux +# +# This test ensures that `panic=abort` code (without `C-unwind`, that is) should not have any +# unwinding related `.eh_frame` sections emitted. + +include ../tools.mk + +all: + $(RUSTC) foo.rs --crate-type=lib --emit=obj=$(TMPDIR)/foo.o -Cpanic=abort + objdump --dwarf=frames $(TMPDIR)/foo.o | $(CGREP) -v 'DW_CFA' diff --git a/tests/run-make/panic-abort-eh_frame/foo.rs b/tests/run-make/panic-abort-eh_frame/foo.rs new file mode 100644 index 0000000000000..e185352945538 --- /dev/null +++ b/tests/run-make/panic-abort-eh_frame/foo.rs @@ -0,0 +1,10 @@ +#![no_std] + +#[panic_handler] +fn handler(_: &core::panic::PanicInfo<'_>) -> ! { + loop {} +} + +pub unsafe fn oops(x: *const u32) -> u32 { + *x +}