@@ -11,7 +11,7 @@ use rustc_metadata::find_native_static_library;
11
11
use rustc_metadata:: fs:: { emit_metadata, METADATA_FILENAME } ;
12
12
use rustc_middle:: middle:: dependency_format:: Linkage ;
13
13
use rustc_middle:: middle:: exported_symbols:: SymbolExportKind ;
14
- use rustc_session:: config:: { self , CFGuard , CrateType , DebugInfo , LdImpl , Strip } ;
14
+ use rustc_session:: config:: { self , CFGuard , CrateType , DebugInfo , LdImpl , Lto , Strip } ;
15
15
use rustc_session:: config:: { OutputFilenames , OutputType , PrintRequest , SplitDwarfKind } ;
16
16
use rustc_session:: cstore:: DllImport ;
17
17
use rustc_session:: output:: { check_file_is_writeable, invalid_output_for_target, out_filename} ;
@@ -49,6 +49,7 @@ use std::ops::Deref;
49
49
use std:: path:: { Path , PathBuf } ;
50
50
use std:: process:: { ExitStatus , Output , Stdio } ;
51
51
use std:: { env, fmt, fs, io, mem, str} ;
52
+ use itertools:: Itertools ;
52
53
53
54
pub fn ensure_removed ( diag_handler : & Handler , path : & Path ) {
54
55
if let Err ( e) = fs:: remove_file ( path) {
@@ -208,11 +209,24 @@ pub fn link_binary<'a>(
208
209
}
209
210
210
211
pub fn each_linked_rlib (
212
+ sess : & Session ,
211
213
info : & CrateInfo ,
212
214
f : & mut dyn FnMut ( CrateNum , & Path ) ,
213
215
) -> Result < ( ) , errors:: LinkRlibError > {
214
216
let crates = info. used_crates . iter ( ) ;
215
217
let mut fmts = None ;
218
+
219
+ let lto_active = matches ! ( sess. lto( ) , Lto :: Fat | Lto :: Thin ) ;
220
+ if lto_active {
221
+ for combination in info. dependency_formats . iter ( ) . combinations ( 2 ) {
222
+ let ( ty1, list1) = combination[ 0 ] ;
223
+ let ( ty2, list2) = combination[ 1 ] ;
224
+ if list1 != list2 {
225
+ return Err ( format ! ( "{ty1:?} and {ty2:?} do not have equivalent dependency formats (`{list1:?}` vs `{list2:?}`)" ) ) ;
226
+ }
227
+ }
228
+ }
229
+
216
230
for ( ty, list) in info. dependency_formats . iter ( ) {
217
231
match ty {
218
232
CrateType :: Executable
@@ -222,6 +236,10 @@ pub fn each_linked_rlib(
222
236
fmts = Some ( list) ;
223
237
break ;
224
238
}
239
+ CrateType :: Dylib if lto_active => {
240
+ fmts = Some ( list) ;
241
+ break ;
242
+ }
225
243
_ => { }
226
244
}
227
245
}
@@ -490,7 +508,7 @@ fn link_staticlib<'a>(
490
508
) ?;
491
509
let mut all_native_libs = vec ! [ ] ;
492
510
493
- let res = each_linked_rlib ( & codegen_results. crate_info , & mut |cnum, path| {
511
+ let res = each_linked_rlib ( sess , & codegen_results. crate_info , & mut |cnum, path| {
494
512
let name = codegen_results. crate_info . crate_name [ & cnum] ;
495
513
let native_libs = & codegen_results. crate_info . native_libraries [ & cnum] ;
496
514
0 commit comments