Skip to content

Commit 4ad6fb2

Browse files
committed
Adjust how native static libraries are linked
1 parent fd182c4 commit 4ad6fb2

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

src/librustc_trans/back/link.rs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,38 +1021,23 @@ fn add_local_native_libraries(cmd: &mut Linker, sess: &Session) {
10211021
}
10221022
});
10231023

1024-
let pair = sess.cstore.used_libraries().into_iter().filter(|l| {
1024+
let libs = sess.cstore.used_libraries().into_iter().filter(|l| {
10251025
relevant_lib(sess, l)
1026-
}).partition(|lib| {
1027-
lib.kind == NativeLibraryKind::NativeStatic
10281026
});
1029-
let (staticlibs, others): (Vec<_>, Vec<_>) = pair;
1030-
1031-
// Some platforms take hints about whether a library is static or dynamic.
1032-
// For those that support this, we ensure we pass the option if the library
1033-
// was flagged "static" (most defaults are dynamic) to ensure that if
1034-
// libfoo.a and libfoo.so both exist that the right one is chosen.
1035-
cmd.hint_static();
1036-
1037-
let search_path = archive_search_paths(sess);
1038-
for l in staticlibs {
1039-
// Here we explicitly ask that the entire archive is included into the
1040-
// result artifact. For more details see #15460, but the gist is that
1041-
// the linker will strip away any unused objects in the archive if we
1042-
// don't otherwise explicitly reference them. This can occur for
1043-
// libraries which are just providing bindings, libraries with generic
1044-
// functions, etc.
1045-
cmd.link_whole_staticlib(&l.name.as_str(), &search_path);
1046-
}
1047-
1048-
cmd.hint_dynamic();
10491027

1050-
for lib in others {
1028+
for lib in libs {
10511029
match lib.kind {
10521030
NativeLibraryKind::NativeUnknown => cmd.link_dylib(&lib.name.as_str()),
10531031
NativeLibraryKind::NativeFramework => cmd.link_framework(&lib.name.as_str()),
1054-
NativeLibraryKind::NativeStaticNobundle => cmd.link_staticlib(&lib.name.as_str()),
1055-
NativeLibraryKind::NativeStatic => bug!(),
1032+
NativeLibraryKind::NativeStaticNobundle | NativeLibraryKind::NativeStatic => {
1033+
// Some platforms take hints about whether a library is static or dynamic.
1034+
// For those that support this, we ensure we pass the option if the library
1035+
// was flagged "static" (most defaults are dynamic) to ensure that if
1036+
// libfoo.a and libfoo.so both exist that the right one is chosen.
1037+
cmd.hint_static();
1038+
cmd.link_staticlib(&lib.name.as_str());
1039+
cmd.hint_dynamic();
1040+
}
10561041
}
10571042
}
10581043
}
@@ -1338,7 +1323,9 @@ fn add_upstream_native_libraries(cmd: &mut Linker, sess: &Session, crate_type: c
13381323
// or is an rlib already included via some other dylib crate, the symbols from
13391324
// native libs will have already been included in that dylib.
13401325
if data[cnum.as_usize() - 1] == Linkage::Static {
1341-
cmd.link_staticlib(&lib.name.as_str())
1326+
cmd.hint_static();
1327+
cmd.link_staticlib(&lib.name.as_str());
1328+
cmd.hint_dynamic();
13421329
}
13431330
},
13441331
// ignore statically included native libraries here as we've

0 commit comments

Comments
 (0)