-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TSan] futex syscalls are not marked as blocking, causing hangs on TSan builds when combined with async signals #123138
Comments
Are you correctly linking against your newly patched runtime? |
I think so. I tried calling a preexisting function too just to check but that didn't work either. I'm not 100% sure if I'm not making an obvious mistake while trying to link though. I tried a combination of various things but not luck so far. This code only compiles when I build with tsan enabled (), which makes me think that the compiler-rt is not linked for the normal builds? |
You need to |
Oh, right. Actually that seems to match the behavior of clang: https://godbolt.org/z/K9E347ecn It also fails to link when tsan is not enabled. Let me try the |
@Nilstrieb I can verify that the linker successfully finds them when they are behind a sanitize cfg. My test case is also fixed with the patched LLVM + calling these pre/post hooks. Would be happy to send a PR, but to be able to do that we need to update the LLVM fork first. Do you know if there is a process to do that? (either as a cherry-pick or some other way like updating the whole fork?) Or if that's something I can do? |
We support being compiled with LLVM that's not our fork and like 1 version old, so you'd either need to wait for like a year or find a way to only apply this change when possible (weak linkage maybe?). |
They're not direct syscalls via assembly, they still go through the libc helper. Can't that be intercepted too? |
Based on my experience and investigation in rust-random/getrandom#463, Although the (libstd doesn't need to call |
I've been investigating the Firefox Profiler hangs that were happening in TSan builds, and discovered that LLVM doesn't correctly mark some blocking functions calls (llvm/llvm-project#83561 and llvm/llvm-project#83844). And it was failing to send async signals like
SIGPROF
properly.There is also a Rust test case in the second issue if you want to try it yourself: https://github.com/canova/rustc-tsan-testcase
They've been resolved now, but Rust needs to get the LLVM patches as well and on top of it it needs to do a manual handling for
FUTEX_WAIT
syscalls.It looks like for calling syscalls directly, there isn't a way to intercept the call (it's possible for glibc calls like
pthread_mutex_lock
etc.). That's why when a syscall is being called, the program itself has to inject pre/post syscall hooks itself. My PR added these new hooks forfutex
syscalls so they can be marked as blocking properly. Rust std library also callsFUTEX_WAIT
syscalls directly, which means that we need to add__sanitizer_syscall_pre_futex
and__sanitizer_syscall_post_futex
to here (beware that these are macros, so you'll want to cal the functions that the macros call instead):rust/library/std/src/sys/pal/unix/futex.rs
Lines 60 to 70 in 10a7aa1
I tried implementing it, but I couldn't make the linker happy yet. It can't find the hooks, they should be inside the libclang_rt but I can't seem to make it work. Any help would be appreciated!
The text was updated successfully, but these errors were encountered: