From a169d337e473aaa23a7703bba850259df7063464 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 2 Apr 2022 14:31:34 +0300 Subject: [PATCH] linker: Implicitly link native libs as whole-archive in some more cases --- compiler/rustc_codegen_ssa/src/back/link.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 548ae0e411d..c2b296bba1c 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -2079,9 +2079,14 @@ fn add_local_native_libraries( NativeLibKind::Framework { as_needed } => { cmd.link_framework(name, as_needed.unwrap_or(true)) } - NativeLibKind::Static { whole_archive, .. } => { + NativeLibKind::Static { whole_archive, bundle, .. } => { if whole_archive == Some(true) || (whole_archive == None && default_to_whole_archive(sess, crate_type, cmd)) + // Backward compatibility case: this can be a rlib (so `+whole-archive` cannot + // be added explicitly if necessary, see the error in `fn link_rlib`) compiled + // as an executable due to `--test`. Use whole-archive implicitly, like before + // the introduction of native lib modifiers. + || (bundle != Some(false) && sess.opts.test) { cmd.link_whole_staticlib( name,