|
| 1 | +commit ddcbab37ac0e5743a8d39be3dd48d967f4c85504 |
| 2 | +Author: serge-sans-paille < [email protected]> |
| 3 | +Date: Thu Mar 14 07:41:46 2024 +0100 |
| 4 | + |
| 5 | + [compiler-rt] Also consider SIGPROF as a synchronous signal |
| 6 | + |
| 7 | + Blocking that signal causes inter-blocking for profilers that monitor |
| 8 | + threads through that signal. |
| 9 | + |
| 10 | + Update tests accordingly to use an uncaught signal. |
| 11 | + |
| 12 | + This is a recommit of 6f3f659ce9ab91002b4a490b0ce4b085981383cd with the |
| 13 | + tests fixed. |
| 14 | + |
| 15 | + Fix #83844 and #83561 |
| 16 | + |
| 17 | +diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp |
| 18 | +index 8ffc703b05ea..2bebe651b994 100644 |
| 19 | +--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp |
| 20 | ++++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp |
| 21 | +@@ -126,6 +126,7 @@ const int SIGFPE = 8; |
| 22 | + const int SIGSEGV = 11; |
| 23 | + const int SIGPIPE = 13; |
| 24 | + const int SIGTERM = 15; |
| 25 | ++const int SIGPROF = 27; |
| 26 | + #if defined(__mips__) || SANITIZER_FREEBSD || SANITIZER_APPLE || SANITIZER_NETBSD |
| 27 | + const int SIGBUS = 10; |
| 28 | + const int SIGSYS = 12; |
| 29 | +@@ -2168,7 +2169,8 @@ static bool is_sync_signal(ThreadSignalContext *sctx, int sig, |
| 30 | + return false; |
| 31 | + #endif |
| 32 | + return sig == SIGSEGV || sig == SIGBUS || sig == SIGILL || sig == SIGTRAP || |
| 33 | +- sig == SIGABRT || sig == SIGFPE || sig == SIGPIPE || sig == SIGSYS; |
| 34 | ++ sig == SIGABRT || sig == SIGFPE || sig == SIGPIPE || sig == SIGSYS || |
| 35 | ++ sig == SIGPROF; |
| 36 | + } |
| 37 | + |
| 38 | + void sighandler(int sig, __sanitizer_siginfo *info, void *ctx) { |
| 39 | +diff --git a/compiler-rt/test/tsan/signal_errno.cpp b/compiler-rt/test/tsan/signal_errno.cpp |
| 40 | +index 7e1fd4b0c5a5..99d4b6d84ca4 100644 |
| 41 | +--- a/compiler-rt/test/tsan/signal_errno.cpp |
| 42 | ++++ b/compiler-rt/test/tsan/signal_errno.cpp |
| 43 | +@@ -18,7 +18,7 @@ static void MyHandler(int, siginfo_t *s, void *c) { |
| 44 | + |
| 45 | + static void* sendsignal(void *p) { |
| 46 | + barrier_wait(&barrier); |
| 47 | +- pthread_kill(mainth, SIGPROF); |
| 48 | ++ pthread_kill(mainth, SIGALRM); |
| 49 | + return 0; |
| 50 | + } |
| 51 | + |
| 52 | +@@ -37,7 +37,7 @@ int main() { |
| 53 | + mainth = pthread_self(); |
| 54 | + struct sigaction act = {}; |
| 55 | + act.sa_sigaction = &MyHandler; |
| 56 | +- sigaction(SIGPROF, &act, 0); |
| 57 | ++ sigaction(SIGALRM, &act, 0); |
| 58 | + pthread_t th; |
| 59 | + pthread_create(&th, 0, sendsignal, 0); |
| 60 | + loop(); |
| 61 | +@@ -46,7 +46,7 @@ int main() { |
| 62 | + } |
| 63 | + |
| 64 | + // CHECK: WARNING: ThreadSanitizer: signal handler spoils errno |
| 65 | +-// CHECK: Signal 27 handler invoked at: |
| 66 | ++// CHECK: Signal 14 handler invoked at: |
| 67 | + // CHECK: #0 MyHandler(int, {{(__)?}}siginfo{{(_t)?}}*, void*) {{.*}}signal_errno.cpp |
| 68 | + // CHECK: main |
| 69 | + // CHECK: SUMMARY: ThreadSanitizer: signal handler spoils errno{{.*}}MyHandler |
| 70 | +diff --git a/compiler-rt/test/tsan/signal_sync.cpp b/compiler-rt/test/tsan/signal_sync.cpp |
| 71 | +index b529a1859f52..b283c9341636 100644 |
| 72 | +--- a/compiler-rt/test/tsan/signal_sync.cpp |
| 73 | ++++ b/compiler-rt/test/tsan/signal_sync.cpp |
| 74 | +@@ -30,7 +30,7 @@ int main() { |
| 75 | + |
| 76 | + struct sigaction act = {}; |
| 77 | + act.sa_handler = &handler; |
| 78 | +- if (sigaction(SIGPROF, &act, 0)) { |
| 79 | ++ if (sigaction(SIGALRM, &act, 0)) { |
| 80 | + perror("sigaction"); |
| 81 | + exit(1); |
| 82 | + } |
| 83 | +@@ -39,7 +39,7 @@ int main() { |
| 84 | + t.it_value.tv_sec = 0; |
| 85 | + t.it_value.tv_usec = 10; |
| 86 | + t.it_interval = t.it_value; |
| 87 | +- if (setitimer(ITIMER_PROF, &t, 0)) { |
| 88 | ++ if (setitimer(ITIMER_REAL, &t, 0)) { |
| 89 | + perror("setitimer"); |
| 90 | + exit(1); |
| 91 | + } |
| 92 | +diff --git a/compiler-rt/test/tsan/signal_thread.cpp b/compiler-rt/test/tsan/signal_thread.cpp |
| 93 | +index aa91d1ddeb10..e5ea44187e32 100644 |
| 94 | +--- a/compiler-rt/test/tsan/signal_thread.cpp |
| 95 | ++++ b/compiler-rt/test/tsan/signal_thread.cpp |
| 96 | +@@ -24,7 +24,7 @@ static void* thr(void *p) { |
| 97 | + int main() { |
| 98 | + struct sigaction act = {}; |
| 99 | + act.sa_handler = &handler; |
| 100 | +- if (sigaction(SIGPROF, &act, 0)) { |
| 101 | ++ if (sigaction(SIGALRM, &act, 0)) { |
| 102 | + perror("sigaction"); |
| 103 | + exit(1); |
| 104 | + } |
| 105 | +@@ -33,7 +33,7 @@ int main() { |
| 106 | + t.it_value.tv_sec = 0; |
| 107 | + t.it_value.tv_usec = 10; |
| 108 | + t.it_interval = t.it_value; |
| 109 | +- if (setitimer(ITIMER_PROF, &t, 0)) { |
| 110 | ++ if (setitimer(ITIMER_REAL, &t, 0)) { |
| 111 | + perror("setitimer"); |
| 112 | + exit(1); |
| 113 | + } |
| 114 | +diff --git a/compiler-rt/test/tsan/signal_thread2.cpp b/compiler-rt/test/tsan/signal_thread2.cpp |
| 115 | +index 9bde4f70b39d..5236628e13b6 100644 |
| 116 | +--- a/compiler-rt/test/tsan/signal_thread2.cpp |
| 117 | ++++ b/compiler-rt/test/tsan/signal_thread2.cpp |
| 118 | +@@ -40,7 +40,7 @@ static void *thr(void *p) { |
| 119 | + int main() { |
| 120 | + struct sigaction act = {}; |
| 121 | + act.sa_handler = &handler; |
| 122 | +- if (sigaction(SIGPROF, &act, 0)) { |
| 123 | ++ if (sigaction(SIGALRM, &act, 0)) { |
| 124 | + perror("sigaction"); |
| 125 | + exit(1); |
| 126 | + } |
| 127 | +@@ -49,7 +49,7 @@ int main() { |
| 128 | + t.it_value.tv_sec = 0; |
| 129 | + t.it_value.tv_usec = 10; |
| 130 | + t.it_interval = t.it_value; |
| 131 | +- if (setitimer(ITIMER_PROF, &t, 0)) { |
| 132 | ++ if (setitimer(ITIMER_REAL, &t, 0)) { |
| 133 | + perror("setitimer"); |
| 134 | + exit(1); |
| 135 | + } |
0 commit comments