Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 887ca1e

Browse files
committed
Link static libraries with --whole-archive if the output is a dylib
1 parent 50fcee0 commit 887ca1e

File tree

2 files changed

+13
-2
lines changed
  • compiler

2 files changed

+13
-2
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,7 +2684,7 @@ fn add_native_libs_from_crate(
26842684
NativeLibKind::Static { bundle, whole_archive } => {
26852685
if link_static {
26862686
let bundle = bundle.unwrap_or(true);
2687-
let whole_archive = whole_archive == Some(true);
2687+
let whole_archive = whole_archive.unwrap_or(link_output_kind.is_dylib());
26882688
if bundle && cnum != LOCAL_CRATE {
26892689
if let Some(filename) = lib.filename {
26902690
// If rlib contains native libs as archives, they are unpacked to tmpdir.
@@ -2706,7 +2706,7 @@ fn add_native_libs_from_crate(
27062706
// link kind is unspecified.
27072707
if !link_output_kind.can_link_dylib() && !sess.target.crt_static_allows_dylibs {
27082708
if link_static {
2709-
cmd.link_staticlib_by_name(name, verbatim, false);
2709+
cmd.link_staticlib_by_name(name, verbatim, link_output_kind.is_dylib());
27102710
}
27112711
} else if link_dynamic {
27122712
cmd.link_dylib_by_name(name, verbatim, true);

compiler/rustc_target/src/spec/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,17 @@ impl LinkOutputKind {
12351235
| LinkOutputKind::WasiReactorExe => true,
12361236
}
12371237
}
1238+
1239+
pub fn is_dylib(self) -> bool {
1240+
match self {
1241+
LinkOutputKind::DynamicDylib | LinkOutputKind::StaticDylib => true,
1242+
LinkOutputKind::StaticNoPicExe
1243+
| LinkOutputKind::DynamicNoPicExe
1244+
| LinkOutputKind::DynamicPicExe
1245+
| LinkOutputKind::WasiReactorExe
1246+
| LinkOutputKind::StaticPicExe => false,
1247+
}
1248+
}
12381249
}
12391250

12401251
impl fmt::Display for LinkOutputKind {

0 commit comments

Comments
 (0)