Rollup merge of #122790 - Zoxc:dllimp-rev, r=ChrisDenton

Apply dllimport in ThinLTO

This partially reverts https://github.com/rust-lang/rust/pull/103353 by properly applying `dllimport` if  `-Z dylib-lto` is passed. That PR should probably fully be reverted as it looks quite sketchy. We don't know locally if the entire crate graph would be statically linked.

This should hopefully be sufficient to make ThinLTO work for rustc on Windows.

r? ``@wesleywiser``

---

Edit: This PR is changed to just generally revert https://github.com/rust-lang/rust/pull/103353.
This commit is contained in:
Matthias Krüger 2025-03-09 16:41:48 +01:00 committed by GitHub
commit 827bb5e27b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 34 deletions

View file

@ -16,7 +16,6 @@ use rustc_middle::mir::mono::MonoItem;
use rustc_middle::ty::Instance;
use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf};
use rustc_middle::{bug, span_bug};
use rustc_session::config::Lto;
use tracing::{debug, instrument, trace};
use crate::common::{AsCCharPtr, CodegenCx};
@ -344,11 +343,11 @@ impl<'ll> CodegenCx<'ll, '_> {
// 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;
// Linker plugin ThinLTO doesn't create the self-dllimport Rust uses for rlibs
// as the code generation happens out of process. Instead we assume static linkage
// and disallow dynamic linking when linker plugin based LTO is enabled.
// Regular in-process ThinLTO doesn't need this workaround.
&& !self.tcx.sess.opts.cg.linker_plugin_lto.enabled();
// If this assertion triggers, there's something wrong with commandline
// argument validation.