diff options
| author | Joel Galenson <jgalenson@google.com> | 2019-08-07 09:30:16 -0700 |
|---|---|---|
| committer | Joel Galenson <jgalenson@google.com> | 2019-08-07 09:30:16 -0700 |
| commit | ffa4d7e87f7565177693eefb4650bb32c3498968 (patch) | |
| tree | e9badeae903b7892c5cc32b6b435dd2e665c1583 | |
| parent | d4abb08be6c3a06a14e285396f5e3ef367584f77 (diff) | |
| download | rust-ffa4d7e87f7565177693eefb4650bb32c3498968.tar.gz rust-ffa4d7e87f7565177693eefb4650bb32c3498968.zip | |
Sort the fat LTO modules to produce deterministic output.
| -rw-r--r-- | src/librustc_codegen_ssa/back/write.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index c9e4663fdbd..2bd46b9f6ef 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -755,6 +755,15 @@ 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>, @@ -1345,10 +1354,15 @@ fn start_executing_work<B: ExtraBackendMethods>( assert!(!started_lto); started_lto = true; - let needs_fat_lto = mem::take(&mut needs_fat_lto); + let mut needs_fat_lto: Vec<FatLTOInput<B>> = 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 |
