@@ -1201,21 +1201,29 @@ fn add_sanitizer_libraries(
1201
1201
crate_type : CrateType ,
1202
1202
linker : & mut dyn Linker ,
1203
1203
) {
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
+ }
1217
1209
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
+ {
1219
1227
return ;
1220
1228
}
1221
1229
0 commit comments