From 95201d11af705ab3b0b383d13019b0120218f1e6 Mon Sep 17 00:00:00 2001 From: Andrew Gallagher Date: Tue, 10 Sep 2013 13:22:22 -0700 Subject: [PATCH] folly: don't inline functions with ASAN disabled Summary: The address sanitizer disabling attribute has some issues in gcc when the function is inlined. Test Plan: Built and ran tao tests with ASAN. Reviewed By: philipp@fb.com FB internal diff: D962930 --- folly/FBString.h | 29 +++++++++++++++++------------ folly/Portability.h | 29 +++++++++++++++++------------ 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/folly/FBString.h b/folly/FBString.h index e00194ba..e19943ab 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -113,21 +113,26 @@ namespace folly { #endif // Different versions of gcc/clang support different versions of -// the address sanitizer attribute. +// the address sanitizer attribute. Unfortunately, this attribute +// has issues when inlining is used, so disable that as well. #if defined(__clang__) -# if __has_attribute(__no_address_safety_analysis__) -# define FBSTRING_DISABLE_ADDRESS_SANITIZER \ - __attribute__((__no_address_safety_analysis__)) -# elif __has_attribute(__no_sanitize_address__) -# define FBSTRING_DISABLE_ADDRESS_SANITIZER \ - __attribute__((__no_sanitize_address__)) -# else -# define FBSTRING_DISABLE_ADDRESS_SANITIZER +# if __has_feature(address_sanitizer) +# if __has_attribute(__no_address_safety_analysis__) +# define FBSTRING_DISABLE_ADDRESS_SANITIZER \ + __attribute__((__no_address_safety_analysis__, __noinline__)) +# elif __has_attribute(__no_sanitize_address__) +# define FBSTRING_DISABLE_ADDRESS_SANITIZER \ + __attribute__((__no_sanitize_address__, __noinline__)) +# endif # endif -#elif defined (__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8) +#elif defined (__GNUC__) && \ + (__GNUC__ == 4) && \ + (__GNUC_MINOR__ >= 8) && \ + __SANITIZE_ADDRESS__ # define FBSTRING_DISABLE_ADDRESS_SANITIZER \ - __attribute__((__no_address_safety_analysis__)) -#else + __attribute__((__no_address_safety_analysis__, __noinline__)) +#endif +#ifndef FBSTRING_DISABLE_ADDRESS_SANITIZER # define FBSTRING_DISABLE_ADDRESS_SANITIZER #endif diff --git a/folly/Portability.h b/folly/Portability.h index 07852f2d..89d5199e 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -85,21 +85,26 @@ struct MaxAlign { char c; } __attribute__((aligned)); #endif /* Define attribute wrapper for function attribute used to disable - * address sanitizer instrumentation */ + * address sanitizer instrumentation. Unfortunately, this attribute + * has issues when inlining is used, so disable that as well. */ #if defined(__clang__) -# if __has_attribute(__no_address_safety_analysis__) -# define FOLLY_DISABLE_ADDRESS_SANITIZER \ - __attribute__((__no_address_safety_analysis__)) -# elif __has_attribute(__no_sanitize_address__) -# define FOLLY_DISABLE_ADDRESS_SANITIZER \ - __attribute__((__no_sanitize_address__)) -# else -# define FOLLY_DISABLE_ADDRESS_SANITIZER +# if __has_feature(address_sanitizer) +# if __has_attribute(__no_address_safety_analysis__) +# define FOLLY_DISABLE_ADDRESS_SANITIZER \ + __attribute__((__no_address_safety_analysis__, __noinline__)) +# elif __has_attribute(__no_sanitize_address__) +# define FOLLY_DISABLE_ADDRESS_SANITIZER \ + __attribute__((__no_sanitize_address__, __noinline__)) +# endif # endif -#elif defined (__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8) +#elif defined (__GNUC__) && \ + (__GNUC__ == 4) && \ + (__GNUC_MINOR__ >= 8) && \ + __SANITIZE_ADDRESS__ # define FOLLY_DISABLE_ADDRESS_SANITIZER \ - __attribute__((__no_address_safety_analysis__)) -#else + __attribute__((__no_address_safety_analysis__, __noinline__)) +#endif +#ifndef FOLLY_DISABLE_ADDRESS_SANITIZER # define FOLLY_DISABLE_ADDRESS_SANITIZER #endif -- 2.34.1