@@ -24,36 +24,24 @@ use std::sync::Arc;
2424
2525use gccjit:: { Context , OutputKind } ;
2626use object:: read:: archive:: ArchiveFile ;
27- use rustc_codegen_ssa:: back:: lto:: { SerializedModule , ThinModule , ThinShared } ;
28- use rustc_codegen_ssa:: back:: symbol_export;
27+ use rustc_codegen_ssa:: back:: lto:: {
28+ SerializedModule , ThinModule , ThinShared , exported_symbols_for_lto,
29+ } ;
2930use rustc_codegen_ssa:: back:: write:: { CodegenContext , FatLtoInput } ;
3031use rustc_codegen_ssa:: traits:: * ;
3132use rustc_codegen_ssa:: { ModuleCodegen , ModuleKind , looks_like_rust_object_file} ;
3233use rustc_data_structures:: memmap:: Mmap ;
3334use rustc_errors:: { DiagCtxtHandle , FatalError } ;
34- use rustc_hir:: def_id:: LOCAL_CRATE ;
3535use rustc_middle:: bug;
3636use rustc_middle:: dep_graph:: WorkProduct ;
37- use rustc_middle:: middle:: exported_symbols:: { SymbolExportInfo , SymbolExportLevel } ;
38- use rustc_session:: config:: { CrateType , Lto } ;
37+ use rustc_session:: config:: Lto ;
3938use rustc_target:: spec:: RelocModel ;
4039use tempfile:: { TempDir , tempdir} ;
4140
4241use crate :: back:: write:: save_temp_bitcode;
43- use crate :: errors:: { DynamicLinkingWithLTO , LtoBitcodeFromRlib , LtoDisallowed , LtoDylib } ;
42+ use crate :: errors:: LtoBitcodeFromRlib ;
4443use crate :: { GccCodegenBackend , GccContext , SyncContext , to_gcc_opt_level} ;
4544
46- pub fn crate_type_allows_lto ( crate_type : CrateType ) -> bool {
47- match crate_type {
48- CrateType :: Executable
49- | CrateType :: Dylib
50- | CrateType :: Staticlib
51- | CrateType :: Cdylib
52- | CrateType :: Sdylib => true ,
53- CrateType :: Rlib | CrateType :: ProcMacro => false ,
54- }
55- }
56-
5745struct LtoData {
5846 // TODO(antoyo): use symbols_below_threshold.
5947 //symbols_below_threshold: Vec<String>,
@@ -65,15 +53,8 @@ fn prepare_lto(
6553 cgcx : & CodegenContext < GccCodegenBackend > ,
6654 dcx : DiagCtxtHandle < ' _ > ,
6755) -> Result < LtoData , FatalError > {
68- let export_threshold = match cgcx. lto {
69- // We're just doing LTO for our one crate
70- Lto :: ThinLocal => SymbolExportLevel :: Rust ,
71-
72- // We're doing LTO for the entire crate graph
73- Lto :: Fat | Lto :: Thin => symbol_export:: crates_export_threshold ( & cgcx. crate_types ) ,
74-
75- Lto :: No => panic ! ( "didn't request LTO but we're doing LTO" ) ,
76- } ;
56+ // FIXME(bjorn3): Limit LTO exports to these symbols
57+ let _symbols_below_threshold = exported_symbols_for_lto ( cgcx, dcx) ?;
7758
7859 let tmp_path = match tempdir ( ) {
7960 Ok ( tmp_path) => tmp_path,
@@ -83,20 +64,6 @@ fn prepare_lto(
8364 }
8465 } ;
8566
86- let symbol_filter = & |& ( ref name, info) : & ( String , SymbolExportInfo ) | {
87- if info. level . is_below_threshold ( export_threshold) || info. used {
88- Some ( name. clone ( ) )
89- } else {
90- None
91- }
92- } ;
93- let exported_symbols = cgcx. exported_symbols . as_ref ( ) . expect ( "needs exported symbols for LTO" ) ;
94- let mut symbols_below_threshold = {
95- let _timer = cgcx. prof . generic_activity ( "GCC_lto_generate_symbols_below_threshold" ) ;
96- exported_symbols[ & LOCAL_CRATE ] . iter ( ) . filter_map ( symbol_filter) . collect :: < Vec < String > > ( )
97- } ;
98- info ! ( "{} symbols to preserve in this crate" , symbols_below_threshold. len( ) ) ;
99-
10067 // If we're performing LTO for the entire crate graph, then for each of our
10168 // upstream dependencies, find the corresponding rlib and load the bitcode
10269 // from the archive.
@@ -105,32 +72,7 @@ fn prepare_lto(
10572 // with either fat or thin LTO
10673 let mut upstream_modules = Vec :: new ( ) ;
10774 if cgcx. lto != Lto :: ThinLocal {
108- // Make sure we actually can run LTO
109- for crate_type in cgcx. crate_types . iter ( ) {
110- if !crate_type_allows_lto ( * crate_type) {
111- dcx. emit_err ( LtoDisallowed ) ;
112- return Err ( FatalError ) ;
113- }
114- if * crate_type == CrateType :: Dylib && !cgcx. opts . unstable_opts . dylib_lto {
115- dcx. emit_err ( LtoDylib ) ;
116- return Err ( FatalError ) ;
117- }
118- }
119-
120- if cgcx. opts . cg . prefer_dynamic && !cgcx. opts . unstable_opts . dylib_lto {
121- dcx. emit_err ( DynamicLinkingWithLTO ) ;
122- return Err ( FatalError ) ;
123- }
124-
125- for & ( cnum, ref path) in cgcx. each_linked_rlib_for_lto . iter ( ) {
126- let exported_symbols =
127- cgcx. exported_symbols . as_ref ( ) . expect ( "needs exported symbols for LTO" ) ;
128- {
129- let _timer = cgcx. prof . generic_activity ( "GCC_lto_generate_symbols_below_threshold" ) ;
130- symbols_below_threshold
131- . extend ( exported_symbols[ & cnum] . iter ( ) . filter_map ( symbol_filter) ) ;
132- }
133-
75+ for & ( _cnum, ref path) in cgcx. each_linked_rlib_for_lto . iter ( ) {
13476 let archive_data = unsafe {
13577 Mmap :: map ( File :: open ( path) . expect ( "couldn't open rlib" ) ) . expect ( "couldn't map rlib" )
13678 } ;
0 commit comments