@@ -24,36 +24,24 @@ use std::sync::Arc;
24
24
25
25
use gccjit:: { Context , OutputKind } ;
26
26
use 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
+ } ;
29
30
use rustc_codegen_ssa:: back:: write:: { CodegenContext , FatLtoInput } ;
30
31
use rustc_codegen_ssa:: traits:: * ;
31
32
use rustc_codegen_ssa:: { ModuleCodegen , ModuleKind , looks_like_rust_object_file} ;
32
33
use rustc_data_structures:: memmap:: Mmap ;
33
34
use rustc_errors:: { DiagCtxtHandle , FatalError } ;
34
- use rustc_hir:: def_id:: LOCAL_CRATE ;
35
35
use rustc_middle:: bug;
36
36
use 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 ;
39
38
use rustc_target:: spec:: RelocModel ;
40
39
use tempfile:: { TempDir , tempdir} ;
41
40
42
41
use crate :: back:: write:: save_temp_bitcode;
43
- use crate :: errors:: { DynamicLinkingWithLTO , LtoBitcodeFromRlib , LtoDisallowed , LtoDylib } ;
42
+ use crate :: errors:: LtoBitcodeFromRlib ;
44
43
use crate :: { GccCodegenBackend , GccContext , SyncContext , to_gcc_opt_level} ;
45
44
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
-
57
45
struct LtoData {
58
46
// TODO(antoyo): use symbols_below_threshold.
59
47
//symbols_below_threshold: Vec<String>,
@@ -65,15 +53,8 @@ fn prepare_lto(
65
53
cgcx : & CodegenContext < GccCodegenBackend > ,
66
54
dcx : DiagCtxtHandle < ' _ > ,
67
55
) -> 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) ?;
77
58
78
59
let tmp_path = match tempdir ( ) {
79
60
Ok ( tmp_path) => tmp_path,
@@ -83,20 +64,6 @@ fn prepare_lto(
83
64
}
84
65
} ;
85
66
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
-
100
67
// If we're performing LTO for the entire crate graph, then for each of our
101
68
// upstream dependencies, find the corresponding rlib and load the bitcode
102
69
// from the archive.
@@ -105,32 +72,7 @@ fn prepare_lto(
105
72
// with either fat or thin LTO
106
73
let mut upstream_modules = Vec :: new ( ) ;
107
74
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 ( ) {
134
76
let archive_data = unsafe {
135
77
Mmap :: map ( File :: open ( path) . expect ( "couldn't open rlib" ) ) . expect ( "couldn't map rlib" )
136
78
} ;
0 commit comments