about summary refs log tree commit diff
path: root/src/test/run-pass/thinlto
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-10-20 23:08:17 +0000
committerbors <bors@rust-lang.org>2017-10-20 23:08:17 +0000
commit6511b4f7ee19fbc2e0dd98fa65f23fa11fece722 (patch)
tree3cee2a75681efe9d782f7045ed55be7a5cd2548b /src/test/run-pass/thinlto
parentb633341c49498488b6e3fce501e23e9f9f8fadec (diff)
parent3541ffb668c3b908aa5e3b6ba8a890d56a8360a7 (diff)
downloadrust-6511b4f7ee19fbc2e0dd98fa65f23fa11fece722.tar.gz
rust-6511b4f7ee19fbc2e0dd98fa65f23fa11fece722.zip
Auto merge of #45348 - alexcrichton:thinlto-timp, r=michaelwoerister
rustc: Add `_imp_` symbols later in compilation

On MSVC targets rustc will add symbols prefixed with `_imp_` to LLVM modules to
"emulate" dllexported statics as that workaround is still in place after #27438
hasn't been solved otherwise. These statics, however, were getting gc'd by
ThinLTO accidentally which later would cause linking failures.

This commit updates the location we add such symbols to happen just before
codegen to ensure that (a) they're not eliminated by the optimizer and (b) the
optimizer doesn't even worry about them.

Closes #45347
Diffstat (limited to 'src/test/run-pass/thinlto')
-rw-r--r--src/test/run-pass/thinlto/auxiliary/msvc-imp-present.rs21
-rw-r--r--src/test/run-pass/thinlto/msvc-imp-present.rs31
2 files changed, 52 insertions, 0 deletions
diff --git a/src/test/run-pass/thinlto/auxiliary/msvc-imp-present.rs b/src/test/run-pass/thinlto/auxiliary/msvc-imp-present.rs
new file mode 100644
index 00000000000..eff7802a245
--- /dev/null
+++ b/src/test/run-pass/thinlto/auxiliary/msvc-imp-present.rs
@@ -0,0 +1,21 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// no-prefer-dynamic
+// compile-flags: -Z thinlto -C codegen-units=8 -C prefer-dynamic
+
+#![crate_type = "rlib"]
+#![crate_type = "dylib"]
+
+pub static A: u32 = 43;
+
+pub mod a {
+    pub static A: u32 = 43;
+}
diff --git a/src/test/run-pass/thinlto/msvc-imp-present.rs b/src/test/run-pass/thinlto/msvc-imp-present.rs
new file mode 100644
index 00000000000..8329c7032f1
--- /dev/null
+++ b/src/test/run-pass/thinlto/msvc-imp-present.rs
@@ -0,0 +1,31 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:msvc-imp-present.rs
+// compile-flags: -Z thinlto -C codegen-units=8
+// min-llvm-version: 4.0
+// no-prefer-dynamic
+
+// On MSVC we have a "hack" where we emit symbols that look like `_imp_$name`
+// for all exported statics. This is done because we apply `dllimport` to all
+// imported constants and this allows everything to actually link correctly.
+//
+// The ThinLTO passes aggressively remove symbols if they can, and this test
+// asserts that the ThinLTO passes don't remove these compiler-generated
+// `_imp_*` symbols. The external library that we link in here is compiled with
+// ThinLTO and multiple codegen units and has a few exported constants. Note
+// that we also namely compile the library as both a dylib and an rlib, but we
+// link the rlib to ensure that we assert those generated symbols exist.
+
+extern crate msvc_imp_present as bar;
+
+fn main() {
+    println!("{}", bar::A);
+}