Skip to content

Commit 5aa934e

Browse files
authored
Make DWARFUnitVector threadsafe. (#71487)
The DWARFUnitVector class lives inside of the DWARFContextState. Prior to this fix a non const reference was being handed out to clients. When fetching the DWO units, there used to be a "bool Lazy" parameter that could be passed that would allow the DWARFUnitVector to parse individual units on the fly. There were two major issues with this approach: - not thread safe and causes crashes - the accessor would check if DWARFUnitVector was empty and if not empty it would return a partially filled in DWARFUnitVector if it was constructed with "Lazy = true" This patch fixes the issues by always fully parsing the DWARFUnitVector when it is requested and only hands out a "const DWARFUnitVector &". This allows the thread safety mechanism built into the DWARFContext class to work corrrectly, and avoids the issue where if someone construct DWARFUnitVector with "Lazy = true", and then calls an API that partially fills in the DWARFUnitVector with individual entries, and then someone accesses the DWARFUnitVector, they would get a partial and incomplete listing of the DWARF units for the DWOs.
1 parent 070fde3 commit 5aa934e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,10 @@ class ThreadSafeState : public ThreadUnsafeDWARFContextState {
639639
}
640640
DWARFUnitVector &getDWOUnits(bool Lazy) override {
641641
std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
642-
return ThreadUnsafeDWARFContextState::getDWOUnits(Lazy);
642+
// We need to not do lazy parsing when we need thread safety as
643+
// DWARFUnitVector, in lazy mode, will slowly add things to itself and
644+
// will cause problems in a multi-threaded environment.
645+
return ThreadUnsafeDWARFContextState::getDWOUnits(false);
643646
}
644647
const DWARFUnitIndex &getCUIndex() override {
645648
std::unique_lock<std::recursive_mutex> LockGuard(Mutex);

0 commit comments

Comments
 (0)