Merge "hwasan+fortify: don't use _chk variants of memcpy()/memmove()/memset()." into main am: 0f4721d55a

Original change: https://android-review.googlesource.com/c/platform/bionic/+/3537082

Change-Id: Idd266cba74cdc198f7b5d125312a04b26289ad6a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/libc/include/bits/fortify/string.h b/libc/include/bits/fortify/string.h
index 4ec356f..15cb17d 100644
--- a/libc/include/bits/fortify/string.h
+++ b/libc/include/bits/fortify/string.h
@@ -43,7 +43,8 @@
 
 #if defined(__BIONIC_FORTIFY)
 
-#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+/* hwasan intercepts memcpy() but not the _chk variant. */
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED && !__has_feature(hwaddress_sanitizer)
 /* No diag -- clang diagnoses misuses of this on its own.  */
 __BIONIC_FORTIFY_INLINE
 void* _Nonnull memcpy(void* _Nonnull const dst __pass_object_size0, const void* _Nonnull src, size_t copy_amount)
@@ -51,7 +52,10 @@
         __overloadable {
     return __builtin___memcpy_chk(dst, src, copy_amount, __bos0(dst));
 }
+#endif
 
+/* hwasan intercepts memmove() but not the _chk variant. */
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED && !__has_feature(hwaddress_sanitizer)
 /* No diag -- clang diagnoses misuses of this on its own.  */
 __BIONIC_FORTIFY_INLINE
 void* _Nonnull memmove(void* _Nonnull const dst __pass_object_size0, const void* _Nonnull src, size_t len)
@@ -68,7 +72,8 @@
         __overloadable
         /* If you're a user who wants this warning to go away: use `(&memset)(foo, bar, baz)`. */
         __clang_warning_if(c && !n, "'memset' will set 0 bytes; maybe the arguments got flipped?") {
-#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+/* hwasan intercepts memset() but not the _chk variant. */
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED && !__has_feature(hwaddress_sanitizer)
     return __builtin___memset_chk(s, c, n, __bos0(s));
 #else
     return __builtin_memset(s, c, n);