@@ -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} ;
@@ -37,6 +37,7 @@ use cc::windows_registry;
37
37
use regex:: Regex ;
38
38
use tempfile:: Builder as TempFileBuilder ;
39
39
40
+ use itertools:: Itertools ;
40
41
use std:: borrow:: Borrow ;
41
42
use std:: cell:: OnceCell ;
42
43
use std:: collections:: BTreeSet ;
@@ -206,11 +207,26 @@ pub fn link_binary<'a>(
206
207
}
207
208
208
209
pub fn each_linked_rlib (
210
+ sess : & Session ,
209
211
info : & CrateInfo ,
210
212
f : & mut dyn FnMut ( CrateNum , & Path ) ,
211
213
) -> Result < ( ) , String > {
212
214
let crates = info. used_crates . iter ( ) ;
213
215
let mut fmts = None ;
216
+
217
+ let lto_active = matches ! ( sess. lto( ) , Lto :: Fat | Lto :: Thin ) ;
218
+ if lto_active {
219
+ for combination in info. dependency_formats . iter ( ) . combinations ( 2 ) {
220
+ let ( ty1, list1) = combination[ 0 ] ;
221
+ let ( ty2, list2) = combination[ 1 ] ;
222
+ if list1 != list2 {
223
+ return Err ( format ! (
224
+ "{ty1:?} and {ty2:?} do not have equivalent dependency formats (`{list1:?}` vs `{list2:?}`)"
225
+ ) ) ;
226
+ }
227
+ }
228
+ }
229
+
214
230
for ( ty, list) in info. dependency_formats . iter ( ) {
215
231
match ty {
216
232
CrateType :: Executable
@@ -220,6 +236,10 @@ pub fn each_linked_rlib(
220
236
fmts = Some ( list) ;
221
237
break ;
222
238
}
239
+ CrateType :: Dylib if lto_active => {
240
+ fmts = Some ( list) ;
241
+ break ;
242
+ }
223
243
_ => { }
224
244
}
225
245
}
@@ -501,7 +521,7 @@ fn link_staticlib<'a>(
501
521
) ?;
502
522
let mut all_native_libs = vec ! [ ] ;
503
523
504
- let res = each_linked_rlib ( & codegen_results. crate_info , & mut |cnum, path| {
524
+ let res = each_linked_rlib ( sess , & codegen_results. crate_info , & mut |cnum, path| {
505
525
let name = codegen_results. crate_info . crate_name [ & cnum] ;
506
526
let native_libs = & codegen_results. crate_info . native_libraries [ & cnum] ;
507
527
0 commit comments