libhfuzz: call __asan_init is it's available, and under Android
int hfuzz_module_instrument = 0;
static bool guards_initialized = false;
-
-#if defined(__has_feature)
-#if __has_feature(address_sanitizer)
-void __asan_init(void);
-#endif /* __has_feature(address_sanitizer) */
-#endif /* defined(__has_feature) */
+void __asan_init(void) __attribute__((weak));
/*
* We require SSE4.2 with x86-(32|64) for the 'popcnt', as it's much faster than the software
@@ -44,7 +39,6 @@ static feedback_t bbMapFb;
feedback_t* feedback = &bbMapFb;
uint32_t my_thread_no = 0;
-
__attribute__((constructor)) static void mapBB(void) {
char* my_thread_no_str = getenv(_HF_THREAD_NO_ENV);
if (my_thread_no_str == NULL) {
@@ -239,8 +233,6 @@ ATTRIBUTE_X86_REQUIRE_SSE42 void __sanitizer_cov_trace_pc_guard_init(
ATTRIBUTE_X86_REQUIRE_SSE42 void __sanitizer_cov_trace_pc_guard(uint32_t* guard) {
#if defined(__ANDROID__)
-#if defined(__has_feature)
-#if __has_feature(address_sanitizer)
// ANDROID: Bionic invokes routines that Honggfuzz wraps, before either
// ASAN or Honggfuzz have initialized. Check to see if Honggfuzz
// has initialized -- if not, force ASAN to initialize (otherwise
@@ -248,12 +240,12 @@ ATTRIBUTE_X86_REQUIRE_SSE42 void __sanitizer_cov_trace_pc_guard(uint32_t* guard)
//
// Defer all trace_pc_guard activity until trace_pc_guard_init is
// invoked via sancov.module_ctor in the normal process of things.
- if (!inited) {
+ if (!guards_initialized) {
+ if (__asan_init) {
__asan_init();
+ }
return;
}
-#endif /* __has_feature(address_sanitizer) */
-#endif /* defined(__has_feature) */
#endif /* defined(__ANDROID__) */
if (*guard == 0U) {
return;
