@@ -31,7 +31,6 @@ use rustc_data_structures::memmap::Mmap;
3131use rustc_data_structures:: profiling:: SelfProfilerRef ;
3232use rustc_errors:: { DiagCtxt , DiagCtxtHandle } ;
3333use rustc_log:: tracing:: info;
34- use rustc_session:: config:: Lto ;
3534use tempfile:: { TempDir , tempdir} ;
3635
3736use crate :: back:: write:: { codegen, save_temp_bitcode} ;
@@ -45,11 +44,7 @@ struct LtoData {
4544 tmp_path : TempDir ,
4645}
4746
48- fn prepare_lto (
49- cgcx : & CodegenContext ,
50- each_linked_rlib_for_lto : & [ PathBuf ] ,
51- dcx : DiagCtxtHandle < ' _ > ,
52- ) -> LtoData {
47+ fn prepare_lto ( each_linked_rlib_for_lto : & [ PathBuf ] , dcx : DiagCtxtHandle < ' _ > ) -> LtoData {
5348 let tmp_path = match tempdir ( ) {
5449 Ok ( tmp_path) => tmp_path,
5550 Err ( error) => {
@@ -64,32 +59,30 @@ fn prepare_lto(
6459 // We save off all the bytecode and GCC module file path for later processing
6560 // with either fat or thin LTO
6661 let mut upstream_modules = Vec :: new ( ) ;
67- if cgcx. lto != Lto :: ThinLocal {
68- for path in each_linked_rlib_for_lto {
69- let archive_data = unsafe {
70- Mmap :: map ( File :: open ( path) . expect ( "couldn't open rlib" ) ) . expect ( "couldn't map rlib" )
71- } ;
72- let archive = ArchiveFile :: parse ( & * archive_data) . expect ( "wanted an rlib" ) ;
73- let obj_files = archive
74- . members ( )
75- . filter_map ( |child| {
76- child. ok ( ) . and_then ( |c| {
77- std:: str:: from_utf8 ( c. name ( ) ) . ok ( ) . map ( |name| ( name. trim ( ) , c) )
78- } )
79- } )
80- . filter ( |& ( name, _) | looks_like_rust_object_file ( name) ) ;
81- for ( name, child) in obj_files {
82- info ! ( "adding bitcode from {}" , name) ;
83- let path = tmp_path. path ( ) . join ( name) ;
84- match save_as_file ( child. data ( & * archive_data) . expect ( "corrupt rlib" ) , & path) {
85- Ok ( ( ) ) => {
86- let buffer = ModuleBuffer :: new ( path) ;
87- let module = SerializedModule :: Local ( buffer) ;
88- upstream_modules. push ( ( module, CString :: new ( name) . unwrap ( ) ) ) ;
89- }
90- Err ( e) => {
91- dcx. emit_fatal ( e) ;
92- }
62+ for path in each_linked_rlib_for_lto {
63+ let archive_data = unsafe {
64+ Mmap :: map ( File :: open ( path) . expect ( "couldn't open rlib" ) ) . expect ( "couldn't map rlib" )
65+ } ;
66+ let archive = ArchiveFile :: parse ( & * archive_data) . expect ( "wanted an rlib" ) ;
67+ let obj_files = archive
68+ . members ( )
69+ . filter_map ( |child| {
70+ child
71+ . ok ( )
72+ . and_then ( |c| std:: str:: from_utf8 ( c. name ( ) ) . ok ( ) . map ( |name| ( name. trim ( ) , c) ) )
73+ } )
74+ . filter ( |& ( name, _) | looks_like_rust_object_file ( name) ) ;
75+ for ( name, child) in obj_files {
76+ info ! ( "adding bitcode from {}" , name) ;
77+ let path = tmp_path. path ( ) . join ( name) ;
78+ match save_as_file ( child. data ( & * archive_data) . expect ( "corrupt rlib" ) , & path) {
79+ Ok ( ( ) ) => {
80+ let buffer = ModuleBuffer :: new ( path) ;
81+ let module = SerializedModule :: Local ( buffer) ;
82+ upstream_modules. push ( ( module, CString :: new ( name) . unwrap ( ) ) ) ;
83+ }
84+ Err ( e) => {
85+ dcx. emit_fatal ( e) ;
9386 }
9487 }
9588 }
@@ -115,7 +108,7 @@ pub(crate) fn run_fat(
115108) -> CompiledModule {
116109 let dcx = DiagCtxt :: new ( Box :: new ( shared_emitter. clone ( ) ) ) ;
117110 let dcx = dcx. handle ( ) ;
118- let lto_data = prepare_lto ( cgcx , each_linked_rlib_for_lto, dcx) ;
111+ let lto_data = prepare_lto ( each_linked_rlib_for_lto, dcx) ;
119112 /*let symbols_below_threshold =
120113 lto_data.symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();*/
121114 fat_lto (
@@ -151,9 +144,12 @@ fn fat_lto(
151144 for module in modules {
152145 match module {
153146 FatLtoInput :: InMemory ( m) => in_memory. push ( m) ,
154- FatLtoInput :: Serialized { name, buffer } => {
147+ FatLtoInput :: Serialized { name, bitcode_path } => {
155148 info ! ( "pushing serialized module {:?}" , name) ;
156- serialized_modules. push ( ( buffer, CString :: new ( name) . unwrap ( ) ) ) ;
149+ serialized_modules. push ( (
150+ SerializedModule :: from_file ( & bitcode_path) ,
151+ CString :: new ( name) . unwrap ( ) ,
152+ ) ) ;
157153 }
158154 }
159155 }
0 commit comments