Skip to content

Commit 87a3bc9

Browse files
authored
Rollup merge of #143293 - folkertdev:naked-function-kcfi, r=compiler-errors
fix `-Zsanitizer=kcfi` on `#[naked]` functions fixes rust-lang/rust#143266 With `-Zsanitizer=kcfi`, indirect calls happen via generated intermediate shim that forwards the call. The generated shim preserves the attributes of the original, including `#[unsafe(naked)]`. The shim is not a naked function though, and violates its invariants (like having a body that consists of a single `naked_asm!` call). My fix here is to match on the `InstanceKind`, and only use `codegen_naked_asm` when the instance is not a `ReifyShim`. That does beg the question whether there are other `InstanceKind`s that could come up. As far as I can tell the answer is no: calling via `dyn` seems to work find, and `#[track_caller]` is disallowed in combination with `#[naked]`. r? codegen ````@rustbot```` label +A-naked cc ````@maurer```` ````@rcvalle````
2 parents 4b5f5dd + 5c1ff5c commit 87a3bc9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
10861086
ecx: &MiriInterpCx<'tcx>,
10871087
instance: ty::Instance<'tcx>,
10881088
) -> InterpResult<'tcx> {
1089-
let attrs = ecx.tcx.codegen_fn_attrs(instance.def_id());
1089+
let attrs = ecx.tcx.codegen_instance_attrs(instance.def);
10901090
if attrs
10911091
.target_features
10921092
.iter()
@@ -1790,7 +1790,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
17901790
ecx.tcx.sess.opts.unstable_opts.cross_crate_inline_threshold,
17911791
InliningThreshold::Always
17921792
) || !matches!(
1793-
ecx.tcx.codegen_fn_attrs(instance.def_id()).inline,
1793+
ecx.tcx.codegen_instance_attrs(instance.def).inline,
17941794
InlineAttr::Never
17951795
);
17961796
!is_generic && !can_be_inlined

0 commit comments

Comments
 (0)