[ASan] Stop blocking child thread progress from parent thread in `pthread_create` interceptor.
Previously in ASan's `pthread_create` interceptor we would block in the `pthread_create` interceptor waiting for the child thread to start. Unfortunately this has bad performance characteristics because the OS scheduler doesn't know the relationship between the parent and child thread (i.e. the parent thread cannot make progress until the child thread makes progress) and may make the wrong scheduling decision which stalls progress. It turns out that ASan didn't use to block in this interceptor but was changed to do so to try to address http://llvm.org/bugs/show_bug.cgi?id=21621/. In that bug the problem being addressed was a LeakSanitizer false positive. That bug concerns a heap object being passed as `arg` to `pthread_create`. If: * The calling thread loses a live reference to the object (e.g. `pthread_create` finishes and the thread no longer has a live reference to the object). * Leak checking is triggered. * The child thread has not yet started (once it starts it will have a live reference). then the heap object will incorrectly appear to be leaked. This bug is covered by the `lsan/TestCases/leak_check_before_thread_started.cpp` test case. In b029c510 ASan was changed to block in `pthread_create()` until the child thread starts so that `arg` is kept alive for the purposes of leaking check. While this change "works" its problematic due to the performance problems it causes. The change is also completely unnecessary if leak checking is disabled (via detect_leaks runtime option or CAN_SANITIZE_LEAKS compile time config). This patch does two things: 1. Takes a different approach to solving the leak false positive by making LSan's leak checking mechanism treat the `arg` pointer of created but not started threads as reachable. This is done by implementing the `ForEachRegisteredThreadContextCb` callback for ASan. 2. Removes the blocking behaviour in the ASan `pthread_create` interceptor. rdar://problem/63537240 Differential Revision: https://reviews.llvm.org/D95184
Loading
Please register or sign in to comment