libminijail: Bring back the runtime ASan/HWAsan checks

This change brings back the ASan-as-DSO checks since they are needed
under some configurations.

Bug: 130916252
Test: make clean && make USE_ASAN=yes tests
Change-Id: I5b1e9cf6de311a0b2ddea5e51945d71c1b32fa2e
diff --git a/util.h b/util.h
index 341ed67..02e7c23 100644
--- a/util.h
+++ b/util.h
@@ -106,19 +106,34 @@
 #endif
 }
 
-static inline bool running_with_asan(void)
+static inline bool compiled_with_asan(void)
 {
 #if defined(__SANITIZE_ADDRESS__)
 	/* For gcc. */
 	return true;
 #elif defined(__has_feature)
 	/* For clang. */
-	return __has_feature(address_sanitizer);
+	return __has_feature(address_sanitizer) ||
+	       __has_feature(hwaddress_sanitizer);
 #else
 	return false;
 #endif
 }
 
+void __asan_init(void) attribute_weak;
+void __hwasan_init(void) attribute_weak;
+
+static inline bool running_with_asan(void)
+{
+	/*
+	 * There are some configurations under which ASan needs a dynamic (as
+	 * opposed to compile-time) test. Some Android processes that start
+	 * before /data is mounted run with non-instrumented libminijail.so, so
+	 * the symbol-sniffing code must be present to make the right decision.
+	 */
+	return compiled_with_asan() || &__asan_init != 0 || &__hwasan_init != 0;
+}
+
 int lookup_syscall(const char *name);
 const char *lookup_syscall_name(int nr);