[compiler-rt] d83c900 - [sanitizer_common][test] Enable tests on SPARC
Rainer Orth via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 1 13:34:34 PST 2022
Author: Rainer Orth
Date: 2022-02-01T22:33:56+01:00
New Revision: d83c9005cf81e6f7cc00b695726d0c5698b83c1e
URL: https://github.com/llvm/llvm-project/commit/d83c9005cf81e6f7cc00b695726d0c5698b83c1e
DIFF: https://github.com/llvm/llvm-project/commit/d83c9005cf81e6f7cc00b695726d0c5698b83c1e.diff
LOG: [sanitizer_common][test] Enable tests on SPARC
Unfortunately, the `sanitizer_common` tests are disabled on many targets
that are supported by `sanitizer_common`, making it easy to miss issues
with that support. This patch enables SPARC testing.
Beside the enabling proper, the patch fixes (together with D91607
<https://reviews.llvm.org/D91607>) the failures of the `symbolize_pc.cpp`,
`symbolize_pc_demangle.cpp`, and `symbolize_pc_inline.cpp` tests. They
lack calls to `__builtin_extract_return_addr`. When those are added, they
`PASS` when compiled with `gcc`. `clang` incorrectly doesn't implement a
non-default `__builtin_extract_return_addr` on several targets, SPARC
included.
Because `__builtin_extract_return_addr(__builtin_return_addr(0))` is quite
a mouthful and I'm uncertain if the code needs to compile with msvc which
appparently has it's own `_ReturnAddress`, I've introduced
`__sanitizer_return_addr` to hide the difference and complexity. Because
on 32-bit SPARC `__builtin_extract_return_addr` differs when the calling
function returns a struct, I've added a testcase for that.
There are a couple more tests failing on SPARC that I will deal with
separately.
Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and
`x86_64-pc-linux-gnu`.
Differential Revision: https://reviews.llvm.org/D91608
Added:
Modified:
compiler-rt/include/sanitizer/common_interface_defs.h
compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
compiler-rt/test/sanitizer_common/TestCases/symbolize_pc.cpp
compiler-rt/test/sanitizer_common/TestCases/symbolize_pc_demangle.cpp
compiler-rt/test/sanitizer_common/TestCases/symbolize_pc_inline.cpp
Removed:
################################################################################
diff --git a/compiler-rt/include/sanitizer/common_interface_defs.h b/compiler-rt/include/sanitizer/common_interface_defs.h
index 692b8f70c9697..ba58ad46f32d0 100644
--- a/compiler-rt/include/sanitizer/common_interface_defs.h
+++ b/compiler-rt/include/sanitizer/common_interface_defs.h
@@ -211,6 +211,15 @@ void __sanitizer_symbolize_pc(void *pc, const char *fmt, char *out_buf,
// Same as __sanitizer_symbolize_pc, but for data section (i.e. globals).
void __sanitizer_symbolize_global(void *data_ptr, const char *fmt,
char *out_buf, size_t out_buf_size);
+// Determine the return address.
+#if !defined(_MSC_VER) || defined(__clang__)
+#define __sanitizer_return_address() \
+ __builtin_extract_return_addr(__builtin_return_address(0))
+#else
+extern "C" void *_ReturnAddress(void);
+#pragma intrinsic(_ReturnAddress)
+#define __sanitizer_return_address() _ReturnAddress()
+#endif
/// Sets the callback to be called immediately before death on error.
///
diff --git a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
index 4602ee9398f53..929ef15bd846d 100644
--- a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
+++ b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
@@ -3,7 +3,7 @@ include(CompilerRTCompile)
clang_compiler_add_cxx_check()
# FIXME: use SANITIZER_COMMON_SUPPORTED_ARCH here
-filter_available_targets(SANITIZER_UNITTEST_SUPPORTED_ARCH x86_64 i386 mips64 mips64el riscv64)
+filter_available_targets(SANITIZER_UNITTEST_SUPPORTED_ARCH x86_64 i386 mips64 mips64el riscv64 sparcv9 sparc)
if(APPLE)
darwin_filter_host_archs(SANITIZER_UNITTEST_SUPPORTED_ARCH SANITIZER_UNITTEST_SUPPORTED_ARCH)
endif()
diff --git a/compiler-rt/test/sanitizer_common/TestCases/symbolize_pc.cpp b/compiler-rt/test/sanitizer_common/TestCases/symbolize_pc.cpp
index 4cea49f33ce99..8c794b5f166e3 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/symbolize_pc.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/symbolize_pc.cpp
@@ -9,33 +9,47 @@ int GLOBAL_VAR_ABC;
void SymbolizeSmallBuffer() {
char data[] = "abcdef";
- __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", data, 0);
+ __sanitizer_symbolize_pc(__sanitizer_return_address(), "%p %F %L", data, 0);
printf("UNCHANGED '%s'\n", data);
- __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", data, 1);
+ __sanitizer_symbolize_pc(__sanitizer_return_address(), "%p %F %L", data, 1);
printf("EMPTY '%s'\n", data);
- __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", data,
+ __sanitizer_symbolize_pc(__sanitizer_return_address(), "%p %F %L", data,
sizeof(data));
printf("PARTIAL '%s'\n", data);
}
void SymbolizeCaller() {
char data[100];
- __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", data,
+ __sanitizer_symbolize_pc(__sanitizer_return_address(), "%p %F %L", data,
sizeof(data));
printf("FIRST_FORMAT %s\n", data);
- __sanitizer_symbolize_pc(__builtin_return_address(0),
+ __sanitizer_symbolize_pc(__sanitizer_return_address(),
"FUNC:%f LINE:%l FILE:%s", data, sizeof(data));
printf("SECOND_FORMAT %s\n", data);
- __sanitizer_symbolize_pc(__builtin_return_address(0),
- "LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"
- "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"
- "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"
- "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"
- "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG"
- "FUNC:%f LINE:%l FILE:%s", data, sizeof(data));
+ __sanitizer_symbolize_pc(__sanitizer_return_address(),
+ "LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"
+ "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"
+ "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"
+ "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"
+ "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG"
+ "FUNC:%f LINE:%l FILE:%s",
+ data, sizeof(data));
printf("LONG_FORMAT %s\n", data);
}
+struct s {
+ int i;
+};
+
+struct s SymbolizeSRet() {
+ char data[100];
+ __sanitizer_symbolize_pc(__sanitizer_return_address(),
+ "FUNC:%f LINE:%l FILE:%s", data, sizeof(data));
+ printf("SRET: %s\n", data);
+ struct s s = {1};
+ return s;
+}
+
void SymbolizeData() {
char data[100];
__sanitizer_symbolize_global(&GLOBAL_VAR_ABC, "%g %s:%l", data, sizeof(data));
@@ -52,6 +66,10 @@ int main() {
// CHECK: SECOND_FORMAT FUNC:main LINE:[[@LINE+1]] FILE:symbolize_pc.cpp
SymbolizeCaller();
+ struct s s;
+ // CHECK: SRET: FUNC:main LINE:[[@LINE+1]] FILE:symbolize_pc.cpp
+ s = SymbolizeSRet();
+
// CHECK: GLOBAL: GLOBAL_VAR_ABC
SymbolizeData();
}
diff --git a/compiler-rt/test/sanitizer_common/TestCases/symbolize_pc_demangle.cpp b/compiler-rt/test/sanitizer_common/TestCases/symbolize_pc_demangle.cpp
index 62ac5d0b23379..6e035c16a3045 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/symbolize_pc_demangle.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/symbolize_pc_demangle.cpp
@@ -12,7 +12,7 @@
char buffer[10000];
__attribute__((noinline)) static void Symbolize() {
- __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", buffer,
+ __sanitizer_symbolize_pc(__sanitizer_return_address(), "%p %F %L", buffer,
sizeof(buffer));
for (char *p = buffer; strlen(p); p += strlen(p) + 1)
printf("%s\n", p);
diff --git a/compiler-rt/test/sanitizer_common/TestCases/symbolize_pc_inline.cpp b/compiler-rt/test/sanitizer_common/TestCases/symbolize_pc_inline.cpp
index a39f30e0633dc..e95ef324db652 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/symbolize_pc_inline.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/symbolize_pc_inline.cpp
@@ -12,7 +12,7 @@
char buffer[10000];
__attribute__((noinline)) static void Symbolize() {
- __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", buffer,
+ __sanitizer_symbolize_pc(__sanitizer_return_address(), "%p %F %L", buffer,
sizeof(buffer));
for (char *p = buffer; strlen(p); p += strlen(p) + 1)
printf("%s\n", p);
More information about the llvm-commits
mailing list