about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-12-12 08:06:58 +0100
committerGitHub <noreply@github.com>2024-12-12 08:06:58 +0100
commita4cf1f89abe757727442abcbdafa7888b6b1978f (patch)
tree51619b74160537b06cdaa71155ca3f1eb5ce35af
parent903d2976fdb6ceeb65526b7555d8d1e6f8c02134 (diff)
parentd442cf54ea114399d0f892acce22d13b02a9232b (diff)
downloadrust-a4cf1f89abe757727442abcbdafa7888b6b1978f.tar.gz
rust-a4cf1f89abe757727442abcbdafa7888b6b1978f.zip
Rollup merge of #122003 - mati865:gnullvm-build-libunwind, r=petrochenkov
link libunwind dynamically and allow controlling it via `crt-static` on gnullvm targets

Alternative to https://github.com/rust-lang/rust/pull/121794

```
$ cargo b -r
    Finished `release` profile [optimized] target(s) in 0.38s

$ ntldd target/release/hello.exe | rg unwind
        libunwind.dll => H:\msys64\clang64\bin\libunwind.dll (0x0000020c35df0000)

$ RUSTFLAGS="-C target-feature=+crt-static" cargo b -r
    Finished `release` profile [optimized] target(s) in 0.23s

$ ntldd target/release/hello.exe | rg unwind
```
-rw-r--r--compiler/rustc_target/src/spec/base/windows_gnullvm.rs2
-rw-r--r--library/unwind/src/lib.rs5
-rw-r--r--library/unwind/src/libunwind.rs9
3 files changed, 10 insertions, 6 deletions
diff --git a/compiler/rustc_target/src/spec/base/windows_gnullvm.rs b/compiler/rustc_target/src/spec/base/windows_gnullvm.rs
index d5acd37092a..4f370ec8bd0 100644
--- a/compiler/rustc_target/src/spec/base/windows_gnullvm.rs
+++ b/compiler/rustc_target/src/spec/base/windows_gnullvm.rs
@@ -42,6 +42,8 @@ pub(crate) fn opts() -> TargetOptions {
         eh_frame_header: false,
         no_default_libraries: false,
         has_thread_local: true,
+        crt_static_allows_dylibs: true,
+        crt_static_respected: true,
         // FIXME(davidtwco): Support Split DWARF on Windows GNU - may require LLVM changes to
         // output DWO, despite using DWARF, doesn't use ELF..
         debuginfo_kind: DebuginfoKind::Pdb,
diff --git a/library/unwind/src/lib.rs b/library/unwind/src/lib.rs
index 79baa5b0b83..40d409310ff 100644
--- a/library/unwind/src/lib.rs
+++ b/library/unwind/src/lib.rs
@@ -178,3 +178,8 @@ cfg_if::cfg_if! {
 #[cfg(target_os = "hurd")]
 #[link(name = "gcc_s")]
 extern "C" {}
+
+#[cfg(all(target_os = "windows", target_env = "gnu", target_abi = "llvm"))]
+#[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
+#[link(name = "unwind", cfg(not(target_feature = "crt-static")))]
+extern "C" {}
diff --git a/library/unwind/src/libunwind.rs b/library/unwind/src/libunwind.rs
index 715f8b57876..1fa9e480166 100644
--- a/library/unwind/src/libunwind.rs
+++ b/library/unwind/src/libunwind.rs
@@ -102,12 +102,9 @@ pub type _Unwind_Exception_Cleanup_Fn =
 // rustc_codegen_ssa::src::back::symbol_export, rustc_middle::middle::exported_symbols
 // and RFC 2841
 #[cfg_attr(
-    any(
-        all(
-            feature = "llvm-libunwind",
-            any(target_os = "fuchsia", target_os = "linux", target_os = "xous")
-        ),
-        all(target_os = "windows", target_env = "gnu", target_abi = "llvm")
+    all(
+        feature = "llvm-libunwind",
+        any(target_os = "fuchsia", target_os = "linux", target_os = "xous")
     ),
     link(name = "unwind", kind = "static", modifiers = "-bundle")
 )]