This is an archive of the discontinued LLVM Phabricator instance.

Make gCrashRecoveryEnabled thread local
ClosedPublic

Authored by jpienaar on Dec 29 2020, 10:43 AM.

Details

Summary

If context is enabled/disabled and queried concurrently then this results in a
data race/TSAN failure with RunSafely (where boolean variable was not locked).

There doesn't seem to be a reasonable way to enable threads to enable and disable recovery in parallel (without also keeping gCrashRecoveryEnabled's lock held during Fn execution which seems undesirable). This makes enable checking if enabled thread local and seems to be consistent with other thread local usage of crash context here.

Diff Detail

Event Timeline

jpienaar created this revision.Dec 29 2020, 10:43 AM
jpienaar requested review of this revision.Dec 29 2020, 10:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 29 2020, 10:43 AM

The boolean variable is guarded by std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex); so non-atomic works.
Making it a counter is fine.

MaskRay added inline comments.Feb 9 2021, 1:04 PM
llvm/lib/Support/CrashRecoveryContext.cpp
145
if (--gCrashRecoveryEnabled == 0)
  uninstallExceptionOrSignalHandlers();
MaskRay accepted this revision.Feb 10 2021, 11:01 AM

LG, with nits. (RunSafely accesses gCrashRecoveryEnabled without a lock.)

llvm/lib/Support/CrashRecoveryContext.cpp
141

std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex); can be moved after gCrashRecoveryEnabled++

145

std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex); can be moved after decrement.

This revision is now accepted and ready to land.Feb 10 2021, 11:01 AM
jpienaar updated this revision to Diff 322794.Feb 10 2021, 12:41 PM

Updated to use thread local variable instead.

jpienaar marked 3 inline comments as done.Feb 10 2021, 12:41 PM

Switched as discussed

jpienaar retitled this revision from Make gCrashRecoveryEnabled atomic to Make gCrashRecoveryEnabled thread local.Feb 10 2021, 12:42 PM
jpienaar edited the summary of this revision. (Show Details)
This revision was landed with ongoing or failed builds.Feb 10 2021, 12:46 PM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Feb 11 2021, 4:28 AM

Fyi, this also made c-index-test hang reliably when running check-clang on linux and mac. If you plan to reland this, please check that too before relanding :)