@@ -391,13 +391,14 @@ fn link_rlib<'a>(
391
391
}
392
392
393
393
for ( raw_dylib_name, raw_dylib_imports) in
394
- collate_raw_dylibs ( sess, & codegen_results. crate_info . used_libraries ) ?
394
+ collate_raw_dylibs ( sess, codegen_results. crate_info . used_libraries . iter ( ) ) ?
395
395
{
396
396
let output_path = archive_builder_builder. create_dll_import_lib (
397
397
sess,
398
398
& raw_dylib_name,
399
399
& raw_dylib_imports,
400
400
tmpdir. as_ref ( ) ,
401
+ true ,
401
402
) ;
402
403
403
404
ab. add_archive ( & output_path, Box :: new ( |_| false ) ) . unwrap_or_else ( |error| {
@@ -449,9 +450,9 @@ fn link_rlib<'a>(
449
450
/// then the CodegenResults value contains one NativeLib instance for each block. However, the
450
451
/// linker appears to expect only a single import library for each library used, so we need to
451
452
/// collate the symbols together by library name before generating the import libraries.
452
- fn collate_raw_dylibs (
453
- sess : & Session ,
454
- used_libraries : & [ NativeLib ] ,
453
+ fn collate_raw_dylibs < ' a , ' b > (
454
+ sess : & ' a Session ,
455
+ used_libraries : impl IntoIterator < Item = & ' b NativeLib > ,
455
456
) -> Result < Vec < ( String , Vec < DllImport > ) > , ErrorGuaranteed > {
456
457
// Use index maps to preserve original order of imports and libraries.
457
458
let mut dylib_table = FxIndexMap :: < String , FxIndexMap < Symbol , & DllImport > > :: default ( ) ;
@@ -2068,13 +2069,43 @@ fn linker_with_args<'a>(
2068
2069
2069
2070
// Link with the import library generated for any raw-dylib functions.
2070
2071
for ( raw_dylib_name, raw_dylib_imports) in
2071
- collate_raw_dylibs ( sess, & codegen_results. crate_info . used_libraries ) ?
2072
+ collate_raw_dylibs ( sess, codegen_results. crate_info . used_libraries . iter ( ) ) ?
2073
+ {
2074
+ cmd. add_object ( & archive_builder_builder. create_dll_import_lib (
2075
+ sess,
2076
+ & raw_dylib_name,
2077
+ & raw_dylib_imports,
2078
+ tmpdir,
2079
+ true ,
2080
+ ) ) ;
2081
+ }
2082
+ // As with add_upstream_native_libraries, we need to add the upstream raw-dylib symbols in case
2083
+ // they are used within inlined functions or instantiated generic functions. We do this *after*
2084
+ // handling the raw-dylib symbols in the current crate to make sure that those are chosen first
2085
+ // by the linker.
2086
+ let ( _, dependency_linkage) = codegen_results
2087
+ . crate_info
2088
+ . dependency_formats
2089
+ . iter ( )
2090
+ . find ( |( ty, _) | * ty == crate_type)
2091
+ . expect ( "failed to find crate type in dependency format list" ) ;
2092
+ let native_libraries_from_nonstatics = codegen_results
2093
+ . crate_info
2094
+ . native_libraries
2095
+ . iter ( )
2096
+ . filter_map ( |( cnum, libraries) | {
2097
+ ( dependency_linkage[ cnum. as_usize ( ) - 1 ] != Linkage :: Static ) . then ( || libraries)
2098
+ } )
2099
+ . flatten ( ) ;
2100
+ for ( raw_dylib_name, raw_dylib_imports) in
2101
+ collate_raw_dylibs ( sess, native_libraries_from_nonstatics) ?
2072
2102
{
2073
2103
cmd. add_object ( & archive_builder_builder. create_dll_import_lib (
2074
2104
sess,
2075
2105
& raw_dylib_name,
2076
2106
& raw_dylib_imports,
2077
2107
tmpdir,
2108
+ false ,
2078
2109
) ) ;
2079
2110
}
2080
2111
0 commit comments