X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FCPortability.h;h=37d97382e56b5d5d88e3759ce645a5d191c34e93;hb=8cf0c3e0f10e74e89f0b868e4168ec019ed9b998;hp=cf69d6a3e764d8796ce52904151fd5467dc46e1a;hpb=22afce906d7e98d95f8c45c3301072d9fd891d41;p=folly.git diff --git a/folly/CPortability.h b/folly/CPortability.h index cf69d6a3..37d97382 100644 --- a/folly/CPortability.h +++ b/folly/CPortability.h @@ -1,5 +1,5 @@ /* - * Copyright 2014 Facebook, Inc. + * Copyright 2016 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef CPORTABILITY_H -#define CPORTABILITY_H +#pragma once /* These definitions are in a separate file so that they * may be included from C- as well as C++-based projects. */ @@ -37,7 +36,10 @@ * has issues when inlining is used, so disable that as well. */ #ifdef FOLLY_SANITIZE_ADDRESS # if defined(__clang__) -# if __has_attribute(__no_address_safety_analysis__) +# if __has_attribute(__no_sanitize__) +# define FOLLY_DISABLE_ADDRESS_SANITIZER \ + __attribute__((__no_sanitize__("address"), __noinline__)) +# elif __has_attribute(__no_address_safety_analysis__) # define FOLLY_DISABLE_ADDRESS_SANITIZER \ __attribute__((__no_address_safety_analysis__, __noinline__)) # elif __has_attribute(__no_sanitize_address__) @@ -53,4 +55,28 @@ # define FOLLY_DISABLE_ADDRESS_SANITIZER #endif +/* Define a convenience macro to test when thread sanitizer is being used + * across the different compilers (e.g. clang, gcc) */ +#if defined(__clang__) +# if __has_feature(thread_sanitizer) +# define FOLLY_SANITIZE_THREAD 1 +# endif +#elif defined(__GNUC__) && __SANITIZE_THREAD__ +# define FOLLY_SANITIZE_THREAD 1 #endif + +/** + * ASAN/MSAN/TSAN define pre-processor symbols: + * ADDRESS_SANITIZER/MEMORY_SANITIZER/THREAD_SANITIZER. + * + * UBSAN doesn't define anything and makes it hard to + * conditionally compile. + * + * The build system should define UNDEFINED_SANITIZER=1 when UBSAN is + * used as folly whitelists some functions. + */ +#if UNDEFINED_SANITIZER +# define UBSAN_DISABLE(x) __attribute__((no_sanitize(x))) +#else +# define UBSAN_DISABLE(x) +#endif // UNDEFINED_SANITIZER