about summary refs log tree commit diff
path: root/compiler/rustc_codegen_cranelift/src/driver/mod.rs
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-05-13 13:26:33 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-05-13 13:26:33 +0000
commit75f8bdbca4965896c3d3ead656f6a13e8409a78b (patch)
treed8fba5cd3ad9aee184393d91c0c1b01fc5e76faa /compiler/rustc_codegen_cranelift/src/driver/mod.rs
parentabb95639ef2b837dbfe7b5d18f51fadda29711cb (diff)
parent3270432f4b0583104c8b9b6f695bf97d6bbf3ac2 (diff)
downloadrust-75f8bdbca4965896c3d3ead656f6a13e8409a78b.tar.gz
rust-75f8bdbca4965896c3d3ead656f6a13e8409a78b.zip
Merge commit '3270432f4b0583104c8b9b6f695bf97d6bbf3ac2' into sync_cg_clif-2024-05-13
Diffstat (limited to 'compiler/rustc_codegen_cranelift/src/driver/mod.rs')
-rw-r--r--compiler/rustc_codegen_cranelift/src/driver/mod.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/driver/mod.rs b/compiler/rustc_codegen_cranelift/src/driver/mod.rs
index 12e90b58410..fb0eed07c19 100644
--- a/compiler/rustc_codegen_cranelift/src/driver/mod.rs
+++ b/compiler/rustc_codegen_cranelift/src/driver/mod.rs
@@ -5,6 +5,7 @@
 //! [`codegen_static`]: crate::constant::codegen_static
 
 use rustc_data_structures::profiling::SelfProfilerRef;
+use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
 use rustc_middle::mir::mono::{MonoItem, MonoItemData};
 
 use crate::prelude::*;
@@ -33,7 +34,20 @@ fn predefine_mono_items<'tcx>(
                         data.visibility,
                         is_compiler_builtins,
                     );
-                    module.declare_function(name, linkage, &sig).unwrap();
+                    let is_naked = tcx
+                        .codegen_fn_attrs(instance.def_id())
+                        .flags
+                        .contains(CodegenFnAttrFlags::NAKED);
+                    module
+                        .declare_function(
+                            name,
+                            // Naked functions are defined in a separate object
+                            // file from the codegen unit rustc expects them to
+                            // be defined in.
+                            if is_naked { Linkage::Import } else { linkage },
+                            &sig,
+                        )
+                        .unwrap();
                 }
                 MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
             }