diff options
| author | bors <bors@rust-lang.org> | 2020-07-29 13:58:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-07-29 13:58:19 +0000 |
| commit | 584e83dd5ae7a75b8214560c22eafbcfe153caa6 (patch) | |
| tree | eb24aacddc69ffba99306c244094deaaee69aef6 /src/librustc_codegen_llvm | |
| parent | 06e7b93f6a2a3eeaf80fd6a9a3ef7b180bb5d778 (diff) | |
| parent | 87abd656dabdb97758413b7f4be5bda9be71e26e (diff) | |
| download | rust-584e83dd5ae7a75b8214560c22eafbcfe153caa6.tar.gz rust-584e83dd5ae7a75b8214560c22eafbcfe153caa6.zip | |
Auto merge of #72049 - mati865:mingw-lld, r=petrochenkov
MinGW: enable dllexport/dllimport Fixes (only when using LLD) https://github.com/rust-lang/rust/issues/50176 Fixes https://github.com/rust-lang/rust/issues/72319 This makes `windows-gnu` on pair with `windows-msvc` when it comes to symbol exporting. For MinGW it means both good things like correctly working dllimport/dllexport, ability to link with LLD and bad things like https://github.com/rust-lang/rust/issues/27438. Not sure but maybe this should land behind unstable compiler option (`-Z`) or environment variable?
Diffstat (limited to 'src/librustc_codegen_llvm')
| -rw-r--r-- | src/librustc_codegen_llvm/callee.rs | 7 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/consts.rs | 2 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/context.rs | 15 |
3 files changed, 19 insertions, 5 deletions
diff --git a/src/librustc_codegen_llvm/callee.rs b/src/librustc_codegen_llvm/callee.rs index 75b4f2e3ca5..afdc8dc6187 100644 --- a/src/librustc_codegen_llvm/callee.rs +++ b/src/librustc_codegen_llvm/callee.rs @@ -172,7 +172,12 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value } } - if cx.use_dll_storage_attrs && tcx.is_dllimport_foreign_item(instance_def_id) { + // MinGW: For backward compatibility we rely on the linker to decide whether it + // should use dllimport for functions. + if cx.use_dll_storage_attrs + && tcx.is_dllimport_foreign_item(instance_def_id) + && tcx.sess.target.target.target_env != "gnu" + { unsafe { llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport); } diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index 3e9e5d9c8c1..1288870f55f 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -287,7 +287,7 @@ impl CodegenCx<'ll, 'tcx> { // argument validation. debug_assert!( !(self.tcx.sess.opts.cg.linker_plugin_lto.enabled() - && self.tcx.sess.target.target.options.is_like_msvc + && self.tcx.sess.target.target.options.is_like_windows && self.tcx.sess.opts.cg.prefer_dynamic) ); diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 33a3cdbfa9b..26707fdf839 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -217,7 +217,16 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { // attributes in LLVM IR as well as native dependencies (in C these // correspond to `__declspec(dllimport)`). // - // Whenever a dynamic library is built by MSVC it must have its public + // LD (BFD) in MinGW mode can often correctly guess `dllexport` but + // relying on that can result in issues like #50176. + // LLD won't support that and expects symbols with proper attributes. + // Because of that we make MinGW target emit dllexport just like MSVC. + // When it comes to dllimport we use it for constants but for functions + // rely on the linker to do the right thing. Opposed to dllexport this + // task is easy for them (both LD and LLD) and allows us to easily use + // symbols from static libraries in shared libraries. + // + // Whenever a dynamic library is built on Windows it must have its public // interface specified by functions tagged with `dllexport` or otherwise // they're not available to be linked against. This poses a few problems // for the compiler, some of which are somewhat fundamental, but we use @@ -254,8 +263,8 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { // this effect) by marking very little as `dllimport` and praying the // linker will take care of everything. Fixing this problem will likely // require adding a few attributes to Rust itself (feature gated at the - // start) and then strongly recommending static linkage on MSVC! - let use_dll_storage_attrs = tcx.sess.target.target.options.is_like_msvc; + // start) and then strongly recommending static linkage on Windows! + let use_dll_storage_attrs = tcx.sess.target.target.options.is_like_windows; let check_overflow = tcx.sess.overflow_checks(); |
