folly: don't inline functions with ASAN disabled
authorAndrew Gallagher <agallagher@fb.com>
Tue, 10 Sep 2013 20:22:22 +0000 (13:22 -0700)
committerJordan DeLong <jdelong@fb.com>
Sun, 22 Sep 2013 23:39:56 +0000 (16:39 -0700)
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
folly/Portability.h

index e00194babfe8d542b4c5e0f1e1bca8150fe99a28..e19943ab837ada34102153d9e8a4910c0e3bc0d9 100644 (file)
@@ -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
 
index 07852f2d97792825937ab5dceb182030f0642f8b..89d5199ed4b6645fab88c4e6a463905ae0a1b454 100644 (file)
@@ -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