dwarf-reader: Fix data race on reader::die_pretty_repr_maps_

Message ID 20260926105149.3656120-1-dodji@seketeli.org
State New
Headers
Series dwarf-reader: Fix data race on reader::die_pretty_repr_maps_ |

Commit Message

Dodji Seketeli Sept. 26, 2026, 10:51 a.m. UTC
  Thread Sanitizer running on the CI builders of sourceware.org detected
a data race while accessing the data member
abigail::dwarf::reader::die_pretty_repr_maps_.  This is because
abigail::dwarf::reader::get_die_pretty_representation does not take
the mutex abigail::dwarf::reader::die_pretty_repr_maps_mutex_, whereas
abigail::dwarf::reader::set_die_pretty_repr does.

This patch makes abigail::dwarf::reader::get_die_pretty_representation
take the mutex.

	* src/abg-dwarf-reader.cc (reader::die_pretty_repr_maps_mutex_):
	Turn this mutex into a recursive_mutex.
	(reader::set_die_pretty_repr): Adjust.
	(reader::get_die_pretty_representation): Take the
	reader::die_pretty_repr_maps_mutex_ before accessing
	reader::die_pretty_repr_maps_.

Signed-off-by: Dodji Seketeli <dodji@seketeli.org>
---
 src/abg-dwarf-reader.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Patch

diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index cb9e14ba..aebcaa2b 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -2150,7 +2150,7 @@  public:
   mutable mutex			die_qualified_name_maps_mutex_;
 
   mutable die_istring_map_type		die_pretty_repr_maps_;
-  mutable mutex			die_pretty_repr_maps_mutex_;
+  mutable recursive_mutex		die_pretty_repr_maps_mutex_;
 
   // A map that associates the address of a decl die to its
   // corresponding decl artifact, along with its mutex.
@@ -2797,7 +2797,7 @@  public:
   set_die_pretty_repr(const void* die_addr, interned_string istr) const
   {
     ABG_ASSERT(die_addr && !istr.empty());
-    std::lock_guard<mutex> lock(die_pretty_repr_maps_mutex_);
+    std::lock_guard<recursive_mutex> lock(die_pretty_repr_maps_mutex_);
     die_pretty_repr_maps_[const_cast<void*>(die_addr)] = istr;
   }
 
@@ -3483,6 +3483,7 @@  public:
     ABG_ASSERT(die);
 
     const die_istring_map_type& map = die_pretty_repr_maps();
+    lock_guard<recursive_mutex> lock(die_pretty_repr_maps_mutex_);
     die_istring_map_type::const_iterator i = map.find(die->addr);
 
     if (i == map.end())