Objective-C's @synchronize synchronization primitive uses calls to objc_sync_enter and objc_sync_exit runtime functions. In most cases, they end up just calling pthread_mutex_lock/pthread_mutex_unlock, but there are some cases where the synchronization from pthread_mutex_lock/pthread_mutex_unlock interceptors isn't enough. Let's add explicit interceptors for objc_sync_enter and objc_sync_exit to handle all cases.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
lib/tsan/CMakeLists.txt | ||
---|---|---|
121 ↗ | (On Diff #141862) | Does this mean that clang_rt.tsan will now always link against libobjc? Is that really necessary. Won't that mean it gets linked in for sanitized C programs that have absolutely no business doing anything with the ObjectiveC runtime? |
lib/tsan/CMakeLists.txt | ||
---|---|---|
121 ↗ | (On Diff #141862) | You're right, this always links libobjc, even into program that are not using Objective-C. I don't know how to avoid this dependency, because the dyld interposition requires us to link against the symbols that we intercept. On the bright side, libobjc gets loaded into every process on macOS anyway. So I believe this is actually safe and shouldn't break anything. |
Whaat kind of test are you looking for? As this adds more synchronization edges, this strictly removes reports (false positives in this case). I can add a test that incorrectly uses @synchronized that still triggers a TSan report, if you want.
this strictly removes reports
Ah sorry, didn't realize that.
I thought it would remove some reports and add some as well (deadlocks? but now I see those are not fully supported)
LGTM in that case.
lib/tsan/CMakeLists.txt | ||
---|---|---|
121 ↗ | (On Diff #141862) | Okay. Presumably, TSan will still initialise properly (i.e. the fact that TSan links libobjc won't break initialisation order)? |
lib/tsan/CMakeLists.txt | ||
---|---|---|
121 ↗ | (On Diff #141862) | Although libobjc isn't part of libSystem, it's actually loaded by libSystem unconditionally to all processes, and libobjc initializer (_objc_init) is called early in process startup. So explicitly linking against libobjc shouldn't really change any initialization order. |