From 6d2d47b2fc73b7beacced1f2a62037193ea1ed30 Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Fri, 5 Sep 2014 14:30:36 -0700 Subject: [PATCH] don't use `ld -r` with `-C codegen-units=1` --- src/librustc/back/write.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/librustc/back/write.rs b/src/librustc/back/write.rs index 506d3585016..627d455f06e 100644 --- a/src/librustc/back/write.rs +++ b/src/librustc/back/write.rs @@ -476,6 +476,9 @@ pub fn run_passes(sess: &Session, sess.fatal("can't perform LTO when using multiple codegen units"); } + // Sanity check + assert!(trans.modules.len() == sess.opts.cg.codegen_units); + unsafe { configure_llvm(sess); } @@ -607,6 +610,15 @@ pub fn run_passes(sess: &Session, }; let link_obj = |output_path: &Path| { + // Running `ld -r` on a single input is kind of pointless. + if sess.opts.cg.codegen_units == 1 { + fs::copy(&crate_output.with_extension("0.o"), + output_path).unwrap(); + // Leave the .0.o file around, to mimic the behavior of the normal + // code path. + return; + } + // Some builds of MinGW GCC will pass --force-exe-suffix to ld, which // will automatically add a .exe extension if the extension is not // already .exe or .dll. To ensure consistent behavior on Windows, we