about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorFolkert de Vries <folkert@folkertdev.nl>2025-07-01 20:02:31 +0200
committerFolkert de Vries <folkert@folkertdev.nl>2025-07-16 21:38:48 +0200
commitf100767dce1fcc0287047053cc29659ac5321a6b (patch)
tree87c54ef57c6e3134a2a7cc8a14b442084b5b5e10 /compiler/rustc_codegen_ssa/src
parent9c3064e131f4939cc95a29bb11413c49bbda1491 (diff)
downloadrust-f100767dce1fcc0287047053cc29659ac5321a6b.tar.gz
rust-f100767dce1fcc0287047053cc29659ac5321a6b.zip
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.
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/mono_item.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mono_item.rs b/compiler/rustc_codegen_ssa/src/mono_item.rs
index 7b4268abe4b..fa0ef04b2e6 100644
--- a/compiler/rustc_codegen_ssa/src/mono_item.rs
+++ b/compiler/rustc_codegen_ssa/src/mono_item.rs
@@ -1,5 +1,6 @@
 use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
 use rustc_middle::mir::mono::{Linkage, MonoItem, MonoItemData, Visibility};
+use rustc_middle::ty::InstanceKind;
 use rustc_middle::ty::layout::HasTyCtxt;
 use tracing::debug;
 
@@ -41,12 +42,12 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
                 base::codegen_global_asm(cx, item_id);
             }
             MonoItem::Fn(instance) => {
-                if cx
-                    .tcx()
-                    .codegen_fn_attrs(instance.def_id())
-                    .flags
-                    .contains(CodegenFnAttrFlags::NAKED)
-                {
+                // Other `InstanceKind`s (e.g. `ReifyShim` generated by indirect calls) should be
+                // codegened like a normal function.
+                let is_item_instance = matches!(instance.def, InstanceKind::Item(_));
+
+                let flags = cx.tcx().codegen_fn_attrs(instance.def_id()).flags;
+                if is_item_instance && flags.contains(CodegenFnAttrFlags::NAKED) {
                     naked_asm::codegen_naked_asm::<Bx::CodegenCx>(cx, instance, item_data);
                 } else {
                     base::codegen_instance::<Bx>(cx, instance);