Skip to content

Commit

Permalink
Break complex conditional into separate statements
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswailes committed Feb 22, 2024
1 parent 3bdef53 commit a1a3a21
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
37 changes: 22 additions & 15 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,22 +1197,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.cg.link_self_contained.is_sanitizers_disabled()
|| sess.opts.cg.link_self_contained.is_sanitizers_enabled())
&& 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.cg.link_self_contained.is_sanitizers_disabled() {
// Linking against in-tree sanitizer runtimes is disabled via
// `-C link-self-contained=-sanitizers`
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, crate_type == 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
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl LinkSelfContained {
self.enabled_components.contains(LinkSelfContainedComponents::SANITIZERS)
}

/// Returns whether the self-contained linker component was disabled on the CLI, using the
/// Returns whether the self-contained sanitizer component was disabled on the CLI, using the
/// `-C link-self-contained=-sanitizers` syntax, or one of the `false` shortcuts.
pub fn is_sanitizers_disabled(&self) -> bool {
self.disabled_components.contains(LinkSelfContainedComponents::SANITIZERS)
Expand Down

0 comments on commit a1a3a21

Please sign in to comment.