Skip to content

Commit 5b2c5e1

Browse files
committed
Sort fat LTO modules later and add a test.
1 parent ffa4d7e commit 5b2c5e1

File tree

3 files changed

+15
-18
lines changed
  • src
    • librustc_codegen_llvm/back
    • librustc_codegen_ssa/back
    • test/run-make-fulldeps/reproducible-build

3 files changed

+15
-18
lines changed

src/librustc_codegen_llvm/back/lto.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
265265
// and we want to move everything to the same LLVM context. Currently the
266266
// way we know of to do that is to serialize them to a string and them parse
267267
// them later. Not great but hey, that's why it's "fat" LTO, right?
268-
serialized_modules.extend(modules.into_iter().map(|module| {
268+
let mut new_modules = modules.into_iter().map(|module| {
269269
match module {
270270
FatLTOInput::InMemory(module) => {
271271
let buffer = ModuleBuffer::new(module.module_llvm.llmod());
@@ -277,7 +277,9 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
277277
(SerializedModule::Local(buffer), llmod_id)
278278
}
279279
}
280-
}));
280+
}).collect::<Vec<_>>();
281+
new_modules.sort_by(|module1, module2| module1.1.partial_cmp(&module2.1).unwrap());
282+
serialized_modules.extend(new_modules);
281283
serialized_modules.extend(cached_modules.into_iter().map(|(buffer, wp)| {
282284
(buffer, CString::new(wp.cgu_name).unwrap())
283285
}));

src/librustc_codegen_ssa/back/write.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -755,15 +755,6 @@ pub enum FatLTOInput<B: WriteBackendMethods> {
755755
InMemory(ModuleCodegen<B::Module>),
756756
}
757757

758-
impl<B: WriteBackendMethods> FatLTOInput<B> {
759-
fn name(&'a self) -> &'a String {
760-
match self {
761-
FatLTOInput::Serialized { name, buffer: _ } => &name,
762-
FatLTOInput::InMemory(module) => &module.name,
763-
}
764-
}
765-
}
766-
767758
fn execute_work_item<B: ExtraBackendMethods>(
768759
cgcx: &CodegenContext<B>,
769760
work_item: WorkItem<B>,
@@ -1354,15 +1345,10 @@ fn start_executing_work<B: ExtraBackendMethods>(
13541345
assert!(!started_lto);
13551346
started_lto = true;
13561347

1357-
let mut needs_fat_lto: Vec<FatLTOInput<B>> = mem::take(&mut needs_fat_lto);
1348+
let needs_fat_lto = mem::take(&mut needs_fat_lto);
13581349
let needs_thin_lto = mem::take(&mut needs_thin_lto);
13591350
let import_only_modules = mem::take(&mut lto_import_only_modules);
13601351

1361-
// Regardless of what order these modules completed in, report them to
1362-
// the backend in the same order every time to ensure that we're handing
1363-
// out deterministic results.
1364-
needs_fat_lto.sort_by(|m1, m2| m1.name().cmp(m2.name()));
1365-
13661352
for (work, cost) in generate_lto_work(&cgcx, needs_fat_lto,
13671353
needs_thin_lto, import_only_modules) {
13681354
let insertion_index = work_items

src/test/run-make-fulldeps/reproducible-build/Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ all: \
1010
link_paths \
1111
remap_paths \
1212
different_source_dirs \
13-
extern_flags
13+
extern_flags \
14+
fat_lto
1415

1516
smoke:
1617
rm -rf $(TMPDIR) && mkdir $(TMPDIR)
@@ -76,3 +77,11 @@ extern_flags:
7677
--extern reproducible_build_aux=$(TMPDIR)/libbar.rlib \
7778
--crate-type rlib
7879
cmp "$(TMPDIR)/libreproducible_build.rlib" "$(TMPDIR)/libfoo.rlib" || exit 1
80+
81+
fat_lto:
82+
rm -rf $(TMPDIR) && mkdir $(TMPDIR)
83+
$(RUSTC) reproducible-build-aux.rs
84+
$(RUSTC) reproducible-build.rs -C lto=fat
85+
cp $(TMPDIR)/reproducible-build $(TMPDIR)/reproducible-build-a
86+
$(RUSTC) reproducible-build.rs -C lto=fat
87+
cmp "$(TMPDIR)/reproducible-build-a" "$(TMPDIR)/reproducible-build" || exit 1

0 commit comments

Comments
 (0)