@@ -1197,21 +1197,29 @@ fn add_sanitizer_libraries(
11971197 crate_type : CrateType ,
11981198 linker : & mut dyn Linker ,
11991199) {
1200- // On macOS and Windows using MSVC the runtimes are distributed as dylibs
1201- // which should be linked to both executables and dynamic libraries.
1202- // Everywhere else the runtimes are currently distributed as static
1203- // libraries which should be linked to executables only.
1204- let needs_runtime = !sess. target . is_like_android
1205- && !sess. opts . unstable_opts . external_clangrt
1206- && match crate_type {
1207- CrateType :: Executable => true ,
1208- CrateType :: Dylib | CrateType :: Cdylib | CrateType :: ProcMacro => {
1209- sess. target . is_like_osx || sess. target . is_like_msvc
1210- }
1211- CrateType :: Rlib | CrateType :: Staticlib => false ,
1212- } ;
1200+ if sess. target . is_like_android {
1201+ // Sanitizer runtime libraries are provided dynamically on Android
1202+ // targets.
1203+ return ;
1204+ }
12131205
1214- if !needs_runtime {
1206+ if sess. opts . unstable_opts . external_clangrt {
1207+ // Linking against in-tree sanitizer runtimes is disabled via
1208+ // `-Z external-clangrt`
1209+ return ;
1210+ }
1211+
1212+ // On macOS the runtimes are distributed as dylibs which should be linked to
1213+ // both executables and dynamic shared objects. On most other platforms the
1214+ // runtimes are currently distributed as static libraries which should be
1215+ // linked to executables only.
1216+ if matches ! ( crate_type, CrateType :: Rlib | CrateType :: Staticlib ) {
1217+ return ;
1218+ }
1219+
1220+ if matches ! ( crate_type, CrateType :: Dylib | CrateType :: Cdylib | CrateType :: ProcMacro )
1221+ && ( sess. target . is_like_osx || sess. target . is_like_msvc )
1222+ {
12151223 return ;
12161224 }
12171225
0 commit comments