Commit d3468ea8 authored by Andrew Gallagher's avatar Andrew Gallagher Committed by Peter Griess

folly: add a FOLLY_SANITIZE_ADDRESS macro to Portability.h

Summary:
Defines a macro to portably test whether address sanitizer is
enabled across the different compilers we use.

Test Plan:
Compiled source file with address sanitizer and verified macro
was defined.

Reviewed By: delong.j@fb.com

FB internal diff: D978196
parent 464cc74d
...@@ -84,11 +84,24 @@ struct MaxAlign { char c; } __attribute__((aligned)); ...@@ -84,11 +84,24 @@ struct MaxAlign { char c; } __attribute__((aligned));
# endif # endif
#endif #endif
/* Define a convenience macro to test when address sanitizer is being used
* across the different compilers (e.g. clang, gcc) */
#if defined(__clang__)
# if __has_feature(address_sanitizer)
# define FOLLY_SANITIZE_ADDRESS 1
# endif
#elif defined (__GNUC__) && \
(((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ >= 5)) && \
__SANITIZE_ADDRESS__
# define FOLLY_SANITIZE_ADDRESS 1
#endif
/* Define attribute wrapper for function attribute used to disable /* Define attribute wrapper for function attribute used to disable
* address sanitizer instrumentation. Unfortunately, this attribute * address sanitizer instrumentation. Unfortunately, this attribute
* has issues when inlining is used, so disable that as well. */ * has issues when inlining is used, so disable that as well. */
#if defined(__clang__) #ifdef FOLLY_SANITIZE_ADDRESS
# if __has_feature(address_sanitizer) # if defined(__clang__)
# if __has_attribute(__no_address_safety_analysis__) # if __has_attribute(__no_address_safety_analysis__)
# define FOLLY_DISABLE_ADDRESS_SANITIZER \ # define FOLLY_DISABLE_ADDRESS_SANITIZER \
__attribute__((__no_address_safety_analysis__, __noinline__)) __attribute__((__no_address_safety_analysis__, __noinline__))
...@@ -96,13 +109,10 @@ struct MaxAlign { char c; } __attribute__((aligned)); ...@@ -96,13 +109,10 @@ struct MaxAlign { char c; } __attribute__((aligned));
# define FOLLY_DISABLE_ADDRESS_SANITIZER \ # define FOLLY_DISABLE_ADDRESS_SANITIZER \
__attribute__((__no_sanitize_address__, __noinline__)) __attribute__((__no_sanitize_address__, __noinline__))
# endif # endif
# elif defined(__GNUC__)
# define FOLLY_DISABLE_ADDRESS_SANITIZER \
__attribute__((__no_address_safety_analysis__, __noinline__))
# endif # endif
#elif defined (__GNUC__) && \
(__GNUC__ == 4) && \
(__GNUC_MINOR__ >= 8) && \
__SANITIZE_ADDRESS__
# define FOLLY_DISABLE_ADDRESS_SANITIZER \
__attribute__((__no_address_safety_analysis__, __noinline__))
#endif #endif
#ifndef FOLLY_DISABLE_ADDRESS_SANITIZER #ifndef FOLLY_DISABLE_ADDRESS_SANITIZER
# define FOLLY_DISABLE_ADDRESS_SANITIZER # define FOLLY_DISABLE_ADDRESS_SANITIZER
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment