@@ -1187,20 +1187,27 @@ mod win {
11871187}
11881188
11891189fn add_sanitizer_libraries ( sess : & Session , crate_type : CrateType , linker : & mut dyn Linker ) {
1190- // On macOS the runtimes are distributed as dylibs which should be linked to
1191- // both executables and dynamic shared objects. Everywhere else the runtimes
1192- // are currently distributed as static libraries which should be linked to
1193- // executables only.
1194- let needs_runtime = !sess. target . is_like_android
1195- && ( !sess. opts . cg . link_self_contained . is_sanitizers_disabled ( )
1196- || sess. opts . cg . link_self_contained . is_sanitizers_enabled ( ) )
1197- && match crate_type {
1198- CrateType :: Executable => true ,
1199- CrateType :: Dylib | CrateType :: Cdylib | CrateType :: ProcMacro => sess. target . is_like_osx ,
1200- CrateType :: Rlib | CrateType :: Staticlib => false ,
1201- } ;
1190+ if sess. target . is_like_android {
1191+ // Sanitizer runtime libraries are provided dynamically on Android
1192+ // targets.
1193+ return ;
1194+ }
12021195
1203- if !needs_runtime {
1196+ if sess. opts . cg . link_self_contained . is_sanitizers_disabled ( ) {
1197+ // Linking against in-tree sanitizer runtimes is disabled via
1198+ // `-C link-self-contained=-sanitizers`
1199+ return ;
1200+ }
1201+
1202+ // On macOS the runtimes are distributed as dylibs which should be linked to
1203+ // both executables and dynamic shared objects. On most other platforms the
1204+ // runtimes are currently distributed as static libraries which should be
1205+ // linked to executables only.
1206+ if match crate_type {
1207+ CrateType :: Executable => false ,
1208+ CrateType :: Dylib | CrateType :: Cdylib | CrateType :: ProcMacro => !sess. target . is_like_osx ,
1209+ CrateType :: Rlib | CrateType :: Staticlib => true ,
1210+ } {
12041211 return ;
12051212 }
12061213
0 commit comments