[PATCH] D46459: [asan] On RTEMS, checks for asan_inited before entering ASan run-time

Walter Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 7 08:52:31 PDT 2018


waltl updated this revision to Diff 145474.
waltl added a comment.

Add guard for fake stack.  This was missing in the initial commit, so
even though we may need to redo it I just want to make the patches
consistent first.


Repository:
  rL LLVM

https://reviews.llvm.org/D46459

Files:
  compiler-rt/lib/asan/asan_fake_stack.cc
  compiler-rt/lib/asan/asan_poisoning.cc
  compiler-rt/lib/asan/asan_rtl.cc


Index: compiler-rt/lib/asan/asan_rtl.cc
===================================================================
--- compiler-rt/lib/asan/asan_rtl.cc
+++ compiler-rt/lib/asan/asan_rtl.cc
@@ -95,16 +95,22 @@
 #define ASAN_REPORT_ERROR(type, is_write, size)                     \
 extern "C" NOINLINE INTERFACE_ATTRIBUTE                             \
 void __asan_report_ ## type ## size(uptr addr) {                    \
+  if (SANITIZER_RTEMS && !asan_inited)                              \
+    return;                                                         \
   GET_CALLER_PC_BP_SP;                                              \
   ReportGenericError(pc, bp, sp, addr, is_write, size, 0, true);    \
 }                                                                   \
 extern "C" NOINLINE INTERFACE_ATTRIBUTE                             \
 void __asan_report_exp_ ## type ## size(uptr addr, u32 exp) {       \
+  if (SANITIZER_RTEMS && !asan_inited)                              \
+    return;                                                         \
   GET_CALLER_PC_BP_SP;                                              \
   ReportGenericError(pc, bp, sp, addr, is_write, size, exp, true);  \
 }                                                                   \
 extern "C" NOINLINE INTERFACE_ATTRIBUTE                             \
 void __asan_report_ ## type ## size ## _noabort(uptr addr) {        \
+  if (SANITIZER_RTEMS && !asan_inited)                              \
+    return;                                                         \
   GET_CALLER_PC_BP_SP;                                              \
   ReportGenericError(pc, bp, sp, addr, is_write, size, 0, false);   \
 }                                                                   \
@@ -123,24 +129,32 @@
 #define ASAN_REPORT_ERROR_N(type, is_write)                                 \
 extern "C" NOINLINE INTERFACE_ATTRIBUTE                                     \
 void __asan_report_ ## type ## _n(uptr addr, uptr size) {                   \
+  if (SANITIZER_RTEMS && !asan_inited)                                      \
+    return;                                                                 \
   GET_CALLER_PC_BP_SP;                                                      \
   ReportGenericError(pc, bp, sp, addr, is_write, size, 0, true);            \
 }                                                                           \
 extern "C" NOINLINE INTERFACE_ATTRIBUTE                                     \
 void __asan_report_exp_ ## type ## _n(uptr addr, uptr size, u32 exp) {      \
+  if (SANITIZER_RTEMS && !asan_inited)                                      \
+    return;                                                                 \
   GET_CALLER_PC_BP_SP;                                                      \
   ReportGenericError(pc, bp, sp, addr, is_write, size, exp, true);          \
 }                                                                           \
 extern "C" NOINLINE INTERFACE_ATTRIBUTE                                     \
 void __asan_report_ ## type ## _n_noabort(uptr addr, uptr size) {           \
+  if (SANITIZER_RTEMS && !asan_inited)                                      \
+    return;                                                                 \
   GET_CALLER_PC_BP_SP;                                                      \
   ReportGenericError(pc, bp, sp, addr, is_write, size, 0, false);           \
 }                                                                           \
 
 ASAN_REPORT_ERROR_N(load, false)
 ASAN_REPORT_ERROR_N(store, true)
 
 #define ASAN_MEMORY_ACCESS_CALLBACK_BODY(type, is_write, size, exp_arg, fatal) \
+    if (SANITIZER_RTEMS && !asan_inited)                                       \
+      return;                                                                  \
     if (SANITIZER_RTEMS && !AddrIsInMem(addr) && !AddrIsInShadow(addr))        \
       return;                                                                  \
     uptr sp = MEM_TO_SHADOW(addr);                                             \
@@ -524,6 +538,9 @@
 using namespace __asan;  // NOLINT
 
 void NOINLINE __asan_handle_no_return() {
+  if (SANITIZER_RTEMS && !asan_inited)
+    return;
+
   if (asan_init_is_running)
     return;
 
Index: compiler-rt/lib/asan/asan_poisoning.cc
===================================================================
--- compiler-rt/lib/asan/asan_poisoning.cc
+++ compiler-rt/lib/asan/asan_poisoning.cc
@@ -181,6 +181,8 @@
 
 uptr __asan_region_is_poisoned(uptr beg, uptr size) {
   if (!size) return 0;
+  if (SANITIZER_RTEMS && !asan_inited)
+    return 0;
   uptr end = beg + size;
   if (SANITIZER_MYRIAD2) {
     // On Myriad, address not in DRAM range need to be treated as
Index: compiler-rt/lib/asan/asan_fake_stack.cc
===================================================================
--- compiler-rt/lib/asan/asan_fake_stack.cc
+++ compiler-rt/lib/asan/asan_fake_stack.cc
@@ -192,6 +192,8 @@
 }
 
 static FakeStack *GetFakeStackFast() {
+  if (SANITIZER_RTEMS && !asan_inited)
+    return nullptr;
   if (FakeStack *fs = GetTLSFakeStack())
     return fs;
   if (!__asan_option_detect_stack_use_after_return)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46459.145474.patch
Type: text/x-patch
Size: 5205 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180507/b11d292b/attachment.bin>


More information about the llvm-commits mailing list