Skip to content

Commit

Permalink
Skip linking if it is not required
Browse files Browse the repository at this point in the history
This allows to use `--emit=metadata,obj` and other metadata
+ non-link combinations.

Fixes #81117.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
  • Loading branch information
ojeda committed Jan 17, 2021
1 parent fc9944f commit f9275e1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
6 changes: 2 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/emit-metadata-obj.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit f9275e1

Please sign in to comment.