Skip to content

Commit

Permalink
Rollup merge of #112403 - nbdd0121:eh_frame, r=Nilstrieb
Browse files Browse the repository at this point in the history
Prevent `.eh_frame` from being emitted for `-C panic=abort`

Since `CheckAlignment` pass is after the `AbortUnwindingCalls` pass, the `UnwindAction::Terminate` inserted in it has no chance to be converted to `UnwindAction::Unreachable` anymore, causing us to emit landing pads that are not necessary. Although these landing pads can themselves be eliminated by LLVM, `.eh_frame` sections are still generated. This causes trouble for Rust-for-Linux project recently.

This PR changes it to generate `UnwindAction::Terminate` when we opt for `-Cpanic=unwind`, and `UnwindAction::Unreachable` for `-Cpanic=abort`.

`@ojeda`
  • Loading branch information
GuillaumeGomez authored Jun 15, 2023
2 parents 331249a + d9531a0 commit ab314a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/rustc_mir_transform/src/check_alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
},
},
});
}
10 changes: 10 additions & 0 deletions tests/run-make/panic-abort-eh_frame/Makefile
Original file line number Diff line number Diff line change
@@ -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'
10 changes: 10 additions & 0 deletions tests/run-make/panic-abort-eh_frame/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![no_std]

#[panic_handler]
fn handler(_: &core::panic::PanicInfo<'_>) -> ! {
loop {}
}

pub unsafe fn oops(x: *const u32) -> u32 {
*x
}

0 comments on commit ab314a5

Please sign in to comment.