forked from OSchip/llvm-project
[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
This commit is contained in:
parent
d7c4072fdb
commit
d83c9005cf
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue