@@ -11,7 +11,7 @@ use object::{Object, ObjectSection};
1111use rustc_codegen_ssa:: back:: lto:: { SerializedModule , ThinModule , ThinShared } ;
1212use rustc_codegen_ssa:: back:: write:: { CodegenContext , FatLtoInput } ;
1313use rustc_codegen_ssa:: traits:: * ;
14- use rustc_codegen_ssa:: { ModuleCodegen , looks_like_rust_object_file} ;
14+ use rustc_codegen_ssa:: { ModuleCodegen , ModuleKind , looks_like_rust_object_file} ;
1515use rustc_data_structures:: fx:: FxHashMap ;
1616use rustc_data_structures:: memmap:: Mmap ;
1717use rustc_errors:: DiagCtxtHandle ;
@@ -185,12 +185,9 @@ pub(crate) fn run_thin(
185185 thin_lto ( cgcx, dcx, modules, upstream_modules, cached_modules, & symbols_below_threshold)
186186}
187187
188- pub ( crate ) fn prepare_thin (
189- module : ModuleCodegen < ModuleLlvm > ,
190- emit_summary : bool ,
191- ) -> ( String , ThinBuffer ) {
188+ pub ( crate ) fn prepare_thin ( module : ModuleCodegen < ModuleLlvm > ) -> ( String , ThinBuffer ) {
192189 let name = module. name ;
193- let buffer = ThinBuffer :: new ( module. module_llvm . llmod ( ) , true , emit_summary ) ;
190+ let buffer = ThinBuffer :: new ( module. module_llvm . llmod ( ) , true ) ;
194191 ( name, buffer)
195192}
196193
@@ -225,9 +222,15 @@ fn fat_lto(
225222 // All the other modules will be serialized and reparsed into the new
226223 // context, so this hopefully avoids serializing and parsing the largest
227224 // codegen unit.
225+ //
226+ // Additionally use a regular module as the base here to ensure that various
227+ // file copy operations in the backend work correctly. The only other kind
228+ // of module here should be an allocator one, and if your crate is smaller
229+ // than the allocator module then the size doesn't really matter anyway.
228230 let costliest_module = in_memory
229231 . iter ( )
230232 . enumerate ( )
233+ . filter ( |& ( _, module) | module. kind == ModuleKind :: Regular )
231234 . map ( |( i, module) | {
232235 let cost = unsafe { llvm:: LLVMRustModuleCost ( module. module_llvm . llmod ( ) ) } ;
233236 ( cost, i)
@@ -681,9 +684,9 @@ unsafe impl Send for ThinBuffer {}
681684unsafe impl Sync for ThinBuffer { }
682685
683686impl ThinBuffer {
684- pub ( crate ) fn new ( m : & llvm:: Module , is_thin : bool , emit_summary : bool ) -> ThinBuffer {
687+ pub ( crate ) fn new ( m : & llvm:: Module , is_thin : bool ) -> ThinBuffer {
685688 unsafe {
686- let buffer = llvm:: LLVMRustThinLTOBufferCreate ( m, is_thin, emit_summary ) ;
689+ let buffer = llvm:: LLVMRustThinLTOBufferCreate ( m, is_thin) ;
687690 ThinBuffer ( buffer)
688691 }
689692 }
@@ -692,21 +695,21 @@ impl ThinBuffer {
692695 let mut ptr = NonNull :: new ( ptr) . unwrap ( ) ;
693696 ThinBuffer ( unsafe { ptr. as_mut ( ) } )
694697 }
695- }
696698
697- impl ThinBufferMethods for ThinBuffer {
698- fn data ( & self ) -> & [ u8 ] {
699+ pub ( crate ) fn thin_link_data ( & self ) -> & [ u8 ] {
699700 unsafe {
700- let ptr = llvm:: LLVMRustThinLTOBufferPtr ( self . 0 ) as * const _ ;
701- let len = llvm:: LLVMRustThinLTOBufferLen ( self . 0 ) ;
701+ let ptr = llvm:: LLVMRustThinLTOBufferThinLinkDataPtr ( self . 0 ) as * const _ ;
702+ let len = llvm:: LLVMRustThinLTOBufferThinLinkDataLen ( self . 0 ) ;
702703 slice:: from_raw_parts ( ptr, len)
703704 }
704705 }
706+ }
705707
706- fn thin_link_data ( & self ) -> & [ u8 ] {
708+ impl ThinBufferMethods for ThinBuffer {
709+ fn data ( & self ) -> & [ u8 ] {
707710 unsafe {
708- let ptr = llvm:: LLVMRustThinLTOBufferThinLinkDataPtr ( self . 0 ) as * const _ ;
709- let len = llvm:: LLVMRustThinLTOBufferThinLinkDataLen ( self . 0 ) ;
711+ let ptr = llvm:: LLVMRustThinLTOBufferPtr ( self . 0 ) as * const _ ;
712+ let len = llvm:: LLVMRustThinLTOBufferLen ( self . 0 ) ;
710713 slice:: from_raw_parts ( ptr, len)
711714 }
712715 }
0 commit comments