]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Change type of dwarf_lock from rwlock to mutex
authorAaron Merey <amerey@redhat.com>
Thu, 20 Feb 2025 04:36:36 +0000 (23:36 -0500)
committerAaron Merey <amerey@redhat.com>
Wed, 26 Mar 2025 21:01:24 +0000 (17:01 -0400)
Change type of dwarf_lock to mutex in order to take advantage of
built-in support for recursive locking.

* lib/locks.h: Add macros for locking, unlocking, initializing
and destroying mutexes.
* libdw/dwarf_begin_elf.c (dwarf_end): Replace rwlock macro with
mutex macro.
* libdw/dwarf_formref_die.c (dwarf_formref_die): Ditto.
* libdw/dwarf_getalt.c (dwarf_getalt): Ditto.
* libdw/dwarf_setalt.c (dwarf_setalt): Ditto.
* libdw/libdwP.h (struct Dwarf): Ditto.
* libdw/libdw_findcu.c (__libdw_findcu): Ditto.

Signed-off-by: Aaron Merey <amerey@redhat.com>
lib/locks.h
libdw/dwarf_begin_elf.c
libdw/dwarf_end.c
libdw/dwarf_formref_die.c
libdw/dwarf_getalt.c
libdw/dwarf_setalt.c
libdw/libdwP.h
libdw/libdw_findcu.c

index 90fe3f1b8befb925ed6ab5358bd92c7c5e183fab..9c17eca71c49ae747a999c15e92ae1173f3a8fa9 100644 (file)
 # define rwlock_rdlock(lock)            RWLOCK_CALL (rdlock (&lock))
 # define rwlock_wrlock(lock)            RWLOCK_CALL (wrlock (&lock))
 # define rwlock_unlock(lock)            RWLOCK_CALL (unlock (&lock))
+# define mutex_define(class,name)       class pthread_mutex_t name
+# define MUTEX_CALL(call)              \
+  ({ int _err = pthread_mutex_ ## call; assert_perror (_err); })
+# define mutex_init(lock)                                         \
+  ({ pthread_mutexattr_t _attr;                                           \
+     pthread_mutexattr_init (&_attr);                             \
+     pthread_mutexattr_settype (&_attr, PTHREAD_MUTEX_RECURSIVE);  \
+     MUTEX_CALL (init (&lock, &_attr)); })
+# define mutex_lock(_lock)             MUTEX_CALL (lock (&_lock))
+# define mutex_unlock(lock)            MUTEX_CALL (unlock (&lock))
+# define mutex_fini(lock)              MUTEX_CALL (destroy (&lock))
 # define once(once_control, init_routine)  \
   ONCE_CALL (once (&once_control, init_routine))
 #else
 # define rwlock_rdlock(lock) ((void) (lock))
 # define rwlock_wrlock(lock) ((void) (lock))
 # define rwlock_unlock(lock) ((void) (lock))
+# define mutex_define(class,name) class int name
+# define mutex_init(lock) ((void) (lock))
+# define mutex_lock(lock) ((void) (lock))
+# define mutex_unlock(lock) ((void) (lock))
+# define mutex_fini(lock) ((void) (lock))
 # define once_define(class,name)
 # define once(once_control, init_routine)       init_routine()
 #endif  /* USE_LOCKS */
index c8292913851a17131269bbf1af9acb7538e4b745..8a3a939bea3c23da8817e71c12e3a6c89638495c 100644 (file)
@@ -579,7 +579,7 @@ dwarf_begin_elf (Elf *elf, Dwarf_Cmd cmd, Elf_Scn *scngrp)
       __libdw_seterrno (DWARF_E_NOMEM); /* no memory.  */
       return NULL;
     }
-  rwlock_init (result->dwarf_lock);
+  mutex_init (result->dwarf_lock);
   eu_search_tree_init (&result->cu_tree);
   eu_search_tree_init (&result->tu_tree);
   eu_search_tree_init (&result->split_tree);
index ee3ed74e355821148c46c5e481dba839e5441a76..92389c07ae4af65f72a6712c11aa82a62588543f 100644 (file)
@@ -129,7 +129,7 @@ dwarf_end (Dwarf *dwarf)
       if (dwarf->mem_tails != NULL)
         free (dwarf->mem_tails);
       pthread_rwlock_destroy (&dwarf->mem_rwl);
-      rwlock_fini (dwarf->dwarf_lock);
+      mutex_fini (dwarf->dwarf_lock);
 
       /* Free the pubnames helper structure.  */
       free (dwarf->pubnames_sets);
index 69d1bf1cf54fddba0d831970c2b435590c49d080..85c484f6560f7fbc60d5c8ae782bb354e36ab7a4 100644 (file)
@@ -92,9 +92,9 @@ dwarf_formref_die (Dwarf_Attribute *attr, Dwarf_Die *result)
          bool scan_debug_types = false;
          do
            {
-             rwlock_wrlock(attr->cu->dbg->dwarf_lock);
+             mutex_lock (attr->cu->dbg->dwarf_lock);
              cu = __libdw_intern_next_unit (attr->cu->dbg, scan_debug_types);
-             rwlock_unlock(attr->cu->dbg->dwarf_lock);
+             mutex_unlock (attr->cu->dbg->dwarf_lock);
 
              if (cu == NULL)
                {
index 26433b8155ce1696333f768786d99bd256dc2416..f4b8ad02acdc431433a90320f841651cdb09e8ac 100644 (file)
@@ -170,12 +170,12 @@ dwarf_getalt (Dwarf *main)
   if (main == NULL)
     return NULL;
 
-  rwlock_wrlock(main->dwarf_lock);
+  mutex_lock (main->dwarf_lock);
 
   /* Only try once.  */
   if (main->alt_dwarf == (void *) -1)
     {
-      rwlock_unlock (main->dwarf_lock);
+      mutex_unlock (main->dwarf_lock);
       return NULL;
     }
 
@@ -185,7 +185,7 @@ dwarf_getalt (Dwarf *main)
   if (main->alt_dwarf != NULL)
     {
       result = main->alt_dwarf;
-      rwlock_unlock (main->dwarf_lock);
+      mutex_unlock (main->dwarf_lock);
       return result;
     }
 
@@ -195,12 +195,12 @@ dwarf_getalt (Dwarf *main)
   if (main->alt_dwarf == NULL)
     {
       main->alt_dwarf = (void *) -1;
-      rwlock_unlock (main->dwarf_lock);
+      mutex_unlock (main->dwarf_lock);
       return NULL;
     }
 
   result = main->alt_dwarf;
-  rwlock_unlock (main->dwarf_lock);
+  mutex_unlock (main->dwarf_lock);
 
   return result;
 }
index f98a457c690738b0b43cd65c7ed5037d9ed56fac..d8790fd3c08010d0357e1dfbd1c386982a168848 100644 (file)
@@ -35,7 +35,7 @@
 void
 dwarf_setalt (Dwarf *main, Dwarf *alt)
 {
-  rwlock_wrlock (main->dwarf_lock);
+  mutex_lock (main->dwarf_lock);
 
   if (main->alt_fd != -1)
     {
@@ -45,6 +45,6 @@ dwarf_setalt (Dwarf *main, Dwarf *alt)
     }
 
   main->alt_dwarf = alt;
-  rwlock_unlock (main->dwarf_lock);
+  mutex_unlock (main->dwarf_lock);
 }
 INTDEF (dwarf_setalt)
index 7d9c12607c0c841ca4a82b33e3f685bd106ea51d..a9d4c0a7c5a12bce7be9abc602c0ce2413f2352f 100644 (file)
@@ -264,9 +264,11 @@ struct Dwarf
      allocations for this Dwarf.  */
   pthread_rwlock_t mem_rwl;
 
-  /* The dwarf_lock is a read-write lock designed to ensure thread-safe access
-     and modification of an entire Dwarf object.  */
-  rwlock_define(, dwarf_lock);
+  /* Recursive mutex intended for setting/getting alt_dwarf, next_tu_offset,
+     and next_cu_offset.  Covers dwarf_getsrclines, dwarf_getsrcfiles and
+     dwarf_macro_getsrcfiles.  Should also be held when calling
+     __libdw_intern_next_unit.  */
+  mutex_define(, dwarf_lock);
 
   /* Internal memory handling.  This is basically a simplified thread-local
      reimplementation of obstacks.  Unfortunately the standard obstack
@@ -452,10 +454,11 @@ struct Dwarf_CU
   Dwarf_Off locs_base;
 
   /* Synchronize access to the abbrev member of a Dwarf_Die that
-     refers to this Dwarf_CU.  */
+     refers to this Dwarf_CU.  Covers __libdw_die_abbrev. */
   rwlock_define(, abbrev_lock);
 
-  /* Synchronize access to the split member of this Dwarf_CU.  */
+  /* Synchronize access to the split member of this Dwarf_CU.
+     Covers __libdw_find_split_unit.  */
   rwlock_define(, split_lock);
 
   /* Memory boundaries of this CU.  */
index bbbbee5d74e57959e6f1f60cf5cd04bbeced3e4a..613f61c89622f6316cabb3e53e8dc44e15fc0d7d 100644 (file)
@@ -249,7 +249,7 @@ __libdw_findcu (Dwarf *dbg, Dwarf_Off start, bool v4_debug_types)
   if (found != NULL)
     return *found;
 
-  rwlock_wrlock (dbg->dwarf_lock);
+  mutex_lock (dbg->dwarf_lock);
 
   if (start < *next_offset)
     __libdw_seterrno (DWARF_E_INVALID_DWARF);
@@ -276,7 +276,7 @@ __libdw_findcu (Dwarf *dbg, Dwarf_Off start, bool v4_debug_types)
        }
     }
 
-  rwlock_unlock (dbg->dwarf_lock);
+  mutex_unlock (dbg->dwarf_lock);
   return result;
 }