about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm/lib.rs
diff options
context:
space:
mode:
authorVictor Ding <victording@google.com>2019-12-21 21:37:15 +1100
committerVictor Ding <victording@google.com>2020-01-23 11:00:36 +1100
commit6a6ebb4403683e1e12d3916cabc1a4898ce798cf (patch)
tree855442fe1710ff235f8ea29628dce81581b1f5e3 /src/librustc_codegen_llvm/lib.rs
parentd1e594f4029c6ac8feb7c2acf9f9e04c1b9c493c (diff)
downloadrust-6a6ebb4403683e1e12d3916cabc1a4898ce798cf.tar.gz
rust-6a6ebb4403683e1e12d3916cabc1a4898ce798cf.zip
Add `-Z no-link` flag
Adds a compiler option to allow rustc compile a crate without linking.
With this flag, rustc serializes codegen_results into a .rlink file.
Diffstat (limited to 'src/librustc_codegen_llvm/lib.rs')
-rw-r--r--src/librustc_codegen_llvm/lib.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs
index a6168128c4d..70e3874035b 100644
--- a/src/librustc_codegen_llvm/lib.rs
+++ b/src/librustc_codegen_llvm/lib.rs
@@ -33,6 +33,7 @@ use rustc_codegen_ssa::CompiledModule;
 use rustc_errors::{FatalError, Handler};
 use std::any::Any;
 use std::ffi::CStr;
+use std::fs;
 use std::sync::Arc;
 use syntax::expand::allocator::AllocatorKind;
 
@@ -44,6 +45,7 @@ use rustc::ty::{self, TyCtxt};
 use rustc::util::common::ErrorReported;
 use rustc_codegen_ssa::ModuleCodegen;
 use rustc_codegen_utils::codegen_backend::CodegenBackend;
+use rustc_serialize::json;
 
 mod back {
     pub mod archive;
@@ -298,6 +300,18 @@ impl CodegenBackend for LlvmCodegenBackend {
             return Ok(());
         }
 
+        if sess.opts.debugging_opts.no_link {
+            // FIXME: use a binary format to encode the `.rlink` file
+            let rlink_data = json::encode(&codegen_results).map_err(|err| {
+                sess.fatal(&format!("failed to encode rlink: {}", err));
+            })?;
+            let rlink_file = outputs.with_extension("rlink");
+            fs::write(&rlink_file, rlink_data).map_err(|err| {
+                sess.fatal(&format!("failed to write file {}: {}", rlink_file.display(), err));
+            })?;
+            return Ok(());
+        }
+
         // Run the linker on any artifacts that resulted from the LLVM run.
         // This should produce either a finished executable or library.
         sess.time("link_crate", || {