[PATCH] D61871: [asan] Fix debug asan build link error

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 15 16:28:46 PDT 2019


rnk updated this revision to Diff 199698.
rnk marked 5 inline comments as done.
rnk added a comment.

- various fixes to RTEMS / Myriad codepath


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61871/new/

https://reviews.llvm.org/D61871

Files:
  compiler-rt/lib/asan/asan_malloc_local.h
  compiler-rt/lib/asan/asan_new_delete.cc


Index: compiler-rt/lib/asan/asan_new_delete.cc
===================================================================
--- compiler-rt/lib/asan/asan_new_delete.cc
+++ compiler-rt/lib/asan/asan_new_delete.cc
@@ -71,25 +71,19 @@
 // TODO(alekseyshl): throw std::bad_alloc instead of dying on OOM.
 // For local pool allocation, align to SHADOW_GRANULARITY to match asan
 // allocator behavior.
-#define OPERATOR_NEW_BODY(type, nothrow) \
-  if (ALLOCATE_FROM_LOCAL_POOL) {\
-    void *res = MemalignFromLocalPool(SHADOW_GRANULARITY, size);\
-    if (!nothrow) CHECK(res);\
-    return res;\
-  }\
-  GET_STACK_TRACE_MALLOC;\
-  void *res = asan_memalign(0, size, &stack, type);\
-  if (!nothrow && UNLIKELY(!res)) ReportOutOfMemory(size, &stack);\
+#define OPERATOR_NEW_BODY(type, nothrow)            \
+  MAYBE_ALLOCATE_FROM_LOCAL_POOL(nothrow);          \
+  GET_STACK_TRACE_MALLOC;                           \
+  void *res = asan_memalign(0, size, &stack, type); \
+  if (!nothrow && UNLIKELY(!res))                   \
+    ReportOutOfMemory(size, &stack);                \
   return res;
-#define OPERATOR_NEW_BODY_ALIGN(type, nothrow) \
-  if (ALLOCATE_FROM_LOCAL_POOL) {\
-    void *res = MemalignFromLocalPool((uptr)align, size);\
-    if (!nothrow) CHECK(res);\
-    return res;\
-  }\
-  GET_STACK_TRACE_MALLOC;\
-  void *res = asan_memalign((uptr)align, size, &stack, type);\
-  if (!nothrow && UNLIKELY(!res)) ReportOutOfMemory(size, &stack);\
+#define OPERATOR_NEW_BODY_ALIGN(type, nothrow)                \
+  MAYBE_ALLOCATE_FROM_LOCAL_POOL(nothrow);                    \
+  GET_STACK_TRACE_MALLOC;                                     \
+  void *res = asan_memalign((uptr)align, size, &stack, type); \
+  if (!nothrow && UNLIKELY(!res))                             \
+    ReportOutOfMemory(size, &stack);                          \
   return res;
 
 // On OS X it's not enough to just provide our own 'operator new' and
Index: compiler-rt/lib/asan/asan_malloc_local.h
===================================================================
--- compiler-rt/lib/asan/asan_malloc_local.h
+++ compiler-rt/lib/asan/asan_malloc_local.h
@@ -17,25 +17,33 @@
 #include "sanitizer_common/sanitizer_platform.h"
 #include "asan_internal.h"
 
-// On RTEMS, we use the local pool to handle memory allocation when the ASan
-// run-time is not up.
+#if SANITIZER_RTEMS
+
 static INLINE bool EarlyMalloc() {
-  return SANITIZER_RTEMS && (!__asan::asan_inited ||
-                             __asan::asan_init_is_running);
+  return !__asan::asan_inited || __asan::asan_init_is_running;
 }
 
-void* MemalignFromLocalPool(uptr alignment, uptr size);
-
-#if SANITIZER_RTEMS
-
 bool IsFromLocalPool(const void *ptr);
+void *MemalignFromLocalPool(uptr alignment, uptr size);
+
+// On RTEMS, we use the local pool to handle memory allocation when the ASan
+// run-time is not up. This macro is expanded in the context of the operator new
+// implementation.
+#define MAYBE_ALLOCATE_FROM_LOCAL_POOL(nothrow)                    \
+  do {                                                             \
+    if (UNLIKELY(EarlyMalloc())) {                                 \
+      void *res = MemalignFromLocalPool(SHADOW_GRANULARITY, size); \
+      if (!nothrow)                                                \
+        CHECK(res);                                                \
+      return res;                                                  \
+    }                                                              \
+  } while (0)
 
-#define ALLOCATE_FROM_LOCAL_POOL UNLIKELY(EarlyMalloc())
 #define IS_FROM_LOCAL_POOL(ptr) UNLIKELY(IsFromLocalPool(ptr))
 
 #else  // SANITIZER_RTEMS
 
-#define ALLOCATE_FROM_LOCAL_POOL 0
+#define MAYBE_ALLOCATE_FROM_LOCAL_POOL(nothrow)
 #define IS_FROM_LOCAL_POOL(ptr) 0
 
 #endif  // SANITIZER_RTEMS


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61871.199698.patch
Type: text/x-patch
Size: 3820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190515/52b02f19/attachment.bin>


More information about the llvm-commits mailing list