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