Skip to content

Commit

Permalink
Create safe helper for LLVMSetDLLStorageClass
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Feb 20, 2025
1 parent eeb9035 commit ea71808
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 2 additions & 4 deletions compiler/rustc_codegen_llvm/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
// LLVM will prefix the name with `__imp_`. Ideally, we'd like the
// existing logic below to set the Storage Class, but it has an
// exemption for MinGW for backwards compatibility.
unsafe {
llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport);
}
llvm::set_dllimport_storage_class(llfn);
llfn
} else {
cx.declare_fn(sym, fn_abi, Some(instance))
Expand Down Expand Up @@ -150,7 +148,7 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
&& library.kind.is_dllimport()
&& !matches!(tcx.sess.target.env.as_ref(), "gnu" | "uclibc")
{
llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport);
llvm::set_dllimport_storage_class(llfn);
}

if cx.should_assume_dso_local(llfn, true) {
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,7 @@ impl<'ll> CodegenCx<'ll, '_> {
// is actually present in the current crate. We can find out via the
// is_codegened_item query.
if !self.tcx.is_codegened_item(def_id) {
unsafe {
llvm::LLVMSetDLLStorageClass(g, llvm::DLLStorageClass::DllImport);
}
llvm::set_dllimport_storage_class(g);
}
}
}
Expand All @@ -387,9 +385,7 @@ impl<'ll> CodegenCx<'ll, '_> {
&& library.kind.is_dllimport()
{
// For foreign (native) libs we know the exact storage type to use.
unsafe {
llvm::LLVMSetDLLStorageClass(g, llvm::DLLStorageClass::DllImport);
}
llvm::set_dllimport_storage_class(g);
}

self.instances.borrow_mut().insert(instance, g);
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,9 @@ pub(crate) fn add_module_flag_str(
);
}
}

pub(crate) fn set_dllimport_storage_class<'ll>(v: &'ll Value) {
unsafe {
LLVMSetDLLStorageClass(v, DLLStorageClass::DllImport);
}
}

0 comments on commit ea71808

Please sign in to comment.