2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 /* These definitions are in a separate file so that they
20 * may be included from C- as well as C++-based projects. */
22 /* Define a convenience macro to test when address sanitizer is being used
23 * across the different compilers (e.g. clang, gcc) */
24 #if defined(__clang__)
25 # if __has_feature(address_sanitizer)
26 # define FOLLY_SANITIZE_ADDRESS 1
28 #elif defined (__GNUC__) && \
29 (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ >= 5)) && \
31 # define FOLLY_SANITIZE_ADDRESS 1
34 /* Define attribute wrapper for function attribute used to disable
35 * address sanitizer instrumentation. Unfortunately, this attribute
36 * has issues when inlining is used, so disable that as well. */
37 #ifdef FOLLY_SANITIZE_ADDRESS
38 # if defined(__clang__)
39 # if __has_attribute(__no_sanitize__)
40 # define FOLLY_DISABLE_ADDRESS_SANITIZER \
41 __attribute__((__no_sanitize__("address"), __noinline__))
42 # elif __has_attribute(__no_address_safety_analysis__)
43 # define FOLLY_DISABLE_ADDRESS_SANITIZER \
44 __attribute__((__no_address_safety_analysis__, __noinline__))
45 # elif __has_attribute(__no_sanitize_address__)
46 # define FOLLY_DISABLE_ADDRESS_SANITIZER \
47 __attribute__((__no_sanitize_address__, __noinline__))
49 # elif defined(__GNUC__)
50 # define FOLLY_DISABLE_ADDRESS_SANITIZER \
51 __attribute__((__no_address_safety_analysis__, __noinline__))
54 #ifndef FOLLY_DISABLE_ADDRESS_SANITIZER
55 # define FOLLY_DISABLE_ADDRESS_SANITIZER
58 /* Define a convenience macro to test when thread sanitizer is being used
59 * across the different compilers (e.g. clang, gcc) */
60 #if defined(__clang__)
61 # if __has_feature(thread_sanitizer)
62 # define FOLLY_SANITIZE_THREAD 1
64 #elif defined(__GNUC__) && __SANITIZE_THREAD__
65 # define FOLLY_SANITIZE_THREAD 1
69 * ASAN/MSAN/TSAN define pre-processor symbols:
70 * ADDRESS_SANITIZER/MEMORY_SANITIZER/THREAD_SANITIZER.
72 * UBSAN doesn't define anything and makes it hard to
73 * conditionally compile.
75 * The build system should define UNDEFINED_SANITIZER=1 when UBSAN is
76 * used as folly whitelists some functions.
78 #if UNDEFINED_SANITIZER
79 # define UBSAN_DISABLE(x) __attribute__((no_sanitize(x)))
81 # define UBSAN_DISABLE(x)
82 #endif // UNDEFINED_SANITIZER