| diff --git compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp |
| index b87798603fda..10e34ee86cce 100644 |
| --- compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp |
| +++ compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp |
| @@ -147,11 +147,18 @@ DEFINE_REAL(char *, strstr, const char *, const char *) |
| DEFINE_REAL(char *, strcasestr, const char *, const char *) |
| DEFINE_REAL(void *, memmem, const void *, size_t, const void *, size_t) |
| |
| +extern "C" __attribute__((weak)) bool |
| +__sanitizer_weak_is_relevant_pc(void * caller_pc) { |
| + return false; |
| +} |
| + |
| ATTRIBUTE_INTERFACE int bcmp(const char *s1, const char *s2, size_t n) { |
| if (!FuzzerInited) |
| return internal_memcmp(s1, s2, n); |
| int result = REAL(bcmp)(s1, s2, n); |
| - __sanitizer_weak_hook_memcmp(GET_CALLER_PC(), s1, s2, n, result); |
| + void *caller_pc = GET_CALLER_PC(); |
| + if (__sanitizer_weak_is_relevant_pc(caller_pc)) |
| + __sanitizer_weak_hook_memcmp(caller_pc, s1, s2, n, result); |
| return result; |
| } |
| |
| @@ -159,7 +166,9 @@ ATTRIBUTE_INTERFACE int memcmp(const void *s1, const void *s2, size_t n) { |
| if (!FuzzerInited) |
| return internal_memcmp(s1, s2, n); |
| int result = REAL(memcmp)(s1, s2, n); |
| - __sanitizer_weak_hook_memcmp(GET_CALLER_PC(), s1, s2, n, result); |
| + void *caller_pc = GET_CALLER_PC(); |
| + if (__sanitizer_weak_is_relevant_pc(caller_pc)) |
| + __sanitizer_weak_hook_memcmp(caller_pc, s1, s2, n, result); |
| return result; |
| } |
| |
| @@ -167,7 +176,9 @@ ATTRIBUTE_INTERFACE int strncmp(const char *s1, const char *s2, size_t n) { |
| if (!FuzzerInited) |
| return internal_strncmp(s1, s2, n); |
| int result = REAL(strncmp)(s1, s2, n); |
| - __sanitizer_weak_hook_strncmp(GET_CALLER_PC(), s1, s2, n, result); |
| + void *caller_pc = GET_CALLER_PC(); |
| + if (__sanitizer_weak_is_relevant_pc(caller_pc)) |
| + __sanitizer_weak_hook_strncmp(caller_pc, s1, s2, n, result); |
| return result; |
| } |
| |
| @@ -175,21 +186,27 @@ ATTRIBUTE_INTERFACE int strcmp(const char *s1, const char *s2) { |
| if (!FuzzerInited) |
| return internal_strcmp(s1, s2); |
| int result = REAL(strcmp)(s1, s2); |
| - __sanitizer_weak_hook_strcmp(GET_CALLER_PC(), s1, s2, result); |
| + void *caller_pc = GET_CALLER_PC(); |
| + if (__sanitizer_weak_is_relevant_pc(caller_pc)) |
| + __sanitizer_weak_hook_strcmp(caller_pc, s1, s2, result); |
| return result; |
| } |
| |
| ATTRIBUTE_INTERFACE int strncasecmp(const char *s1, const char *s2, size_t n) { |
| ensureFuzzerInited(); |
| int result = REAL(strncasecmp)(s1, s2, n); |
| - __sanitizer_weak_hook_strncasecmp(GET_CALLER_PC(), s1, s2, n, result); |
| + void *caller_pc = GET_CALLER_PC(); |
| + if (__sanitizer_weak_is_relevant_pc(caller_pc)) |
| + __sanitizer_weak_hook_strncasecmp(caller_pc, s1, s2, n, result); |
| return result; |
| } |
| |
| ATTRIBUTE_INTERFACE int strcasecmp(const char *s1, const char *s2) { |
| ensureFuzzerInited(); |
| int result = REAL(strcasecmp)(s1, s2); |
| - __sanitizer_weak_hook_strcasecmp(GET_CALLER_PC(), s1, s2, result); |
| + void *caller_pc = GET_CALLER_PC(); |
| + if (__sanitizer_weak_is_relevant_pc(caller_pc)) |
| + __sanitizer_weak_hook_strcasecmp(caller_pc, s1, s2, result); |
| return result; |
| } |
| |
| @@ -197,14 +214,18 @@ ATTRIBUTE_INTERFACE char *strstr(const char *s1, const char *s2) { |
| if (!FuzzerInited) |
| return internal_strstr(s1, s2); |
| char *result = REAL(strstr)(s1, s2); |
| - __sanitizer_weak_hook_strstr(GET_CALLER_PC(), s1, s2, result); |
| + void *caller_pc = GET_CALLER_PC(); |
| + if (__sanitizer_weak_is_relevant_pc(caller_pc)) |
| + __sanitizer_weak_hook_strstr(caller_pc, s1, s2, result); |
| return result; |
| } |
| |
| ATTRIBUTE_INTERFACE char *strcasestr(const char *s1, const char *s2) { |
| ensureFuzzerInited(); |
| char *result = REAL(strcasestr)(s1, s2); |
| - __sanitizer_weak_hook_strcasestr(GET_CALLER_PC(), s1, s2, result); |
| + void *caller_pc = GET_CALLER_PC(); |
| + if (__sanitizer_weak_is_relevant_pc(caller_pc)) |
| + __sanitizer_weak_hook_strcasestr(caller_pc, s1, s2, result); |
| return result; |
| } |
| |
| @@ -212,7 +233,9 @@ ATTRIBUTE_INTERFACE |
| void *memmem(const void *s1, size_t len1, const void *s2, size_t len2) { |
| ensureFuzzerInited(); |
| void *result = REAL(memmem)(s1, len1, s2, len2); |
| - __sanitizer_weak_hook_memmem(GET_CALLER_PC(), s1, len1, s2, len2, result); |
| + void *caller_pc = GET_CALLER_PC(); |
| + if (__sanitizer_weak_is_relevant_pc(caller_pc)) |
| + __sanitizer_weak_hook_memmem(caller_pc, s1, len1, s2, len2, result); |
| return result; |
| } |
| |