Skip to content

Commit 5320b81

Browse files
committed
fix -Zsanitizer=kcfi on #[naked] functions
And more broadly only codegen `InstanceKind::Item` using the naked function codegen code. Other instance kinds should follow the normal path.
1 parent 08dac6f commit 5320b81

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/driver/aot.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,12 @@ fn codegen_cgu_content(
530530
for (mono_item, item_data) in mono_items {
531531
match mono_item {
532532
MonoItem::Fn(instance) => {
533-
if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED)
534-
{
533+
// Other `InstanceKind`s (e.g. `ReifyShim` generated by indirect calls) should be
534+
// codegened like a normal function.
535+
let is_item_instance = matches!(instance.def, InstanceKind::Item(_));
536+
537+
let flags = tcx.codegen_fn_attrs(instance.def_id()).flags;
538+
if is_item_instance && flags.contains(CodegenFnAttrFlags::NAKED) {
535539
rustc_codegen_ssa::mir::naked_asm::codegen_naked_asm(
536540
&mut GlobalAsmContext { tcx, global_asm: &mut cx.global_asm },
537541
instance,

0 commit comments

Comments
 (0)