Skip to content

Commit

Permalink
Split a complex conditional into separate statements
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswailes committed Mar 13, 2024
1 parent 2a9d1ed commit bf2858a
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit bf2858a

Please sign in to comment.