about summary refs log tree commit diff
path: root/src/librustc_codegen_ssa/back/link.rs
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/librustc_codegen_ssa/back/link.rs
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/librustc_codegen_ssa/back/link.rs')
-rw-r--r--src/librustc_codegen_ssa/back/link.rs22
1 files changed, 2 insertions, 20 deletions
diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs
index 8725bfaa025..657dae504b9 100644
--- a/src/librustc_codegen_ssa/back/link.rs
+++ b/src/librustc_codegen_ssa/back/link.rs
@@ -18,10 +18,7 @@ use super::archive::ArchiveBuilder;
 use super::command::Command;
 use super::linker::Linker;
 use super::rpath::{self, RPathConfig};
-use crate::{
-    looks_like_rust_object_file, CodegenResults, CrateInfo, METADATA_FILENAME,
-    RLIB_BYTECODE_EXTENSION,
-};
+use crate::{looks_like_rust_object_file, CodegenResults, CrateInfo, METADATA_FILENAME};
 
 use cc::windows_registry;
 use tempfile::{Builder as TempFileBuilder, TempDir};
@@ -130,10 +127,6 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
                     remove(sess, obj);
                 }
             }
-            for obj in codegen_results.modules.iter().filter_map(|m| m.bytecode_compressed.as_ref())
-            {
-                remove(sess, obj);
-            }
             if let Some(ref metadata_module) = codegen_results.metadata_module {
                 if let Some(ref obj) = metadata_module.object {
                     remove(sess, obj);
@@ -143,9 +136,6 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
                 if let Some(ref obj) = allocator_module.object {
                     remove(sess, obj);
                 }
-                if let Some(ref bc) = allocator_module.bytecode_compressed {
-                    remove(sess, bc);
-                }
             }
         }
     });
@@ -378,14 +368,6 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
             // contain the metadata in a separate file.
             ab.add_file(&emit_metadata(sess, &codegen_results.metadata, tmpdir));
 
-            // For LTO purposes, the bytecode of this library is also inserted
-            // into the archive.
-            for bytecode in
-                codegen_results.modules.iter().filter_map(|m| m.bytecode_compressed.as_ref())
-            {
-                ab.add_file(bytecode);
-            }
-
             // After adding all files to the archive, we need to update the
             // symbol table of the archive. This currently dies on macOS (see
             // #11162), and isn't necessary there anyway
@@ -1829,7 +1811,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
 
             let mut any_objects = false;
             for f in archive.src_files() {
-                if f.ends_with(RLIB_BYTECODE_EXTENSION) || f == METADATA_FILENAME {
+                if f == METADATA_FILENAME {
                     archive.remove_file(&f);
                     continue;
                 }