void-packages/srcpkgs/rust/patches/0003-Require-static-native-libraries-when-linking-static-.patch
Érico Nogueira af802e87d4 rust: update to 1.53.0.
- rebase patches
- fix type of 'llvm-unwind' in config.toml
- move linux_musl_base stuff to a single patch which makes it behave
  just line linux_gnu_base
- copy new version of need-ssp_nonshared.patch from alpine
- temporary workaround for the new rust-llvm-dwp binary: it's copied
  from the llvm toolchain and shoved into /usr/lib, but they copied the
  binary from the build machine
- fix do_check (thanks cinerea0)
- preliminary ppcle patches (q66)
2021-07-04 22:27:37 +02:00

52 lines
2.5 KiB
Diff

From baa7ce46f19e3584d70e47c8df28c084e76446da Mon Sep 17 00:00:00 2001
From: Samuel Holland <samuel@sholland.org>
Date: Sun, 3 May 2020 17:48:47 +0200
Subject: [PATCH 03/15] Require static native libraries when linking static
executables
On ELF targets like Linux, gcc/ld will create a dynamically-linked
executable without warning, even when passed `-static`, when asked to
link to a `.so`. Avoid this confusing and unintended behavior by always
using the static version of libraries when trying to link static
executables.
Fixes #54243
---
src/librustc_codegen_ssa/back/link.rs | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
index 8bc4e6442..52ff7a52e 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -2081,8 +2081,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
}
}
-/// Link in all of our upstream crates' native dependencies. Remember that all of these upstream
-/// native dependencies are all non-static dependencies. We've got two cases then:
+/// Link in all of our upstream crates' native dependencies. We have two cases:
///
/// 1. The upstream crate is an rlib. In this case we *must* link in the native dependency because
/// the rlib is just an archive.
@@ -2015,7 +2013,19 @@
continue;
}
match lib.kind {
- NativeLibKind::Dylib | NativeLibKind::Unspecified => cmd.link_dylib(name),
+ NativeLibKind::Dylib | NativeLibKind::Unspecified => {
+ // On some targets, like Linux, linking a static executable inhibits using
+ // dylibs at all. Force native libraries to be static, even if for example
+ // an upstream rlib was originally linked against a native shared library.
+ if crate_type == config::CrateType::Executable
+ && sess.crt_static(Some(crate_type))
+ && !sess.target.options.crt_static_allows_dylibs
+ {
+ cmd.link_staticlib(name)
+ } else {
+ cmd.link_dylib(name)
+ }
+ },
NativeLibKind::Framework => cmd.link_framework(name),
NativeLibKind::StaticNoBundle => {
// Link "static-nobundle" native libs only if the crate they originate from