summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@fb.com>2023-11-08 10:20:02 -0800
committerGitHub <noreply@github.com>2023-11-08 10:20:02 -0800
commit5aa934e2af8727852dec0ec1cfa0cba05d858f70 (patch)
tree053702e1a0b56835b265f22e00fed64e997de8d6
parent070fde30a74222c35dc2b72a6b156cc39c94fee3 (diff)
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.
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFContext.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 088dffeaa2b9..c671aedbc9e5 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -639,7 +639,10 @@ public:
}
DWARFUnitVector &getDWOUnits(bool Lazy) override {
std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
- return ThreadUnsafeDWARFContextState::getDWOUnits(Lazy);
+ // We need to not do lazy parsing when we need thread safety as
+ // DWARFUnitVector, in lazy mode, will slowly add things to itself and
+ // will cause problems in a multi-threaded environment.
+ return ThreadUnsafeDWARFContextState::getDWOUnits(false);
}
const DWARFUnitIndex &getCUIndex() override {
std::unique_lock<std::recursive_mutex> LockGuard(Mutex);