[compiler-rt] [TSan] Add lock_during_write flag on Apple platforms to avoid deadlock (PR #157928)
Dan Blackwell via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 11 07:54:09 PDT 2025
DanBlackwell wrote:
Note: I've tested the following on Ubuntu to see if the same thing can happen:
```
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#ifdef SHARED_LIB
#include <dlfcn.h>
#include <stdlib.h>
#include <pthread.h>
pthread_mutex_t mtx;
typedef ssize_t (*func_t)(int, const void *, size_t);
extern "C" ssize_t write(int fd, const void *buf, size_t count) {
static func_t write_real = NULL;
write_real = (func_t)dlsym(RTLD_NEXT, "write");
pthread_mutex_lock(&mtx);
printf("Intercepted\n");
pthread_mutex_unlock(&mtx);
return write_real(fd, buf, count);
}
#else
int main() {
write(1, "test", 4);
return 0;
}
#endif
```
>From what I can tell, any calls within the `write` wrapper here (`pthread_mutex_lock`) don't get intercepted by TSan; thus it can't deadlock in the same way as Apple can with interposition. I will keep this flag as Apple only, as it solves a problem that is Apple specific.
https://github.com/llvm/llvm-project/pull/157928
More information about the llvm-commits
mailing list