Skip to content

Commit 2d11e25

Browse files
committed
Auto merge of #84794 - ChrisDenton:dedup-native-libs, r=petrochenkov
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.
2 parents 45ccf91 + e40faef commit 2d11e25

File tree

1 file changed

+8
-0
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+8
-0
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,11 @@ fn add_local_native_libraries(
18031803
codegen_results.crate_info.used_libraries.iter().filter(|l| relevant_lib(sess, l));
18041804

18051805
let search_path = archive_search_paths(sess);
1806+
let mut last = (NativeLibKind::Unspecified, None);
18061807
for lib in relevant_libs {
1808+
// Skip if this library is the same as the last.
1809+
last = if (lib.kind, lib.name) == last { continue } else { (lib.kind, lib.name) };
1810+
18071811
let name = match lib.name {
18081812
Some(l) => l,
18091813
None => continue,
@@ -2127,8 +2131,12 @@ fn add_upstream_native_libraries(
21272131
.expect("failed to find crate type in dependency format list");
21282132

21292133
let crates = &codegen_results.crate_info.used_crates_static;
2134+
let mut last = (NativeLibKind::Unspecified, None);
21302135
for &(cnum, _) in crates {
21312136
for lib in codegen_results.crate_info.native_libraries[&cnum].iter() {
2137+
// Skip if this library is the same as the last.
2138+
last = if (lib.kind, lib.name) == last { continue } else { (lib.kind, lib.name) };
2139+
21322140
let name = match lib.name {
21332141
Some(l) => l,
21342142
None => continue,

0 commit comments

Comments
 (0)