Skip to content

Commit a2da749

Browse files
committed
codegen-llvm: never combine DSOLocal and DllImport
Prevent DllImport from being attached to DSOLocal definitions in the LLVM IR. The combination makes no sense, since definitions local to the compilation unit will never be imported from external objects. Additionally, LLVM will refuse the IR if it encounters the combination (introduced in [1]): if (GV.hasDLLImportStorageClass()) Assert(!GV.isDSOLocal(), "GlobalValue with DLLImport Storage is dso_local!", &GV); Right now, codegen-llvm will only apply DllImport to constants and rely on call-stubs for functions. Hence, we simply extend the codegen of constants to skip DllImport for any local definitions. This was discovered when switching the EFI targets to the static relocation model [2]. With this fixed, we can start another attempt at this. [1] https://smlnj-gitlab.cs.uchicago.edu/manticore/llvm/commit/509132b368efed10bbdad825403f45e9cf1d6e38 [2] #101656
1 parent 7fe6f36 commit a2da749

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,18 @@ impl<'ll> CodegenCx<'ll, '_> {
295295
llvm::set_thread_local_mode(g, self.tls_model);
296296
}
297297

298+
let dso_local = unsafe { self.should_assume_dso_local(g, true) };
299+
if dso_local {
300+
unsafe {
301+
llvm::LLVMRustSetDSOLocal(g, true);
302+
}
303+
}
304+
298305
if !def_id.is_local() {
299306
let needs_dll_storage_attr = self.use_dll_storage_attrs && !self.tcx.is_foreign_item(def_id) &&
307+
// Local definitions can never be imported, so we must not apply
308+
// the DLLImport annotation.
309+
!dso_local &&
300310
// ThinLTO can't handle this workaround in all cases, so we don't
301311
// emit the attrs. Instead we make them unnecessary by disallowing
302312
// dynamic linking when linker plugin based LTO is enabled.
@@ -340,12 +350,6 @@ impl<'ll> CodegenCx<'ll, '_> {
340350
}
341351
}
342352

343-
unsafe {
344-
if self.should_assume_dso_local(g, true) {
345-
llvm::LLVMRustSetDSOLocal(g, true);
346-
}
347-
}
348-
349353
self.instances.borrow_mut().insert(instance, g);
350354
g
351355
}

0 commit comments

Comments
 (0)