Skip to content

Commit 175bd6b

Browse files
committed
linker: Never use whole-archive linking unless explicitly requested
1 parent c78ebb7 commit 175bd6b

File tree

1 file changed

+5
-16
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+5
-16
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -2030,8 +2030,7 @@ fn add_local_native_libraries(
20302030
NativeLibKind::Framework { as_needed } => {
20312031
cmd.link_framework(name, as_needed.unwrap_or(true))
20322032
}
2033-
NativeLibKind::Static { bundle: None | Some(true), .. }
2034-
| NativeLibKind::Static { whole_archive: Some(true), .. } => {
2033+
NativeLibKind::Static { whole_archive: Some(true), .. } => {
20352034
cmd.link_whole_staticlib(name, verbatim, &search_path);
20362035
}
20372036
NativeLibKind::Static { .. } => cmd.link_staticlib(name, verbatim),
@@ -2137,7 +2136,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
21372136
let src = &codegen_results.crate_info.used_crate_source[&cnum];
21382137
match data[cnum.as_usize() - 1] {
21392138
_ if codegen_results.crate_info.profiler_runtime == Some(cnum) => {
2140-
add_static_crate::<B>(cmd, sess, codegen_results, tmpdir, crate_type, cnum);
2139+
add_static_crate::<B>(cmd, sess, codegen_results, tmpdir, cnum)
21412140
}
21422141
// compiler-builtins are always placed last to ensure that they're
21432142
// linked correctly.
@@ -2146,9 +2145,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
21462145
compiler_builtins = Some(cnum);
21472146
}
21482147
Linkage::NotLinked | Linkage::IncludedFromDylib => {}
2149-
Linkage::Static => {
2150-
add_static_crate::<B>(cmd, sess, codegen_results, tmpdir, crate_type, cnum);
2151-
}
2148+
Linkage::Static => add_static_crate::<B>(cmd, sess, codegen_results, tmpdir, cnum),
21522149
Linkage::Dynamic => add_dynamic_crate(cmd, sess, &src.dylib.as_ref().unwrap().0),
21532150
}
21542151

@@ -2163,7 +2160,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
21632160
// was already "included" in a dylib (e.g., `libstd` when `-C prefer-dynamic`
21642161
// is used)
21652162
if let Some(cnum) = compiler_builtins {
2166-
add_static_crate::<B>(cmd, sess, codegen_results, tmpdir, crate_type, cnum);
2163+
add_static_crate::<B>(cmd, sess, codegen_results, tmpdir, cnum);
21672164
}
21682165

21692166
// Converts a library file-stem into a cc -l argument
@@ -2194,7 +2191,6 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
21942191
sess: &'a Session,
21952192
codegen_results: &CodegenResults,
21962193
tmpdir: &Path,
2197-
crate_type: CrateType,
21982194
cnum: CrateNum,
21992195
) {
22002196
let src = &codegen_results.crate_info.used_crate_source[&cnum];
@@ -2208,14 +2204,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
22082204
// Note, though, that we don't want to include the whole of a
22092205
// compiler-builtins crate (e.g., compiler-rt) because it'll get
22102206
// repeatedly linked anyway.
2211-
let path = fix_windows_verbatim_for_gcc(path);
2212-
if crate_type == CrateType::Dylib
2213-
&& codegen_results.crate_info.compiler_builtins != Some(cnum)
2214-
{
2215-
cmd.link_whole_rlib(&path);
2216-
} else {
2217-
cmd.link_rlib(&path);
2218-
}
2207+
cmd.link_rlib(&fix_windows_verbatim_for_gcc(path));
22192208
};
22202209

22212210
// See the comment above in `link_staticlib` and `link_rlib` for why if

0 commit comments

Comments
 (0)