[llvm] 5aa934e - Make DWARFUnitVector threadsafe. (#71487)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 8 10:20:06 PST 2023


Author: Greg Clayton
Date: 2023-11-08T10:20:02-08:00
New Revision: 5aa934e2af8727852dec0ec1cfa0cba05d858f70

URL: https://github.com/llvm/llvm-project/commit/5aa934e2af8727852dec0ec1cfa0cba05d858f70
DIFF: https://github.com/llvm/llvm-project/commit/5aa934e2af8727852dec0ec1cfa0cba05d858f70.diff

LOG: 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.

Added: 
    

Modified: 
    llvm/lib/DebugInfo/DWARF/DWARFContext.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 088dffeaa2b9f6d..c671aedbc9e52b4 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -639,7 +639,10 @@ class ThreadSafeState : public ThreadUnsafeDWARFContextState {
   }
   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);


        


More information about the llvm-commits mailing list