This is an archive of the discontinued LLVM Phabricator instance.

Fix the ManagedStatic list ordering when using DynamicLibrary::addPermanentLibrary.
ClosedPublic

Authored by marsupial on May 25 2017, 6:35 PM.

Details

Summary

r295737 included a fix for leaking libraries loaded via. DynamicLibrary::addPermanentLibrary.
This created a problem where static constructors in a library could insert llvm::ManagedStatic objects before DynamicLibrary would register it's own ManagedStatic, meaning a crash could occur at shutdown.

r301562 exasperated this problem by cleaning up the DynamicLibrary ManagedStatic during llvm_shutdown.

Diff Detail

Event Timeline

marsupial created this revision.May 25 2017, 6:35 PM
marsupial added a reviewer: efriedma.
efriedma added inline comments.May 26 2017, 11:47 AM
lib/Support/DynamicLibrary.cpp
136

Why are you changing the scope of this lock? (What happens if a static constructor in a library calls getPermanentLibrary?)

marsupial added inline comments.May 26 2017, 11:59 AM
lib/Support/DynamicLibrary.cpp
136

The ManagedStatic OpenedHandles has a lock for construction.
The SymbolsMutex is the lock for adding to the list.
The way it was before it would be impossible for two threads to execute the DLOpen call in parallel.

efriedma accepted this revision.May 26 2017, 12:09 PM

LGTM.

lib/Support/DynamicLibrary.cpp
136

Okay, that makes sense.

This revision is now accepted and ready to land.May 26 2017, 12:09 PM
This revision was automatically updated to reflect the committed changes.