How do I tell at compile time - in code - if the binary is built with Address Sanitizer enabled? Is there some preprocessor define available?
How to tell if Address Sanitizer is active?
There's no macro, AFAIK. I usually add one as a part of the build type.
However, if it's just so that you can prevent a function being instrumented, you can tag them with __attribute__((no_sanitize_address)). E.g:
__attribute__((no_sanitize_address))
void myfunc()
{
// Sketchy or hot-path code.
}
You might be looking for __has_feature(address_sanitizer):
There is __has_feature(address_sanitizer), an example how to use it is at http://clang.llvm.org/docs/AddressSanitizer.html :
#if defined(__has_feature)
# if __has_feature(address_sanitizer)
// code that builds only under AddressSanitizer
# endif
#endif
Perfect. Thank you.