@@ -11,7 +11,7 @@ use object::{Object, ObjectSection};
11
11
use rustc_codegen_ssa:: back:: lto:: { SerializedModule , ThinModule , ThinShared } ;
12
12
use rustc_codegen_ssa:: back:: write:: { CodegenContext , FatLtoInput } ;
13
13
use 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} ;
15
15
use rustc_data_structures:: fx:: FxHashMap ;
16
16
use rustc_data_structures:: memmap:: Mmap ;
17
17
use rustc_errors:: DiagCtxtHandle ;
@@ -185,12 +185,9 @@ pub(crate) fn run_thin(
185
185
thin_lto ( cgcx, dcx, modules, upstream_modules, cached_modules, & symbols_below_threshold)
186
186
}
187
187
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 ) {
192
189
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 ) ;
194
191
( name, buffer)
195
192
}
196
193
@@ -225,9 +222,15 @@ fn fat_lto(
225
222
// All the other modules will be serialized and reparsed into the new
226
223
// context, so this hopefully avoids serializing and parsing the largest
227
224
// 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.
228
230
let costliest_module = in_memory
229
231
. iter ( )
230
232
. enumerate ( )
233
+ . filter ( |& ( _, module) | module. kind == ModuleKind :: Regular )
231
234
. map ( |( i, module) | {
232
235
let cost = unsafe { llvm:: LLVMRustModuleCost ( module. module_llvm . llmod ( ) ) } ;
233
236
( cost, i)
@@ -681,9 +684,9 @@ unsafe impl Send for ThinBuffer {}
681
684
unsafe impl Sync for ThinBuffer { }
682
685
683
686
impl 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 {
685
688
unsafe {
686
- let buffer = llvm:: LLVMRustThinLTOBufferCreate ( m, is_thin, emit_summary ) ;
689
+ let buffer = llvm:: LLVMRustThinLTOBufferCreate ( m, is_thin) ;
687
690
ThinBuffer ( buffer)
688
691
}
689
692
}
@@ -692,21 +695,21 @@ impl ThinBuffer {
692
695
let mut ptr = NonNull :: new ( ptr) . unwrap ( ) ;
693
696
ThinBuffer ( unsafe { ptr. as_mut ( ) } )
694
697
}
695
- }
696
698
697
- impl ThinBufferMethods for ThinBuffer {
698
- fn data ( & self ) -> & [ u8 ] {
699
+ pub ( crate ) fn thin_link_data ( & self ) -> & [ u8 ] {
699
700
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 ) ;
702
703
slice:: from_raw_parts ( ptr, len)
703
704
}
704
705
}
706
+ }
705
707
706
- fn thin_link_data ( & self ) -> & [ u8 ] {
708
+ impl ThinBufferMethods for ThinBuffer {
709
+ fn data ( & self ) -> & [ u8 ] {
707
710
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 ) ;
710
713
slice:: from_raw_parts ( ptr, len)
711
714
}
712
715
}
0 commit comments