Skip to content

Commit 3d83ca4

Browse files
committed
Apply dllimport in ThinLTO for -Z dylib-lto
1 parent a128516 commit 3d83ca4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,20 @@ impl<'ll> CodegenCx<'ll, '_> {
302302
}
303303

304304
if !def_id.is_local() {
305+
// Workaround an LLD bug with importing static symbols triggered by ThinLTO if we're
306+
// not using -Z dylib-lto. Note this workaround may not be sound for crate graphs
307+
// with dylibs.
308+
let workaround_lld_bug =
309+
self.tcx.sess.lto() == Lto::Thin && !self.tcx.sess.opts.unstable_opts.dylib_lto;
310+
305311
let needs_dll_storage_attr = self.use_dll_storage_attrs && !self.tcx.is_foreign_item(def_id) &&
306312
// Local definitions can never be imported, so we must not apply
307313
// the DLLImport annotation.
308314
!dso_local &&
309315
// ThinLTO can't handle this workaround in all cases, so we don't
310316
// emit the attrs. Instead we make them unnecessary by disallowing
311317
// dynamic linking when linker plugin based LTO is enabled.
312-
!self.tcx.sess.opts.cg.linker_plugin_lto.enabled() &&
313-
self.tcx.sess.lto() != Lto::Thin;
318+
!self.tcx.sess.opts.cg.linker_plugin_lto.enabled() && !workaround_lld_bug;
314319

315320
// If this assertion triggers, there's something wrong with commandline
316321
// argument validation.

0 commit comments

Comments
 (0)