about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_codegen_llvm/back/lto.rs6
-rw-r--r--src/librustc_codegen_ssa/back/write.rs16
-rw-r--r--src/test/run-make-fulldeps/reproducible-build/Makefile11
3 files changed, 15 insertions, 18 deletions
diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs
index 5d3cc0c0a25..33b4c8eec54 100644
--- a/src/librustc_codegen_llvm/back/lto.rs
+++ b/src/librustc_codegen_llvm/back/lto.rs
@@ -265,7 +265,7 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
         // and we want to move everything to the same LLVM context. Currently the
         // way we know of to do that is to serialize them to a string and them parse
         // them later. Not great but hey, that's why it's "fat" LTO, right?
-        serialized_modules.extend(modules.into_iter().map(|module| {
+        let mut new_modules = modules.into_iter().map(|module| {
             match module {
                 FatLTOInput::InMemory(module) => {
                     let buffer = ModuleBuffer::new(module.module_llvm.llmod());
@@ -277,7 +277,9 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
                     (SerializedModule::Local(buffer), llmod_id)
                 }
             }
-        }));
+        }).collect::<Vec<_>>();
+        new_modules.sort_by(|module1, module2| module1.1.partial_cmp(&module2.1).unwrap());
+        serialized_modules.extend(new_modules);
         serialized_modules.extend(cached_modules.into_iter().map(|(buffer, wp)| {
             (buffer, CString::new(wp.cgu_name).unwrap())
         }));
diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs
index 2bd46b9f6ef..c9e4663fdbd 100644
--- a/src/librustc_codegen_ssa/back/write.rs
+++ b/src/librustc_codegen_ssa/back/write.rs
@@ -755,15 +755,6 @@ pub enum FatLTOInput<B: WriteBackendMethods> {
     InMemory(ModuleCodegen<B::Module>),
 }
 
-impl<B: WriteBackendMethods> FatLTOInput<B> {
-    fn name(&'a self) -> &'a String {
-        match self {
-            FatLTOInput::Serialized { name, buffer: _ } => &name,
-            FatLTOInput::InMemory(module) => &module.name,
-        }
-    }
-}
-
 fn execute_work_item<B: ExtraBackendMethods>(
     cgcx: &CodegenContext<B>,
     work_item: WorkItem<B>,
@@ -1354,15 +1345,10 @@ fn start_executing_work<B: ExtraBackendMethods>(
                     assert!(!started_lto);
                     started_lto = true;
 
-                    let mut needs_fat_lto: Vec<FatLTOInput<B>> = mem::take(&mut needs_fat_lto);
+                    let needs_fat_lto = mem::take(&mut needs_fat_lto);
                     let needs_thin_lto = mem::take(&mut needs_thin_lto);
                     let import_only_modules = mem::take(&mut lto_import_only_modules);
 
-                    // Regardless of what order these modules completed in, report them to
-                    // the backend in the same order every time to ensure that we're handing
-                    // out deterministic results.
-                    needs_fat_lto.sort_by(|m1, m2| m1.name().cmp(m2.name()));
-
                     for (work, cost) in generate_lto_work(&cgcx, needs_fat_lto,
                                                           needs_thin_lto, import_only_modules) {
                         let insertion_index = work_items
diff --git a/src/test/run-make-fulldeps/reproducible-build/Makefile b/src/test/run-make-fulldeps/reproducible-build/Makefile
index a17ec212cfd..5b9c9d3d035 100644
--- a/src/test/run-make-fulldeps/reproducible-build/Makefile
+++ b/src/test/run-make-fulldeps/reproducible-build/Makefile
@@ -10,7 +10,8 @@ all:  \
 	link_paths \
 	remap_paths \
 	different_source_dirs \
-	extern_flags
+	extern_flags \
+	fat_lto
 
 smoke:
 	rm -rf $(TMPDIR) && mkdir $(TMPDIR)
@@ -76,3 +77,11 @@ extern_flags:
 		--extern reproducible_build_aux=$(TMPDIR)/libbar.rlib \
 		--crate-type rlib
 	cmp "$(TMPDIR)/libreproducible_build.rlib" "$(TMPDIR)/libfoo.rlib" || exit 1
+
+fat_lto:
+	rm -rf $(TMPDIR) && mkdir $(TMPDIR)
+	$(RUSTC) reproducible-build-aux.rs
+	$(RUSTC) reproducible-build.rs -C lto=fat
+	cp $(TMPDIR)/reproducible-build $(TMPDIR)/reproducible-build-a
+	$(RUSTC) reproducible-build.rs -C lto=fat
+	cmp "$(TMPDIR)/reproducible-build-a" "$(TMPDIR)/reproducible-build" || exit 1