about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2020-04-23 11:45:55 -0700
committerAlex Crichton <alex@alexcrichton.com>2020-04-29 11:57:26 -0700
commitef89cc8f042a980e72e9d0262c267bfffd9e75fe (patch)
tree82cc2d96faf8edf01975f5858876c4d16fb9b461 /src/test
parent413a12909f3b149af17d75268ed4a136afb82c36 (diff)
downloadrust-ef89cc8f042a980e72e9d0262c267bfffd9e75fe.tar.gz
rust-ef89cc8f042a980e72e9d0262c267bfffd9e75fe.zip
Store LLVM bitcode in object files, not compressed
This commit is an attempted resurrection of #70458 where LLVM bitcode
emitted by rustc into rlibs is stored into object file sections rather
than in a separate file. The main rationale for doing this is that when
rustc emits bitcode it will no longer use a custom compression scheme
which makes it both easier to interoperate with existing tools and also
cuts down on compile time since this compression isn't happening.

The blocker for this in #70458 turned out to be that native linkers
didn't handle the new sections well, causing the sections to either
trigger bugs in the linker or actually end up in the final linked
artifact. This commit attempts to address these issues by ensuring that
native linkers ignore the new sections by inserting custom flags with
module-level inline assembly.

Note that this does not currently change the API of the compiler at all.
The pre-existing `-C bitcode-in-rlib` flag is co-opted to indicate
whether the bitcode should be present in the object file or not.

Finally, note that an important consequence of this commit, which is also
one of its primary purposes, is to enable rustc's `-Clto` bitcode
loading to load rlibs produced with `-Clinker-plugin-lto`. The goal here
is that when you're building with LTO Cargo will tell rustc to skip
codegen of all intermediate crates and only generate LLVM IR. Today
rustc will generate both object code and LLVM IR, but the object code is
later simply thrown away, wastefully.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/auxiliary/lto-rustc-loads-linker-plugin.rs6
-rw-r--r--src/test/ui/lto-duplicate-symbols.stderr2
-rw-r--r--src/test/ui/lto-rustc-loads-linker-plugin.rs17
-rw-r--r--src/test/ui/lto-thin-rustc-loads-linker-plugin.rs13
4 files changed, 37 insertions, 1 deletions
diff --git a/src/test/ui/auxiliary/lto-rustc-loads-linker-plugin.rs b/src/test/ui/auxiliary/lto-rustc-loads-linker-plugin.rs
new file mode 100644
index 00000000000..d24375b2d0a
--- /dev/null
+++ b/src/test/ui/auxiliary/lto-rustc-loads-linker-plugin.rs
@@ -0,0 +1,6 @@
+// compile-flags: -Clinker-plugin-lto
+// no-prefer-dynamic
+
+#![crate_type = "rlib"]
+
+pub fn foo() {}
diff --git a/src/test/ui/lto-duplicate-symbols.stderr b/src/test/ui/lto-duplicate-symbols.stderr
index 02204830120..713b79bae32 100644
--- a/src/test/ui/lto-duplicate-symbols.stderr
+++ b/src/test/ui/lto-duplicate-symbols.stderr
@@ -1,6 +1,6 @@
 warning: Linking globals named 'foo': symbol multiply defined!
 
-error: failed to load bc of "lto_duplicate_symbols2.3a1fbbbh-cgu.0": 
+error: failed to load bc of "lto-duplicate-symbols2.lto_duplicate_symbols2.3a1fbbbh-cgu.0.rcgu.o": 
 
 error: aborting due to previous error; 1 warning emitted
 
diff --git a/src/test/ui/lto-rustc-loads-linker-plugin.rs b/src/test/ui/lto-rustc-loads-linker-plugin.rs
new file mode 100644
index 00000000000..6ef1d4540b8
--- /dev/null
+++ b/src/test/ui/lto-rustc-loads-linker-plugin.rs
@@ -0,0 +1,17 @@
+// compile-flags: -C lto
+// aux-build:lto-rustc-loads-linker-plugin.rs
+// run-pass
+// no-prefer-dynamic
+
+// This test ensures that if a dependency was compiled with
+// `-Clinker-plugin-lto` then we can compile with `-Clto` and still link against
+// that upstream rlib. This should work because LTO implies we're not actually
+// linking against upstream rlibs since we're generating the object code
+// locally. This test will fail if rustc can't find bytecode in rlibs compiled
+// with `-Clinker-plugin-lto`.
+
+extern crate lto_rustc_loads_linker_plugin;
+
+fn main() {
+    lto_rustc_loads_linker_plugin::foo();
+}
diff --git a/src/test/ui/lto-thin-rustc-loads-linker-plugin.rs b/src/test/ui/lto-thin-rustc-loads-linker-plugin.rs
new file mode 100644
index 00000000000..4d54ce32fb5
--- /dev/null
+++ b/src/test/ui/lto-thin-rustc-loads-linker-plugin.rs
@@ -0,0 +1,13 @@
+// compile-flags: -C lto=thin
+// aux-build:lto-rustc-loads-linker-plugin.rs
+// run-pass
+// no-prefer-dynamic
+
+// Same as the adjacent `lto-thin-rustc-loads-linker-plugin.rs` test, only with
+// ThinLTO.
+
+extern crate lto_rustc_loads_linker_plugin;
+
+fn main() {
+    lto_rustc_loads_linker_plugin::foo();
+}