1
Fork 0

Apply dllimport in ThinLTO

This commit is contained in:
John Kåre Alsaker 2024-03-20 18:54:01 +01:00
parent 81d8edc200
commit cc39e5f266
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.

View file

@ -1,13 +0,0 @@
use std::sync::atomic::{AtomicPtr, Ordering};
#[inline(always)]
pub fn memrchr() {
fn detect() {}
static CROSS_CRATE_STATIC_ITEM: AtomicPtr<()> = AtomicPtr::new(detect as *mut ());
unsafe {
let fun = CROSS_CRATE_STATIC_ITEM.load(Ordering::SeqCst);
std::mem::transmute::<*mut (), fn()>(fun)()
}
}

View file

@ -1,15 +0,0 @@
//@ compile-flags: -Copt-level=3 -C lto=thin -C prefer-dynamic=no
//@ only-windows
//@ aux-build:static_dllimport_aux.rs
// Test that on Windows, when performing ThinLTO, we do not mark cross-crate static items with
// dllimport because lld does not fix the symbol names for us.
extern crate static_dllimport_aux;
// CHECK-LABEL: @{{.+}}CROSS_CRATE_STATIC_ITEM{{.+}} =
// CHECK-SAME: external local_unnamed_addr global %"{{.+}}AtomicPtr
pub fn main() {
static_dllimport_aux::memrchr();
}