@@ -1197,22 +1197,29 @@ fn add_sanitizer_libraries(
1197
1197
crate_type : CrateType ,
1198
1198
linker : & mut dyn Linker ,
1199
1199
) {
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
+ }
1205
+
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 , crate_type == 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 ) {
1214
1222
1215
- if !needs_runtime {
1216
1223
return ;
1217
1224
}
1218
1225
0 commit comments