[llvm] 2a9f02b - [LLVM][DWARF] Create thread safe context for DWO/DWP DWARFContext (#68262)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 06:53:48 PDT 2023


Author: Alexander Yermolovich
Date: 2023-10-10T06:53:44-07:00
New Revision: 2a9f02b709f7d0adea9be84798ba7a07cb042d15

URL: https://github.com/llvm/llvm-project/commit/2a9f02b709f7d0adea9be84798ba7a07cb042d15
DIFF: https://github.com/llvm/llvm-project/commit/2a9f02b709f7d0adea9be84798ba7a07cb042d15.diff

LOG: [LLVM][DWARF] Create thread safe context for DWO/DWP DWARFContext (#68262)

Right now DWARFContext for DWO/DWP that is created is not thread safe. 
Changed it so that thread safety is inherited from the main
binary DWARFContext.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
index 4bd8394e6b4ec82..fa98cbcfc4d997f 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
@@ -97,6 +97,7 @@ class DWARFContext : public DIContext {
         getDWOContext(StringRef AbsolutePath) = 0;
     virtual const DenseMap<uint64_t, DWARFTypeUnit *> &
     getTypeUnitMap(bool IsDWO) = 0;
+    virtual bool isThreadSafe() const = 0;
 
     /// Parse a macro[.dwo] or macinfo[.dwo] section.
     std::unique_ptr<DWARFDebugMacro>

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 3d943a04da2c226..372897835cce199 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -575,13 +575,20 @@ class ThreadUnsafeDWARFContextState : public DWARFContext::DWARFContextState {
 
     auto S = std::make_shared<DWOFile>();
     S->File = std::move(Obj.get());
-    S->Context = DWARFContext::create(*S->File.getBinary(),
-                                      DWARFContext::ProcessDebugRelocations::Ignore);
+    // Allow multi-threaded access if there is a .dwp file as the CU index and
+    // TU index might be accessed from multiple threads.
+    bool ThreadSafe = isThreadSafe();
+    S->Context = DWARFContext::create(
+        *S->File.getBinary(), DWARFContext::ProcessDebugRelocations::Ignore,
+        nullptr, "", WithColor::defaultErrorHandler,
+        WithColor::defaultWarningHandler, ThreadSafe);
     *Entry = S;
     auto *Ctxt = S->Context.get();
     return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
   }
 
+  bool isThreadSafe() const override { return false; }
+
   const DenseMap<uint64_t, DWARFTypeUnit *> &getNormalTypeUnitMap() {
     if (!NormalTypeUnits) {
       NormalTypeUnits.emplace();
@@ -717,6 +724,9 @@ class ThreadSafeState : public ThreadUnsafeDWARFContextState {
     std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
     return ThreadUnsafeDWARFContextState::getDWOContext(AbsolutePath);
   }
+
+  bool isThreadSafe() const override { return true; }
+
   const DenseMap<uint64_t, DWARFTypeUnit *> &
   getTypeUnitMap(bool IsDWO) override {
     std::unique_lock<std::recursive_mutex> LockGuard(Mutex);


        


More information about the llvm-commits mailing list