This is an archive of the discontinued LLVM Phabricator instance.

Don't delete lsan thread-local data until it's no longer required
ClosedPublic

Authored by fjricci on Apr 10 2017, 7:24 AM.

Details

Summary

The routines for thread destruction in the thread registry require
the lsan thread index, which is stored in pthread tls on OS X.
This means that we need to make sure that the lsan tls isn't destroyed
until after the thread registry tls. This change ensures that we
don't delete the lsan tls until we've finished destroying the thread
in the registry, ensuring that the destructor for the lsan tls runs
after the destructor for the thread registry tls.

This patch also adds a check to ensure that the thread ID is valid before
returning it in GetThreadID(), to ensure that the above behavior
is working correctly.

Event Timeline

fjricci created this revision.Apr 10 2017, 7:24 AM
fjricci updated this revision to Diff 94676.Apr 10 2017, 8:31 AM

Fix up some style issues

alekseyshl accepted this revision.Apr 11 2017, 11:13 AM
alekseyshl added inline comments.
lib/lsan/lsan_common_mac.cc
39

Just curious, is !ptr check necessary?

This revision is now accepted and ready to land.Apr 11 2017, 11:13 AM
fjricci added inline comments.Apr 11 2017, 11:31 AM
lib/lsan/lsan_common_mac.cc
39

Good catch, according to the man page, looks like destructors are only called if the value of the key is non-NULL. I'll remove that check before merging.

This revision was automatically updated to reflect the committed changes.