Rollup merge of #147488 - AMS21:remove_llvm_rust_insert_private_global, r=nikic

refactor: Remove `LLVMRustInsertPrivateGlobal` and `define_private_global`

Since it can easily be implemented using the existing LLVM C API in
terms of `LLVMAddGlobal` and `LLVMSetLinkage` and `define_private_global`
was only used in one place.

Work towards https://github.com/rust-lang/rust/issues/46437
This commit is contained in:
Stuart Cook 2025-10-09 18:43:26 +11:00 committed by GitHub
commit 4dfd977c8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 4 additions and 16 deletions

View file

@ -240,11 +240,13 @@ impl<'ll> CodegenCx<'ll, '_> {
let gv = self.define_global(&name, self.val_ty(cv)).unwrap_or_else(|| {
bug!("symbol `{}` is already defined", name);
});
llvm::set_linkage(gv, llvm::Linkage::PrivateLinkage);
gv
}
_ => self.define_private_global(self.val_ty(cv)),
_ => self.define_global("", self.val_ty(cv)).unwrap_or_else(|| {
bug!("anonymous global symbol is already defined");
}),
};
llvm::set_linkage(gv, llvm::Linkage::PrivateLinkage);
llvm::set_initializer(gv, cv);
set_global_alignment(self, gv, align);
llvm::set_unnamed_address(gv, llvm::UnnamedAddr::Global);

View file

@ -230,13 +230,6 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
}
}
/// Declare a private global
///
/// Use this function when you intend to define a global without a name.
pub(crate) fn define_private_global(&self, ty: &'ll Type) -> &'ll Value {
unsafe { llvm::LLVMRustInsertPrivateGlobal(self.llmod(), ty) }
}
/// Gets declared value by name.
pub(crate) fn get_declared_value(&self, name: &str) -> Option<&'ll Value> {
debug!("get_declared_value(name={:?})", name);

View file

@ -1955,7 +1955,6 @@ unsafe extern "C" {
NameLen: size_t,
T: &'a Type,
) -> &'a Value;
pub(crate) fn LLVMRustInsertPrivateGlobal<'a>(M: &'a Module, T: &'a Type) -> &'a Value;
pub(crate) fn LLVMRustGetNamedValue(
M: &Module,
Name: *const c_char,

View file

@ -205,12 +205,6 @@ extern "C" LLVMValueRef LLVMRustGetOrInsertGlobal(LLVMModuleRef M,
return wrap(GV);
}
extern "C" LLVMValueRef LLVMRustInsertPrivateGlobal(LLVMModuleRef M,
LLVMTypeRef Ty) {
return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
GlobalValue::PrivateLinkage, nullptr));
}
// Must match the layout of `rustc_codegen_llvm::llvm::ffi::AttributeKind`.
enum class LLVMRustAttributeKind {
AlwaysInline = 0,