Commit 91199bbe authored by Andrew Gallagher's avatar Andrew Gallagher Committed by Jordan DeLong

folly: disable address sanitizer warnings on fbstring

Summary:
The fbstring constructor does word-aligned copies which may creep
past the end of the C string, which address sanitizer doesn't like.

This also adds a address-sanitizer-disabling-attribute to both
Portability.h (for general use) and a (gross) copy in FBString.h
since it gets put into libstdc++.

Test Plan: ran address sanitizer on folly tests

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D950586
parent 9bfa4150
...@@ -112,6 +112,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -112,6 +112,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
namespace folly { namespace folly {
#endif #endif
// Different versions of gcc/clang support different versions of
// the address sanitizer attribute.
#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
# endif
#elif defined (__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)
# define FBSTRING_DISABLE_ADDRESS_SANITIZER \
__attribute__((__no_address_safety_analysis__))
#else
# define FBSTRING_DISABLE_ADDRESS_SANITIZER
#endif
namespace fbstring_detail { namespace fbstring_detail {
template <class InIt, class OutIt> template <class InIt, class OutIt>
...@@ -347,7 +366,11 @@ public: ...@@ -347,7 +366,11 @@ public:
} }
} }
fbstring_core(const Char *const data, const size_t size) { // NOTE(agallagher): The word-aligned copy path copies bytes which are
// outside the range of the string, and makes address sanitizer unhappy,
// so just disable it on this function.
fbstring_core(const Char *const data, const size_t size)
FBSTRING_DISABLE_ADDRESS_SANITIZER {
// Simplest case first: small strings are bitblitted // Simplest case first: small strings are bitblitted
if (size <= maxSmallSize) { if (size <= maxSmallSize) {
// Layout is: Char* data_, size_t size_, size_t capacity_ // Layout is: Char* data_, size_t size_, size_t capacity_
...@@ -2392,6 +2415,7 @@ struct hash< ::folly::fbstring> { ...@@ -2392,6 +2415,7 @@ struct hash< ::folly::fbstring> {
#endif // _LIBSTDCXX_FBSTRING #endif // _LIBSTDCXX_FBSTRING
#undef FBSTRING_DISABLE_ADDRESS_SANITIZER
#undef FBSTRING_LIKELY #undef FBSTRING_LIKELY
#undef FBSTRING_UNLIKELY #undef FBSTRING_UNLIKELY
......
...@@ -84,4 +84,23 @@ struct MaxAlign { char c; } __attribute__((aligned)); ...@@ -84,4 +84,23 @@ struct MaxAlign { char c; } __attribute__((aligned));
# endif # endif
#endif #endif
/* Define attribute wrapper for function attribute used to disable
* address sanitizer instrumentation */
#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
# endif
#elif defined (__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)
# define FOLLY_DISABLE_ADDRESS_SANITIZER \
__attribute__((__no_address_safety_analysis__))
#else
# define FOLLY_DISABLE_ADDRESS_SANITIZER
#endif
#endif // FOLLY_PORTABILITY_H_ #endif // FOLLY_PORTABILITY_H_
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