-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Runtime] Change MetadataLookup section vectors to use ConcurrentReadableArray. #16753
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
[Runtime] Change MetadataLookup section vectors to use ConcurrentReadableArray. #16753
Conversation
…apshots rather than using a callback-based read call. rdar://problem/40230581
…urrentReadableArray rather than std::vector. This avoids the need to hold a lock while iterating, removing potential deadlocks. rdar://problem/40230581
Awesome, thanks for catching and fixing this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! For some reason I didn't even stop to think that Mutex
might not be reentrant but instead just blindly used the same pattern found in other places in this file while working on swift_getFieldAt
:(
@xedin I don't think it would have occurred to me that |
@swift-ci please test |
Build failed |
@swift-ci Please test OS X platform |
Build failed |
…apshots rather than using a callback-based read call. rdar://problem/40230581
…ouble-free items. Also implement a destructor so it can be used for non-globals. rdar://problem/40484362
…atalookup-deadlocks
@swift-ci please test |
Build failed |
Build failed |
This fixes a deadlock that can occur when dyld loads new images into the process.
MetadataLookup.cpp
takes a lock to iterate over sections and while the lock is held it can call code which eventually calls_dyld_register_func_for_add_image
which takes a lock inside dyld. Elsewhere, a function registered with_dyld_register_func_for_add_image
gets called with that same dyld lock held, and tries to acquire the same lock inMetadataLookup.cpp
. This inconsistent lock ordering results in a deadlock when the stars align just so.The fix here is to switch to
ConcurrentReadableArray
which does not take a lock for reading. It still takes a lock for writing, but since that's only one half of the deadlock, that's OK.Relevant stack trace excerpts for the curious:
rdar://problem/40230581