From 632ea6929d5cb5b3c4ff1b44df5d4e075d9f1dda Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 23 Feb 2022 13:35:22 -0800 Subject: [PATCH] [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 --- compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp | 2 +- compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h | 2 +- compiler-rt/test/tsan/test.h | 7 +++---- llvm/tools/sancov/sancov.cpp | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp index 5a6329e..3013a0c 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 82c2fda..9a5f8fb 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 difficult 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 6635099..efd66cb 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 9a52398..7609b2b 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; } -- 2.7.4