Test fixing raw-dylib

This commit is contained in:
Daniel Paoliello 2024-09-19 15:00:30 -07:00
parent 13a5097796
commit b2fd8a0192
7 changed files with 95 additions and 55 deletions

View file

@ -49,6 +49,22 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
let llfn = if tcx.sess.target.arch == "x86"
&& let Some(dllimport) = crate::common::get_dllimport(tcx, instance_def_id, sym)
{
// When calling functions in generated import libraries, MSVC needs
// the fully decorated name (as would have been in the declaring
// object file), but MinGW wants the name as exported (as would be
// in the def file) which may be missing decorations.
let mingw_gnu_toolchain = common::is_mingw_gnu_toolchain(&tcx.sess.target);
let llfn = cx.declare_fn(
&common::i686_decorated_name(
dllimport,
mingw_gnu_toolchain,
true,
!mingw_gnu_toolchain,
),
fn_abi,
Some(instance),
);
// Fix for https://github.com/rust-lang/rust/issues/104453
// On x86 Windows, LLVM uses 'L' as the prefix for any private
// global symbols, so when we create an undecorated function symbol
@ -60,15 +76,6 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
// LLVM will prefix the name with `__imp_`. Ideally, we'd like the
// existing logic below to set the Storage Class, but it has an
// exemption for MinGW for backwards compatibility.
let llfn = cx.declare_fn(
&common::i686_decorated_name(
dllimport,
common::is_mingw_gnu_toolchain(&tcx.sess.target),
true,
),
fn_abi,
Some(instance),
);
unsafe {
llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport);
}

View file

@ -196,16 +196,10 @@ fn check_and_apply_linkage<'ll, 'tcx>(
g2
}
} else if cx.tcx.sess.target.arch == "x86"
&& common::is_mingw_gnu_toolchain(&cx.tcx.sess.target)
&& let Some(dllimport) = crate::common::get_dllimport(cx.tcx, def_id, sym)
{
cx.declare_global(
&common::i686_decorated_name(
dllimport,
common::is_mingw_gnu_toolchain(&cx.tcx.sess.target),
true,
),
llty,
)
cx.declare_global(&common::i686_decorated_name(dllimport, true, true, false), llty)
} else {
// Generate an external declaration.
// FIXME(nagisa): investigate whether it can be changed into define_global