Skip to content

Commit

Permalink
Apply dllimport in ThinLTO for -Z dylib-lto
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Mar 20, 2024
1 parent a128516 commit 3d83ca4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,20 @@ impl<'ll> CodegenCx<'ll, '_> {
}

if !def_id.is_local() {
// Workaround an LLD bug with importing static symbols triggered by ThinLTO if we're
// not using -Z dylib-lto. Note this workaround may not be sound for crate graphs
// with dylibs.
let workaround_lld_bug =
self.tcx.sess.lto() == Lto::Thin && !self.tcx.sess.opts.unstable_opts.dylib_lto;

let needs_dll_storage_attr = self.use_dll_storage_attrs && !self.tcx.is_foreign_item(def_id) &&
// Local definitions can never be imported, so we must not apply
// the DLLImport annotation.
!dso_local &&
// ThinLTO can't handle this workaround in all cases, so we don't
// emit the attrs. Instead we make them unnecessary by disallowing
// dynamic linking when linker plugin based LTO is enabled.
!self.tcx.sess.opts.cg.linker_plugin_lto.enabled() &&
self.tcx.sess.lto() != Lto::Thin;
!self.tcx.sess.opts.cg.linker_plugin_lto.enabled() && !workaround_lld_bug;

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

0 comments on commit 3d83ca4

Please sign in to comment.