Commit af21e4d6 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

Add a FOLLY_ASAN_ENABLED macro

Summary:
Add a new macro to track if folly was compiled with ASAN enabled.  This
is in addition to the existing FOLLY_SANITIZE_ADDRESS macro, which
reports if the current .cpp file is being compiled with ASAN enabled.

In particular, these macros differ in open source builds if folly was
compiled without ASAN enabled, but some of its headers are being
included from downstream libraries that are being built with ASAN
enabled.

Previously several headers would define structures differently based on
`FOLLY_SANITIZE_ADDRESS`, which meant that different .cpp files would see
different definitions of these structures.  `FOLLY_ASAN_ENABLED` is generally
the correct macro to use for situations like this.

This diff fixes F14Table.h to use FOLLY_ASAN_ENABLED, but several other
headers probably should also be updated in the future.

I did not change the behavior of FOLLY_SANITIZE_ADDRESS, since it appears to
be used by several projects outside of folly, and they expect it to report if
their code is being compiled with ASAN enabled.

At the moment the open source build does not support compiling with ASAN,
so FOLLY_ASAN_ENABLED is always disabled in open source builds.

Reviewed By: nbronson

Differential Revision: D10401271

fbshipit-source-id: 7e028737b42eecae93f06538dcf76dd64bd32e6a
parent a368d112
......@@ -241,3 +241,6 @@ if (FOLLY_HAVE_LIBGFLAGS)
set(FOLLY_GFLAGS_NAMESPACE google)
endif()
endif()
# We currently don't support enabling ASAN in CMake-based builds
set(FOLLY_ASAN_ENABLED OFF)
......@@ -74,4 +74,6 @@
#cmakedefine FOLLY_HAVE_LIBZSTD 1
#cmakedefine FOLLY_HAVE_LIBBZ2 1
#cmakedefine FOLLY_ASAN_ENABLED 1
#cmakedefine FOLLY_SUPPORT_SHARED_LIBRARY 1
......@@ -59,8 +59,18 @@
#define FOLLY_HAS_FEATURE(...) 0
#endif
/* Define a convenience macro to test when address sanitizer is being used
* across the different compilers (e.g. clang, gcc) */
/* FOLLY_SANITIZE_ADDRESS is defined to 1 if the current compilation unit
* is being compiled with ASAN enabled.
*
* Beware when using this macro in a header file: this macro may change values
* across compilation units if some libraries are built with ASAN enabled
* and some built with ASAN disabled. For instance, this may occur, if folly
* itself was compiled without ASAN but a downstream project that uses folly is
* compiling with ASAN enabled.
*
* Use FOLLY_ASAN_ENABLED (defined in folly-config.h) to check if folly itself
* was compiled with ASAN enabled.
*/
#if FOLLY_HAS_FEATURE(address_sanitizer) || __SANITIZE_ADDRESS__
#define FOLLY_SANITIZE_ADDRESS 1
#endif
......
......@@ -106,7 +106,13 @@ constexpr bool kIsArchPPC64 = FOLLY_PPC64 == 1;
namespace folly {
#if FOLLY_SANITIZE_ADDRESS
/**
* folly::kIsSanitizeAddress reports if folly was compiled with ASAN
* enabled. Note that for compilation units outside of folly that include
* folly/Portability.h, the value of kIsSanitizeAddress may be different
* from whether or not the current compilation unit is being compiled with ASAN.
*/
#if FOLLY_ASAN_ENABLED
constexpr bool kIsSanitizeAddress = true;
#else
constexpr bool kIsSanitizeAddress = false;
......
......@@ -47,7 +47,7 @@
#include <folly/container/detail/F14Defaults.h>
#include <folly/container/detail/F14IntrinsicsAvailability.h>
#if FOLLY_SANITIZE_ADDRESS && defined(FOLLY_TLS)
#if FOLLY_ASAN_ENABLED && defined(FOLLY_TLS)
#define FOLLY_F14_TLS_IF_ASAN FOLLY_TLS
#else
#define FOLLY_F14_TLS_IF_ASAN
......
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