Move OPENSSL_ASAN to base.h.

Saves having it in several places.

Change-Id: I329e1bf4dd4a7f51396e36e2604280fcca32b58c
Reviewed-on: https://boringssl-review.googlesource.com/16026
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/crypto/fipsmodule/bcm.c b/crypto/fipsmodule/bcm.c
index 4dbaef9..62abd70 100644
--- a/crypto/fipsmodule/bcm.c
+++ b/crypto/fipsmodule/bcm.c
@@ -95,14 +95,6 @@
 
 #if defined(BORINGSSL_FIPS)
 
-#if defined(__has_feature)
-#if __has_feature(address_sanitizer)
-/* Integrity tests cannot run under ASAN because it involves reading the full
- * .text section, which triggers the global-buffer overflow detection. */
-#define OPENSSL_ASAN
-#endif
-#endif
-
 static void hexdump(const uint8_t *in, size_t len) {
   for (size_t i = 0; i < len; i++) {
     printf("%02x", in[i]);
@@ -296,7 +288,7 @@
   return ec_key;
 }
 
-#ifndef OPENSSL_ASAN
+#if !defined(OPENSSL_ASAN)
 /* These symbols are filled in by delocate.go. They point to the start and end
  * of the module, and the location of the integrity hash, respectively. */
 extern const uint8_t BORINGSSL_bcm_text_start[];
@@ -309,7 +301,9 @@
 static void BORINGSSL_bcm_power_on_self_test(void) {
   CRYPTO_library_init();
 
-#ifndef OPENSSL_ASAN
+#if !defined(OPENSSL_ASAN)
+  /* Integrity tests cannot run under ASAN because it involves reading the full
+   * .text section, which triggers the global-buffer overflow detection. */
   const uint8_t *const start = BORINGSSL_bcm_text_start;
   const uint8_t *const end = BORINGSSL_bcm_text_end;
 
diff --git a/crypto/fipsmodule/is_fips.c b/crypto/fipsmodule/is_fips.c
index 9af0dd2..bff1a05 100644
--- a/crypto/fipsmodule/is_fips.c
+++ b/crypto/fipsmodule/is_fips.c
@@ -18,12 +18,6 @@
 /* This file exists in order to give the fipsmodule target, in non-FIPS mode,
  * something to compile. */
 
-#if defined(__has_feature)
-#if __has_feature(address_sanitizer)
-#define OPENSSL_ASAN
-#endif
-#endif
-
 int FIPS_mode(void) {
 #if defined(BORINGSSL_FIPS) && !defined(OPENSSL_ASAN)
   return 1;
diff --git a/crypto/test/malloc.cc b/crypto/test/malloc.cc
index 33f0972..bb1a6a6 100644
--- a/crypto/test/malloc.cc
+++ b/crypto/test/malloc.cc
@@ -16,7 +16,7 @@
 
 #if defined(__has_feature)
 #if __has_feature(address_sanitizer) || __has_feature(memory_sanitizer)
-#define OPENSSL_ASAN
+#define OPENSSL_ASAN_OR_MSAN
 #endif
 #endif
 
@@ -32,7 +32,7 @@
 // TODO(davidben): See if this and ASan's and MSan's interceptors can be made to
 // coexist.
 #if defined(__linux__) && defined(OPENSSL_GLIBC) && !defined(OPENSSL_ARM) && \
-    !defined(OPENSSL_AARCH64) && !defined(OPENSSL_ASAN)
+    !defined(OPENSSL_AARCH64) && !defined(OPENSSL_ASAN_OR_MSAN)
 
 #include <errno.h>
 #include <signal.h>
diff --git a/include/openssl/base.h b/include/openssl/base.h
index c8ebee8..6ea9501 100644
--- a/include/openssl/base.h
+++ b/include/openssl/base.h
@@ -202,6 +202,12 @@
 #define BORINGSSL_UNSAFE_DETERMINISTIC_MODE
 #endif
 
+#if defined(__has_feature)
+#if __has_feature(address_sanitizer)
+#define OPENSSL_ASAN
+#endif
+#endif
+
 /* CRYPTO_THREADID is a dummy value. */
 typedef int CRYPTO_THREADID;