about summary refs log tree commit diff
path: root/compiler/rustc_monomorphize/src/lib.rs
diff options
context:
space:
mode:
authorBen Kimock <kimockb@gmail.com>2024-04-01 20:17:12 -0400
committerBen Kimock <kimockb@gmail.com>2024-04-01 20:31:19 -0400
commit748dba2bafab14117f626348b716a824d301cffd (patch)
treeaa9edf10cdbc5a752a8f98dcbcb6625409ec4b69 /compiler/rustc_monomorphize/src/lib.rs
parent395f780cd8da001b35d7e588177bbad82d5cf8fa (diff)
downloadrust-748dba2bafab14117f626348b716a824d301cffd.tar.gz
rust-748dba2bafab14117f626348b716a824d301cffd.zip
Only allow upstream calls to LLVM intrinsics, not any link_name function
Diffstat (limited to 'compiler/rustc_monomorphize/src/lib.rs')
-rw-r--r--compiler/rustc_monomorphize/src/lib.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/compiler/rustc_monomorphize/src/lib.rs b/compiler/rustc_monomorphize/src/lib.rs
index 9c4a6e69a3c..2a91d69529a 100644
--- a/compiler/rustc_monomorphize/src/lib.rs
+++ b/compiler/rustc_monomorphize/src/lib.rs
@@ -14,6 +14,7 @@ use rustc_middle::ty::adjustment::CustomCoerceUnsized;
 use rustc_middle::ty::Instance;
 use rustc_middle::ty::TyCtxt;
 use rustc_middle::ty::{self, Ty};
+use rustc_span::def_id::DefId;
 use rustc_span::def_id::LOCAL_CRATE;
 use rustc_span::ErrorGuaranteed;
 
@@ -57,13 +58,24 @@ fn custom_coerce_unsize_info<'tcx>(
 /// linkers will optimize such that dead calls to unresolved symbols are not an error, but this is
 /// not guaranteed. So we used this function in codegen backends to ensure we do not generate any
 /// unlinkable calls.
+///
+/// Note that calls to LLVM intrinsics are uniquely okay because they won't make it to the linker.
 pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
     tcx: TyCtxt<'tcx>,
     instance: Instance<'tcx>,
 ) -> bool {
-    !instance.def_id().is_local()
+    fn is_llvm_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
+        if let Some(name) = tcx.codegen_fn_attrs(def_id).link_name {
+            name.as_str().starts_with("llvm.")
+        } else {
+            false
+        }
+    }
+
+    let def_id = instance.def_id();
+    !def_id.is_local()
         && tcx.is_compiler_builtins(LOCAL_CRATE)
-        && tcx.codegen_fn_attrs(instance.def_id()).link_name.is_none()
+        && !is_llvm_intrinsic(tcx, def_id)
         && !should_codegen_locally(tcx, instance)
 }