From f9275e1092232fcb8ec117fc4acca990f57cba15 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 17 Jan 2021 15:06:47 +0100 Subject: [PATCH] Skip linking if it is not required This allows to use `--emit=metadata,obj` and other metadata + non-link combinations. Fixes #81117. Signed-off-by: Miguel Ojeda --- compiler/rustc_codegen_ssa/src/back/link.rs | 6 ++---- compiler/rustc_session/src/config.rs | 14 ++++++++++++++ src/test/ui/emit-metadata-obj.rs | 7 +++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/emit-metadata-obj.rs diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 728795cf50b85..50a561644dab9 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -74,7 +74,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>( } }); - if outputs.outputs.should_codegen() { + if outputs.outputs.should_link() { let tmpdir = TempFileBuilder::new() .prefix("rustc") .tempdir() @@ -123,9 +123,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>( } }; - if sess.opts.output_types.should_codegen() - && !preserve_objects_for_their_debuginfo(sess) - { + if sess.opts.output_types.should_link() && !preserve_objects_for_their_debuginfo(sess) { for module in &codegen_results.modules { remove_temps_from_module(module); } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 0cafdec1495bb..49833601c9e91 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -403,6 +403,20 @@ impl OutputTypes { OutputType::Metadata | OutputType::DepInfo => false, }) } + + // Returns `true` if any of the output types require linking. + pub fn should_link(&self) -> bool { + self.0.keys().any(|k| match *k { + OutputType::Bitcode + | OutputType::Assembly + | OutputType::LlvmAssembly + | OutputType::Mir + | OutputType::Metadata + | OutputType::Object + | OutputType::DepInfo => false, + OutputType::Exe => true, + }) + } } /// Use tree-based collections to cheaply get a deterministic `Hash` implementation. diff --git a/src/test/ui/emit-metadata-obj.rs b/src/test/ui/emit-metadata-obj.rs new file mode 100644 index 0000000000000..334c7cc5b8101 --- /dev/null +++ b/src/test/ui/emit-metadata-obj.rs @@ -0,0 +1,7 @@ +// compile-flags:--emit=metadata,obj +// build-pass + +// A test for the emission of metadata + obj and other metadata + non-link +// combinations. See issue #81117. + +fn main() {}