Objective-C tagged pointers (either bottom-most or top-most bit is 1) are valid Obj-C objects but are not valid pointers. Make sure we don't crash on them when used in objc_sync_enter/objc_sync_exit. Instead, let's synchronize on a global object.
Details
- Reviewers
dvyukov george.karpenkov delcypher dcoughlin - Commits
- rGdc36389ea8ad: [tsan] Fix crash in objc_sync_enter/objc_sync_exit when using an Obj-C tagged…
rCRT337837: [tsan] Fix crash in objc_sync_enter/objc_sync_exit when using an Obj-C tagged…
rL337837: [tsan] Fix crash in objc_sync_enter/objc_sync_exit when using an Obj-C tagged…
Diff Detail
- Repository
- rCRT Compiler Runtime
Event Timeline
lib/tsan/rtl/tsan_interceptors_mac.cc | ||
---|---|---|
297 | can we have a short docstring for both functions? Also, isTaggedObjCPointer? | |
299 | return ((uptr)obj & kPossibleTaggedBits) != 0 ? | |
303 | what's the point of taking in the argument then? | |
324 | can we extract this line into a function with a name explaining it's semantics? |
lib/tsan/rtl/tsan_interceptors_mac.cc | ||
---|---|---|
303 | The point is that, ideally, the function would return a different sync address for different pointers. But for now, the implementation trivially returns the same address for all, which can cause false negatives. |
lib/tsan/rtl/tsan_interceptors_mac.cc | ||
---|---|---|
297 |
In (almost) all of TSan, private functions starts with an uppercase letter. Let's not try to change style with this patch. |
lib/tsan/rtl/tsan_interceptors_mac.cc | ||
---|---|---|
299 | also all the helper functions should be static |
Other than minor suggestions the basic idea seems okay for now.
lib/tsan/rtl/tsan_interceptors_mac.cc | ||
---|---|---|
299 | Perhaps the name should be IsTaggedObjCPointer? | |
308 | There probably should be a TODO(kubamracek) or FIXME in here. Do we even want to do Acquire() and Release() for tagged pointers? Even if we had a perfect implementation of SyncAddressForTaggedPointer() that still seems wrong because we could have two independent instances of a tagged pointer |
lib/tsan/rtl/tsan_interceptors_mac.cc | ||
---|---|---|
308 | Yes, the entire idea of using value types (strings, integeres, timestamps) as synchronization objects is weird and most likely not what you intended anyway. Therefore this patch is really just to avoid crashing and to mirror what libobjc is actually doing when using @synchronize on a tagged pointer (it does actually establish synchronization if the pointer bits are exactly the same). |
can we have a short docstring for both functions? Also, isTaggedObjCPointer?