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
76 lines
2.4 KiB
C++
76 lines
2.4 KiB
C++
// RUN: %clangxx -O0 %s -o %t
|
|
// RUN: %env_tool_opts=strip_path_prefix=/TestCases/ %run %t 2>&1 | FileCheck %s
|
|
//
|
|
// Tests __sanitizer_symbolize_pc.
|
|
#include <stdio.h>
|
|
#include <sanitizer/common_interface_defs.h>
|
|
|
|
int GLOBAL_VAR_ABC;
|
|
|
|
void SymbolizeSmallBuffer() {
|
|
char data[] = "abcdef";
|
|
__sanitizer_symbolize_pc(__sanitizer_return_address(), "%p %F %L", data, 0);
|
|
printf("UNCHANGED '%s'\n", data);
|
|
__sanitizer_symbolize_pc(__sanitizer_return_address(), "%p %F %L", data, 1);
|
|
printf("EMPTY '%s'\n", 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(__sanitizer_return_address(), "%p %F %L", data,
|
|
sizeof(data));
|
|
printf("FIRST_FORMAT %s\n", data);
|
|
__sanitizer_symbolize_pc(__sanitizer_return_address(),
|
|
"FUNC:%f LINE:%l FILE:%s", data, sizeof(data));
|
|
printf("SECOND_FORMAT %s\n", 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));
|
|
printf("GLOBAL: %s\n", data);
|
|
}
|
|
|
|
int main() {
|
|
// CHECK: UNCHANGED 'abcdef'
|
|
// CHECK: EMPTY ''
|
|
// CHECK: PARTIAL '0x{{.*}}'
|
|
SymbolizeSmallBuffer();
|
|
|
|
// CHECK: FIRST_FORMAT 0x{{.*}} in main symbolize_pc.cpp:[[@LINE+2]]
|
|
// 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();
|
|
}
|