[compiler-rt] 1216f4c - [GWP-ASan] Use functions in backtrace test, not line numbers.

Mitch Phillips via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 26 10:10:35 PDT 2020


Author: Mitch Phillips
Date: 2020-03-26T10:10:24-07:00
New Revision: 1216f4c0ea0c232d545ce3ab8f858c696e085d47

URL: https://github.com/llvm/llvm-project/commit/1216f4c0ea0c232d545ce3ab8f858c696e085d47
DIFF: https://github.com/llvm/llvm-project/commit/1216f4c0ea0c232d545ce3ab8f858c696e085d47.diff

LOG: [GWP-ASan] Use functions in backtrace test, not line numbers.

Summary:
There's no unwinding functionality on Android that allows for line
numbers to be retrieved in-process. As a result, we can't have
this backtrace test run on Android.

Cleanup the test to use optnone functions instead, which is more stable
than line numbers anyway.

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: #sanitizers, morehouse, cferris

Tags: #sanitizers

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

Added: 
    

Modified: 
    compiler-rt/lib/gwp_asan/tests/backtrace.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/gwp_asan/tests/backtrace.cpp b/compiler-rt/lib/gwp_asan/tests/backtrace.cpp
index 6c9a9309ed8b..b3d44270bb2a 100644
--- a/compiler-rt/lib/gwp_asan/tests/backtrace.cpp
+++ b/compiler-rt/lib/gwp_asan/tests/backtrace.cpp
@@ -11,34 +11,52 @@
 #include "gwp_asan/crash_handler.h"
 #include "gwp_asan/tests/harness.h"
 
-TEST_F(BacktraceGuardedPoolAllocator, DoubleFree) {
-  void *Ptr = GPA.allocate(1);
+// Optnone to ensure that the calls to these functions are not optimized away,
+// as we're looking for them in the backtraces.
+__attribute((optnone)) void *
+AllocateMemory(gwp_asan::GuardedPoolAllocator &GPA) {
+  return GPA.allocate(1);
+}
+__attribute((optnone)) void
+DeallocateMemory(gwp_asan::GuardedPoolAllocator &GPA, void *Ptr) {
   GPA.deallocate(Ptr);
+}
+__attribute((optnone)) void
+DeallocateMemory2(gwp_asan::GuardedPoolAllocator &GPA, void *Ptr) {
+  GPA.deallocate(Ptr);
+}
+__attribute__((optnone)) void TouchMemory(void *Ptr) {
+  *(reinterpret_cast<volatile char *>(Ptr)) = 7;
+}
+
+TEST_F(BacktraceGuardedPoolAllocator, DoubleFree) {
+  void *Ptr = AllocateMemory(GPA);
+  DeallocateMemory(GPA, Ptr);
 
   std::string DeathRegex = "Double Free.*";
-  DeathRegex.append("backtrace\\.cpp:26.*");
+  DeathRegex.append("DeallocateMemory2.*");
 
   DeathRegex.append("was deallocated.*");
-  DeathRegex.append("backtrace\\.cpp:16.*");
+  DeathRegex.append("DeallocateMemory.*");
 
   DeathRegex.append("was allocated.*");
-  DeathRegex.append("backtrace\\.cpp:15.*");
-  ASSERT_DEATH(GPA.deallocate(Ptr), DeathRegex);
+  DeathRegex.append("AllocateMemory.*");
+  ASSERT_DEATH(DeallocateMemory2(GPA, Ptr), DeathRegex);
 }
 
 TEST_F(BacktraceGuardedPoolAllocator, UseAfterFree) {
-  char *Ptr = static_cast<char *>(GPA.allocate(1));
-  GPA.deallocate(Ptr);
+  void *Ptr = AllocateMemory(GPA);
+  DeallocateMemory(GPA, Ptr);
 
   std::string DeathRegex = "Use After Free.*";
-  DeathRegex.append("backtrace\\.cpp:41.*");
+  DeathRegex.append("TouchMemory.*");
 
   DeathRegex.append("was deallocated.*");
-  DeathRegex.append("backtrace\\.cpp:31.*");
+  DeathRegex.append("DeallocateMemory.*");
 
   DeathRegex.append("was allocated.*");
-  DeathRegex.append("backtrace\\.cpp:30.*");
-  ASSERT_DEATH({ *Ptr = 7; }, DeathRegex);
+  DeathRegex.append("AllocateMemory.*");
+  ASSERT_DEATH(TouchMemory(Ptr), DeathRegex);
 }
 
 TEST(Backtrace, Short) {


        


More information about the llvm-commits mailing list