Skip to content

Commit d80e436

Browse files
committed
Bug 1885319 - Make SIGPROF a sync signal on TSan of our clang and rust builds r=sergesanspaille,glandium
Due to SIGPROF being async, it was hanging on some cases because some functions were incorrectly marked non-blocking. This patch is merge to LLVM in: llvm/llvm-project#85188 But we want to patch our clang here to start benefiting from that quickly. We are also patching our rustc here. Even though they are not used by default during our normal builds, this custom rustc is needed for building and running TSan already: https://firefox-source-docs.mozilla.org/tools/sanitizer/tsan.html#llvm-clang-rust Differential Revision: https://phabricator.services.mozilla.com/D204631
1 parent 5f382f3 commit d80e436

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed

build/build-clang/clang-17.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"revert-llvmorg-15-init-11205-gcead4eceb01b_clang_16.patch",
1414
"llvmorg-18-init-8471-g160e8eb44961.patch",
1515
"D146664.patch",
16+
"llvmorg-19-init-5399-gddcbab37ac0e.patch",
1617
"win64-ret-null-on-commitment-limit_clang_14.patch",
1718
"compiler-rt-rss-limit-heap-profile.patch"
1819
]

build/build-clang/clang-18.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"revert-llvmorg-16-init-11301-g163bb6d64e5f_clang_18.patch",
1616
"revert-llvmorg-15-init-13446-g7524fe962e47.patch",
1717
"revert-llvmorg-15-init-11205-gcead4eceb01b_clang_18.patch",
18+
"llvmorg-19-init-5399-gddcbab37ac0e.patch",
1819
"win64-ret-null-on-commitment-limit_clang_14.patch",
1920
"compiler-rt-rss-limit-heap-profile.patch"
2021
]
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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+
}

taskcluster/ci/toolchain/rust.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ linux64-rust-dev:
5656
arguments: [
5757
'--patch', 'rust-vendor-std.patch',
5858
'--patch', 'src/tools/cargo:cargo-vendor-std.patch',
59+
'--patch', 'src/llvm-project:../build-clang/llvmorg-19-init-5399-gddcbab37ac0e.patch',
5960
'--channel', 'dev',
6061
'--host', 'x86_64-unknown-linux-gnu',
6162
'--target', 'x86_64-unknown-linux-gnu',

0 commit comments

Comments
 (0)