Skip to content

Commit 8ca0bcd

Browse files
thurstondaokblast
authored andcommitted
[sanitizer][test] Clean up allow_user_segv.cpp test case (llvm#163870)
This test case has two issues: - it has some special treatment of SIGBUS, ostensibly to handle old Darwin platforms, but this been silently broken for years because the assertions only check for SEGV. - it has `XFAIL: !compiler-rt-optimized && tsan` [*], because the null pointer dereference will trigger an assertion (invalid app memory) rather than a segfault. We fix both issues by directly raising SIGSEGV. We also considerably simplify the test case, while maintaining the core test of chaining the segfault handlers. [*] This test might also fail when other sanitizer runtimes are compiled with assertions, though those combinations are not well-tested by buildbots.
1 parent 6bd122a commit 8ca0bcd

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

compiler-rt/test/sanitizer_common/TestCases/Linux/allow_user_segv.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Regression test for
22
// https://code.google.com/p/address-sanitizer/issues/detail?id=180
3-
// Fails with debug checks: https://bugs.llvm.org/show_bug.cgi?id=46860
4-
// XFAIL: !compiler-rt-optimized && tsan
53

64
// FIXME: Implement.
75
// XFAIL: hwasan
@@ -31,15 +29,12 @@
3129
#include <stdio.h>
3230
#include <stdlib.h>
3331

34-
struct sigaction original_sigaction_sigbus;
3532
struct sigaction original_sigaction_sigsegv;
3633

3734
void User_OnSIGSEGV(int signum, siginfo_t *siginfo, void *context) {
3835
fprintf(stderr, "User sigaction called\n");
3936
struct sigaction original_sigaction = {};
40-
if (signum == SIGBUS)
41-
original_sigaction = original_sigaction_sigbus;
42-
else if (signum == SIGSEGV)
37+
if (signum == SIGSEGV)
4338
original_sigaction = original_sigaction_sigsegv;
4439
else {
4540
printf("Invalid signum");
@@ -55,11 +50,6 @@ void User_OnSIGSEGV(int signum, siginfo_t *siginfo, void *context) {
5550
exit(1);
5651
}
5752

58-
int DoSEGV() {
59-
volatile int *x = 0;
60-
return *x;
61-
}
62-
6353
bool InstallHandler(int signum, struct sigaction *original_sigaction) {
6454
struct sigaction user_sigaction = {};
6555
user_sigaction.sa_sigaction = User_OnSIGSEGV;
@@ -72,13 +62,15 @@ bool InstallHandler(int signum, struct sigaction *original_sigaction) {
7262
}
7363

7464
int main() {
75-
// Let's install handlers for both SIGSEGV and SIGBUS, since pre-Yosemite
76-
// 32-bit Darwin triggers SIGBUS instead.
77-
if (InstallHandler(SIGSEGV, &original_sigaction_sigsegv) &&
78-
InstallHandler(SIGBUS, &original_sigaction_sigbus)) {
65+
if (InstallHandler(SIGSEGV, &original_sigaction_sigsegv))
7966
fprintf(stderr, "User sigaction installed\n");
80-
}
81-
return DoSEGV();
67+
68+
// Trying to organically segfault by dereferencing a pointer can be tricky
69+
// when the sanitizer runtime is built with assertions. Additionally, some
70+
// older platforms may SIGBUS instead.
71+
raise(SIGSEGV);
72+
73+
return 0;
8274
}
8375

8476
// CHECK0-NOT: Sanitizer:DEADLYSIGNAL

0 commit comments

Comments
 (0)