@@ -1197,22 +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 . cg . link_self_contained . is_sanitizers_disabled ( )
1206- || sess. opts . cg . link_self_contained . is_sanitizers_enabled ( ) )
1207- && match crate_type {
1208- CrateType :: Executable => true ,
1209- CrateType :: Dylib | CrateType :: Cdylib | CrateType :: ProcMacro => {
1210- sess. target . is_like_osx || sess. target . is_like_msvc
1211- }
1212- CrateType :: Rlib | CrateType :: Staticlib => false ,
1213- } ;
1200+ if sess. target . is_like_android {
1201+ // Sanitizer runtime libraries are provided dynamically on Android
1202+ // targets.
1203+ return ;
1204+ }
12141205
1215- if !needs_runtime {
1206+ if sess. opts . cg . link_self_contained . is_sanitizers_disabled ( ) {
1207+ // Linking against in-tree sanitizer runtimes is disabled via
1208+ // `-C link-self-contained=-sanitizers`
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+ {
12161223 return ;
12171224 }
12181225
0 commit comments