[llvm] 632ea69 - [sanitizer][sancov] Use pc-1 for s390x

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 23 13:35:26 PST 2022


Author: Fangrui Song
Date: 2022-02-23T13:35:22-08:00
New Revision: 632ea6929d5cb5b3c4ff1b44df5d4e075d9f1dda

URL: https://github.com/llvm/llvm-project/commit/632ea6929d5cb5b3c4ff1b44df5d4e075d9f1dda
DIFF: https://github.com/llvm/llvm-project/commit/632ea6929d5cb5b3c4ff1b44df5d4e075d9f1dda.diff

LOG: [sanitizer][sancov] Use pc-1 for s390x

The stack trace addresses may be odd (normally addresses should be even), but
seems a good compromise when the instruction length (2,4,6) cannot be detected
easily.

Reviewed By: uweigand

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

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
    compiler-rt/test/tsan/test.h
    llvm/tools/sancov/sancov.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp
index 5a6329eec484d..3013a0c4abdf0 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp
@@ -46,7 +46,7 @@ uptr StackTrace::GetNextInstructionPc(uptr pc) {
   }
   // bail-out if could not figure out the instruction size
   return 0;
-#elif SANITIZER_I386 || SANITIZER_X32 || SANITIZER_X64
+#elif SANITIZER_S390 || SANITIZER_I386 || SANITIZER_X32 || SANITIZER_X64
   return pc + 1;
 #else
   return pc + 4;

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
index 82c2fda351277..9a5f8fb13a29d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
@@ -98,7 +98,7 @@ uptr StackTrace::GetPreviousInstructionPc(uptr pc) {
   // It seems 
diff icult to figure out the exact instruction length -
   // pc - 2 seems like a safe option for the purposes of stack tracing
   return pc - 2;
-#elif SANITIZER_I386 || SANITIZER_X32 || SANITIZER_X64
+#elif SANITIZER_S390 || SANITIZER_I386 || SANITIZER_X32 || SANITIZER_X64
   return pc - 1;
 #else
   return pc - 4;

diff  --git a/compiler-rt/test/tsan/test.h b/compiler-rt/test/tsan/test.h
index 66350996d104b..efd66cbf91a43 100644
--- a/compiler-rt/test/tsan/test.h
+++ b/compiler-rt/test/tsan/test.h
@@ -69,13 +69,12 @@ unsigned long long monotonic_clock_ns() {
 #endif
 
 //The const kPCInc must be in sync with StackTrace::GetPreviousInstructionPc
-#if defined(__powerpc64__) || defined(__arm__) || defined(__aarch64__)
-// PCs are always 4 byte aligned.
-const int kPCInc = 4;
+#if defined(__s390__) || defined(__i386__) || defined(__x86_64__)
+const int kPCInc = 1;
 #elif defined(__sparc__) || defined(__mips__)
 const int kPCInc = 8;
 #else
-const int kPCInc = 1;
+const int kPCInc = 4;
 #endif
 
 #ifdef __cplusplus

diff  --git a/llvm/tools/sancov/sancov.cpp b/llvm/tools/sancov/sancov.cpp
index 9a523984df75d..7609b2b53981b 100644
--- a/llvm/tools/sancov/sancov.cpp
+++ b/llvm/tools/sancov/sancov.cpp
@@ -698,7 +698,7 @@ static uint64_t getPreviousInstructionPc(uint64_t PC,
     return PC - 8;
   if (TheTriple.isRISCV())
     return PC - 2;
-  if (TheTriple.isX86())
+  if (TheTriple.isX86() || TheTriple.isSystemZ())
     return PC - 1;
   return PC - 4;
 }


        


More information about the llvm-commits mailing list