[compiler-rt] 19edfb3 - [GWP-ASan] Add GWP_ASAN_ prefix to macros.

Mitch Phillips via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 25 12:27:09 PST 2019


Author: Mitch Phillips
Date: 2019-11-25T12:27:00-08:00
New Revision: 19edfb37282ade36c502d8fcea9c915c443474c9

URL: https://github.com/llvm/llvm-project/commit/19edfb37282ade36c502d8fcea9c915c443474c9
DIFF: https://github.com/llvm/llvm-project/commit/19edfb37282ade36c502d8fcea9c915c443474c9.diff

LOG: [GWP-ASan] Add GWP_ASAN_ prefix to macros.

Summary:
When platforms use their own `LIKELY()` definitions, it can be quite
troublesome to ensure they don't conflict with the GWP-ASan internal
definitions. Just force the GWP_ASAN_ prefix to help this issue.

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: #sanitizers, llvm-commits, cferris, pcc

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D70683

Added: 
    

Modified: 
    compiler-rt/lib/gwp_asan/definitions.h
    compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp
    compiler-rt/lib/gwp_asan/guarded_pool_allocator.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/gwp_asan/definitions.h b/compiler-rt/lib/gwp_asan/definitions.h
index 1190adbd4f4f..bebe56c55a26 100644
--- a/compiler-rt/lib/gwp_asan/definitions.h
+++ b/compiler-rt/lib/gwp_asan/definitions.h
@@ -9,21 +9,9 @@
 #ifndef GWP_ASAN_DEFINITIONS_H_
 #define GWP_ASAN_DEFINITIONS_H_
 
-#define TLS_INITIAL_EXEC __thread __attribute__((tls_model("initial-exec")))
+#define GWP_ASAN_TLS_INITIAL_EXEC __thread __attribute__((tls_model("initial-exec")))
 
-#ifdef LIKELY
-# undef LIKELY
-#endif // defined(LIKELY)
-#define LIKELY(X) __builtin_expect(!!(X), 1)
-
-#ifdef UNLIKELY
-# undef UNLIKELY
-#endif // defined(UNLIKELY)
-#define UNLIKELY(X) __builtin_expect(!!(X), 0)
-
-#ifdef ALWAYS_INLINE
-# undef ALWAYS_INLINE
-#endif // defined(ALWAYS_INLINE)
-#define ALWAYS_INLINE inline __attribute__((always_inline))
+#define GWP_ASAN_UNLIKELY(X) __builtin_expect(!!(X), 0)
+#define GWP_ASAN_ALWAYS_INLINE inline __attribute__((always_inline))
 
 #endif // GWP_ASAN_DEFINITIONS_H_

diff  --git a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp
index ef497336025f..b7a5b591223d 100644
--- a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp
+++ b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp
@@ -527,7 +527,7 @@ void GuardedPoolAllocator::reportErrorInternal(uintptr_t AccessPtr, Error E) {
     printAllocDeallocTraces(AccessPtr, Meta, Printf, PrintBacktrace);
 }
 
-TLS_INITIAL_EXEC
+GWP_ASAN_TLS_INITIAL_EXEC
 GuardedPoolAllocator::ThreadLocalPackedVariables
     GuardedPoolAllocator::ThreadLocals;
 } // namespace gwp_asan

diff  --git a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
index 57ad61e9cf4f..7e6e13769d32 100644
--- a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
+++ b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
@@ -100,19 +100,19 @@ class GuardedPoolAllocator {
   void init(const options::Options &Opts);
 
   // Return whether the allocation should be randomly chosen for sampling.
-  ALWAYS_INLINE bool shouldSample() {
+  GWP_ASAN_ALWAYS_INLINE bool shouldSample() {
     // NextSampleCounter == 0 means we "should regenerate the counter".
     //                   == 1 means we "should sample this allocation".
-    if (UNLIKELY(ThreadLocals.NextSampleCounter == 0))
+    if (GWP_ASAN_UNLIKELY(ThreadLocals.NextSampleCounter == 0))
       ThreadLocals.NextSampleCounter =
           (getRandomUnsigned32() % AdjustedSampleRate) + 1;
 
-    return UNLIKELY(--ThreadLocals.NextSampleCounter == 0);
+    return GWP_ASAN_UNLIKELY(--ThreadLocals.NextSampleCounter == 0);
   }
 
   // Returns whether the provided pointer is a current sampled allocation that
   // is owned by this pool.
-  ALWAYS_INLINE bool pointerIsMine(const void *Ptr) const {
+  GWP_ASAN_ALWAYS_INLINE bool pointerIsMine(const void *Ptr) const {
     uintptr_t P = reinterpret_cast<uintptr_t>(Ptr);
     return GuardedPagePool <= P && P < GuardedPagePoolEnd;
   }
@@ -267,7 +267,7 @@ class GuardedPoolAllocator {
     // allocation.
     bool RecursiveGuard = false;
   };
-  static TLS_INITIAL_EXEC ThreadLocalPackedVariables ThreadLocals;
+  static GWP_ASAN_TLS_INITIAL_EXEC ThreadLocalPackedVariables ThreadLocals;
 };
 } // namespace gwp_asan
 


        


More information about the llvm-commits mailing list