Skip to content

Commit

Permalink
Auto merge of #84794 - ChrisDenton:dedup-native-libs, r=petrochenkov
Browse files Browse the repository at this point in the history
Deduplicate native libs before they are passed to the linker

Stop spamming the linker with the same native library over and over again, if they directly follow from each other. This would help prevent [this situation](MSxDOS/ntapi#2).

Issue #38460 has been open since 2016 so I think it's worth making an incomplete fix that at least addresses the most common symptom and without otherwise changing how Rust handles native libs. This PR is intended to be easy to revert (if necessary) when a more permanent fix is implemented.
  • Loading branch information
bors committed May 5, 2021
2 parents 45ccf91 + e40faef commit 2d11e25
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,11 @@ fn add_local_native_libraries(
codegen_results.crate_info.used_libraries.iter().filter(|l| relevant_lib(sess, l));

let search_path = archive_search_paths(sess);
let mut last = (NativeLibKind::Unspecified, None);
for lib in relevant_libs {
// Skip if this library is the same as the last.
last = if (lib.kind, lib.name) == last { continue } else { (lib.kind, lib.name) };

let name = match lib.name {
Some(l) => l,
None => continue,
Expand Down Expand Up @@ -2127,8 +2131,12 @@ fn add_upstream_native_libraries(
.expect("failed to find crate type in dependency format list");

let crates = &codegen_results.crate_info.used_crates_static;
let mut last = (NativeLibKind::Unspecified, None);
for &(cnum, _) in crates {
for lib in codegen_results.crate_info.native_libraries[&cnum].iter() {
// Skip if this library is the same as the last.
last = if (lib.kind, lib.name) == last { continue } else { (lib.kind, lib.name) };

let name = match lib.name {
Some(l) => l,
None => continue,
Expand Down

0 comments on commit 2d11e25

Please sign in to comment.