]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwP.h: Add locking to str_offsets_base_off
authorAaron Merey <amerey@redhat.com>
Mon, 17 Mar 2025 01:51:02 +0000 (21:51 -0400)
committerAaron Merey <amerey@redhat.com>
Wed, 26 Mar 2025 21:01:24 +0000 (17:01 -0400)
* libdw/dwarf_end.c (cu_free): Free str_off_base_lock.
* libdw/libdwP.h (struct Dwarf_CU): Add str_off_base_lock member.
(str_offsets_base_off): Add locking.
* libdw/libdw_findcu.c (__libdw_intern_next_unit): Initialize
str_off_base_lock.

Signed-off-by: Aaron Merey <amerey@redhat.com>
libdw/dwarf_end.c
libdw/libdwP.h
libdw/libdw_findcu.c

index c12815e1004541223e4225f27ea61c49926efa7a..1628e448b0c9d11194dfa8d732b12b5780555163 100644 (file)
@@ -71,6 +71,7 @@ cu_free (void *arg)
       rwlock_fini (p->abbrev_lock);
       rwlock_fini (p->split_lock);
       mutex_fini (p->src_lock);
+      mutex_fini (p->str_off_base_lock);
 
       /* Free split dwarf one way (from skeleton to split).  */
       if (p->unit_type == DW_UT_skeleton
index 3216f2a1dd724fb7365018a7a1bcc4f7085b4016..de80cd4e551442ba459f370746b7fcb10d2d6010 100644 (file)
@@ -467,6 +467,10 @@ struct Dwarf_CU
      Covers dwarf_getsrclines and dwarf_getsrcfiles.  */
   mutex_define(, src_lock);
 
+  /* Synchronize access to the str_off_base of this Dwarf_CU.
+     Covers __libdw_str_offsets_base_off.  */
+  mutex_define(, str_off_base_lock);
+
   /* Memory boundaries of this CU.  */
   void *startp;
   void *endp;
@@ -1210,6 +1214,7 @@ str_offsets_base_off (Dwarf *dbg, Dwarf_CU *cu)
   Dwarf_Off off = 0;
   if (cu != NULL)
     {
+      mutex_lock (cu->str_off_base_lock);
       if (cu->str_off_base == (Dwarf_Off) -1)
        {
          Dwarf_Off dwp_offset;
@@ -1224,6 +1229,7 @@ str_offsets_base_off (Dwarf *dbg, Dwarf_CU *cu)
              if (dwarf_formudata (&attr, &base) == 0)
                {
                  cu->str_off_base = off + base;
+                 mutex_unlock (cu->str_off_base_lock);
                  return cu->str_off_base;
                }
            }
@@ -1231,6 +1237,7 @@ str_offsets_base_off (Dwarf *dbg, Dwarf_CU *cu)
          if (cu->version < 5)
            {
              cu->str_off_base = off;
+             mutex_unlock (cu->str_off_base_lock);
              return cu->str_off_base;
            }
 
@@ -1238,7 +1245,10 @@ str_offsets_base_off (Dwarf *dbg, Dwarf_CU *cu)
            dbg = cu->dbg;
        }
       else
-       return cu->str_off_base;
+       {
+         mutex_unlock (cu->str_off_base_lock);
+         return cu->str_off_base;
+       }
     }
 
   /* No str_offsets_base attribute, we have to assume "zero".
@@ -1288,7 +1298,10 @@ str_offsets_base_off (Dwarf *dbg, Dwarf_CU *cu)
 
  no_header:
   if (cu != NULL)
-    cu->str_off_base = off;
+    {
+      cu->str_off_base = off;
+      mutex_unlock (cu->str_off_base_lock);
+    }
 
   return off;
 }
index f02436434321bbc71fe344afea0d77ff08c4f05e..8805af9b37b03582848a2eafb4ce2aa0ed8182c8 100644 (file)
@@ -180,6 +180,7 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types)
   rwlock_init (newp->abbrev_lock);
   rwlock_init (newp->split_lock);
   mutex_init (newp->src_lock);
+  mutex_init (newp->str_off_base_lock);
 
   /* v4 debug type units have version == 4 and unit_type == DW_UT_type.  */
   if (debug_types)