From ffa4d7e87f7565177693eefb4650bb32c3498968 Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Wed, 7 Aug 2019 09:30:16 -0700 Subject: [PATCH] Sort the fat LTO modules to produce deterministic output. --- src/librustc_codegen_ssa/back/write.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index c9e4663fdbdd..2bd46b9f6efe 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -755,6 +755,15 @@ pub enum FatLTOInput { InMemory(ModuleCodegen), } +impl FatLTOInput { + fn name(&'a self) -> &'a String { + match self { + FatLTOInput::Serialized { name, buffer: _ } => &name, + FatLTOInput::InMemory(module) => &module.name, + } + } +} + fn execute_work_item( cgcx: &CodegenContext, work_item: WorkItem, @@ -1345,10 +1354,15 @@ fn start_executing_work( assert!(!started_lto); started_lto = true; - let needs_fat_lto = mem::take(&mut needs_fat_lto); + let mut needs_fat_lto: Vec> = 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