about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorChris Wailes <chriswailes@google.com>2024-03-13 11:13:25 -0700
committerChris Wailes <chriswailes@google.com>2024-03-13 11:27:06 -0700
commitbf2858a05f510b8a0317d25d7dc587afbd16acfc (patch)
treed4b0f0b25e3d3657aecd20575de9cc0efed9775f /compiler/rustc_codegen_ssa/src
parent2a9d1ed538546483702622a22132f75e24f34ab9 (diff)
downloadrust-bf2858a05f510b8a0317d25d7dc587afbd16acfc.tar.gz
rust-bf2858a05f510b8a0317d25d7dc587afbd16acfc.zip
Split a complex conditional into separate statements
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/back/link.rs36
1 files changed, 22 insertions, 14 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
index a37663b5972..0491b3a2695 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -1201,21 +1201,29 @@ fn add_sanitizer_libraries(
     crate_type: CrateType,
     linker: &mut dyn Linker,
 ) {
-    // On macOS and Windows using MSVC the runtimes are distributed as dylibs
-    // which should be linked to both executables and dynamic libraries.
-    // Everywhere else the runtimes are currently distributed as static
-    // libraries which should be linked to executables only.
-    let needs_runtime = !sess.target.is_like_android
-        && !sess.opts.unstable_opts.external_clangrt
-        && match crate_type {
-            CrateType::Executable => true,
-            CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => {
-                sess.target.is_like_osx || sess.target.is_like_msvc
-            }
-            CrateType::Rlib | CrateType::Staticlib => false,
-        };
+    if sess.target.is_like_android {
+        // Sanitizer runtime libraries are provided dynamically on Android
+        // targets.
+        return;
+    }
 
-    if !needs_runtime {
+    if sess.opts.unstable_opts.external_clangrt {
+        // Linking against in-tree sanitizer runtimes is disabled via
+        // `-Z external-clangrt`
+        return;
+    }
+
+    // On macOS the runtimes are distributed as dylibs which should be linked to
+    // both executables and dynamic shared objects. On most other platforms the
+    // runtimes are currently distributed as static libraries which should be
+    // linked to executables only.
+    if matches!(crate_type, CrateType::Rlib | CrateType::Staticlib) {
+        return;
+    }
+
+    if matches!(crate_type, CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro)
+        && (sess.target.is_like_osx || sess.target.is_like_msvc)
+    {
         return;
     }