]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
propagate from branch 'com.redhat.elfutils.pmachata.threads' (head 8bd3bc10eb015c96f7...
authorUlrich Drepper <drepper@redhat.com>
Sat, 16 Aug 2008 03:09:13 +0000 (03:09 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sat, 16 Aug 2008 03:09:13 +0000 (03:09 +0000)
            to branch 'com.redhat.elfutils' (head c5a11b6b3329382f1b5ffd0020f0d93c64176f20)

67 files changed:
configure.ac
libasm/Makefile.am
libdwfl/ChangeLog
libelf/ChangeLog
libelf/Makefile.am
libelf/common.h
libelf/elf32_checksum.c
libelf/elf32_getehdr.c
libelf/elf32_getphdr.c
libelf/elf32_getshdr.c
libelf/elf32_newehdr.c
libelf/elf32_newphdr.c
libelf/elf32_offscn.c
libelf/elf32_updatenull.c
libelf/elf_begin.c
libelf/elf_clone.c
libelf/elf_cntl.c
libelf/elf_end.c
libelf/elf_getarsym.c
libelf/elf_getdata.c
libelf/elf_getscn.c
libelf/elf_getshnum.c
libelf/elf_getshstrndx.c
libelf/elf_newdata.c
libelf/elf_newscn.c
libelf/elf_nextscn.c
libelf/elf_rawdata.c
libelf/elf_readall.c
libelf/elf_strptr.c
libelf/elf_update.c
libelf/gelf_getauxv.c
libelf/gelf_getdyn.c
libelf/gelf_getehdr.c
libelf/gelf_getlib.c
libelf/gelf_getmove.c
libelf/gelf_getnote.c
libelf/gelf_getphdr.c
libelf/gelf_getrel.c
libelf/gelf_getrela.c
libelf/gelf_getshdr.c
libelf/gelf_getsym.c
libelf/gelf_getsyminfo.c
libelf/gelf_getsymshndx.c
libelf/gelf_getverdaux.c
libelf/gelf_getverdef.c
libelf/gelf_getvernaux.c
libelf/gelf_getverneed.c
libelf/gelf_getversym.c
libelf/gelf_update_auxv.c
libelf/gelf_update_dyn.c
libelf/gelf_update_ehdr.c
libelf/gelf_update_lib.c
libelf/gelf_update_move.c
libelf/gelf_update_phdr.c
libelf/gelf_update_rel.c
libelf/gelf_update_rela.c
libelf/gelf_update_shdr.c
libelf/gelf_update_sym.c
libelf/gelf_update_syminfo.c
libelf/gelf_update_symshndx.c
libelf/gelf_update_verdaux.c
libelf/gelf_update_verdef.c
libelf/gelf_update_vernaux.c
libelf/gelf_update_verneed.c
libelf/gelf_update_versym.c
libelf/libelfP.h
libelf/nlist.c

index c883b8dff3b279b096a7bbb86e331137c6f34531..4008efda5c66efad9baa3a37820aa7a56eb52417 100644 (file)
@@ -50,7 +50,10 @@ AC_CANONICAL_HOST
 
 AC_ARG_ENABLE([tls],
 AS_HELP_STRING([--enable-tls], [enable use of thread local storage]),
-AC_DEFINE(USE_TLS))
+use_tls=yes, use_tls=no)
+AM_CONDITIONAL(USE_TLS, test "$use_tls" = yes)
+AS_IF([test "$use_tls" = yes], [AC_DEFINE(USE_TLS)])
+
 AH_TEMPLATE([USE_TLS], [Defined if thread local storage should be used.])
 
 dnl Add all the languages for which translations are available.
@@ -226,6 +229,21 @@ AM_PO_SUBDIRS
 dnl Test of the config.h file.  We hide all kinds of configuration magic
 dnl in there.
 AH_BOTTOM([
+#ifdef USE_TLS
+# include <pthread.h>
+# define tls_key_t                     __thread void *
+# define key_create(keyp, freefct)     (1)
+# define getspecific(key)              key
+# define setspecific(key,val)          key = val
+# define once_define(class,name)       class struct { } name
+# define once_execute(name,fct)                ((void) &name, (void) (fct))
+# define rwlock_define(class,name)     class pthread_rwlock_t name
+# define rwlock_init(lock)             pthread_rwlock_init (&lock, NULL)
+# define rwlock_fini(lock)             pthread_rwlock_destroy (&lock)
+# define rwlock_rdlock(lock)           pthread_rwlock_rdlock (&lock)
+# define rwlock_wrlock(lock)           pthread_rwlock_wrlock (&lock)
+# define rwlock_unlock(lock)           pthread_rwlock_unlock (&lock)
+#else
 /* Eventually we will allow multi-threaded applications to use the
    libraries.  Therefore we will add the necessary locking although
    the macros used expand to nothing for now.  */
@@ -247,6 +265,7 @@ AH_BOTTOM([
       fct ();                                                                \
     name = 1;                                                                \
   } while (0)
+#endif
 
 /* gettext helper macro.  */
 #define N_(Str) Str
index bd5779e8e2f246cdd556141eb43352f953042f6b..2b39eaefc41041d20b6ba23720503b39d0b9d675 100644 (file)
@@ -65,12 +65,17 @@ if !MUDFLAP
 libasm_pic_a_SOURCES =
 am_libasm_pic_a_OBJECTS = $(libasm_a_SOURCES:.c=.os)
 
+libasm_so_LDLIBS =
+if USE_TLS
+libasm_so_LDLIBS += -lpthread
+endif
+
 libasm_so_SOURCES =
 libasm.so: libasm_pic.a libasm.map
        $(LINK) -shared -o $@ -Wl,--whole-archive,$<,--no-whole-archive \
                -Wl,--version-script,$(srcdir)/libasm.map,--no-undefined \
                -Wl,--soname,$@.$(VERSION) \
-               ../libebl/libebl.a ../libelf/libelf.so
+               ../libebl/libebl.a ../libelf/libelf.so $(libasm_so_LDLIBS)
        if readelf -d $@ | fgrep -q TEXTREL; then exit 1; fi
        ln -fs $@ $@.$(VERSION)
 
index 28c6ee3cdf9f3a2d61a4dae6202b00e97785c001..231f8af446ad5d397333c6227ebcac2a5093917f 100644 (file)
@@ -1,3 +1,9 @@
+2008-07-15  Petr Machata  <pmachata@redhat.com>
+
+       * linux-kernel-modules.c: #undef __USE_FILE_OFFSET64, it doesn't
+       work with fts.  It gets defined through <pthread.h> include in
+       <config.h>.
+
 2008-08-03  Roland McGrath  <roland@redhat.com>
 
        * linux-kernel-modules.c: Include <fts.h> before <config.h>.
index 8e07b9ded886d4023d3e7ae0c1e40f608740000f..193cb033391193606f382418ead10428e980e584 100644 (file)
@@ -1,3 +1,85 @@
+2008-08-05  Petr Machata  <pmachata@redhat.com>
+
+       * elf_getdata.c, libelfP.h (__elf_getdata_internal):
+       Add lockstat argument in a fashion similar to elf32_getehdr below.
+       * elf32_updatenull.c (__elf32_updatenull, __elf64_updatenull):
+       Call __elf32_getshdr_internal and __elf64_getshdr_internal
+       explicitly, not via INTUSE.
+       Call __elf_getdata_internal explicitly, not via INTUSE.
+
+2008-08-05  Petr Machata  <pmachata@redhat.com>
+
+       * gelf_getehdr.c, libelfP.h (__gelf_getehdr_internal):
+       Add lockstat argument in a fashion similar to elf32_getehdr below.
+       * elf_getdata.c, libelfP.h (__libelf_set_rawdata):
+       Add lockstat argument.
+       Call __gelf_getehdr_internal explicitly, not via INTUSE.
+       Call rwlock_to_wrlock instead of RWLOCK_UNLOCK/_WRLOCK sequence.
+       (elf_getdata): Pass lockstat argument to __libelf_set_rawdata.
+       * elf32_updatenull.c, libelfP.h
+       (__elf32_updatenull, __elf64_updatenull):
+       Add lockstat argument in a fashion similar to elf32_getehdr below.
+       Pass lockstat argument to __libelf_set_rawdata.
+       * elf_strptr.c (elf_strptr):
+       Pass lockstat argument to __libelf_set_rawdata.
+       * elf_update.c (elf_update):
+       Pass lockstat argument to __elf32_updatenull and
+       __elf64_updatenull.
+
+2008-08-05  Petr Machata  <pmachata@redhat.com>
+
+       * common.h (rwlock_to_wrlock, rwlock_from_wrlock): New functions.
+       * elf32_getphdr.c, libelfP.h
+       (__elf32_getphdr_internal, __elf64_getphdr_internal):
+       Add lockstat argument in a fashion similar to elf32_getehdr below.
+       * gelf_getphdr.c (gelf_getphdr): Call __elf32_getphdr_internal and
+       __elf32_getphdr_internal explicitly, not via INTUSE.
+
+2008-08-05  Petr Machata  <pmachata@redhat.com>
+
+       * libelfP.h (lockstat_t): New enum that describes what type of
+       lock is currently being held.  To be used by _internal functions.
+       * elf32_getehdr.c, libelfP.h
+       (__elf32_getehdr_internal, __elf64_getehdr_internal):
+       Take extra lockstat argument.
+       Move "meat" of the getehdr functinonality here.
+       * elf32_getehdr.c (elf32_getehdr, elf64_getehdr):
+       Make this a simple wrapper that calls _internal variant.
+       * elf32_updatenull.c: Call __elf32_getehdr_internal explicitly,
+       not via INTUSE.
+       * elf32_getshdr.c, libelfP.h
+       (__elf32_getshdr_internal, __elf64_getshdr_internal):
+       Add lockstat argument in a fashion similar to elf32_getehdr.
+       * elf_getshnum.c, libelfP.h (__elf_getshnum_internal):
+       Likewise.
+       * gelf_getshdr.c (gelf_getshdr): Call __elf32_getshdr_internal,
+       __elf64_getshdr_internal explicitly, not via INTUSE.
+
+2008-08-04  Petr Machata  <pmachata@redhat.com>
+
+       * common.h, elf32_getehdr.c, elf32_getphdr.c, elf32_getshdr.c,
+       elf32_newehdr.c, elf32_newphdr.c, elf32_offscn.c, elf_begin.c,
+       elf_clone.c, elf_cntl.c, elf_end.c, elf_getarsym.c, elf_getdata.c,
+       elf_getscn.c, elf_getshnum.c, elf_getshstrndx.c, elf_newdata.c,
+       elf_newscn.c, elf_nextscn.c, elf_readall.c, elf_strptr.c,
+       elf_update.c, gelf_getauxv.c, gelf_getdyn.c, gelf_getehdr.c,
+       gelf_getlib.c, gelf_getmove.c, gelf_getnote.c, gelf_getphdr.c,
+       gelf_getrel.c, gelf_getrela.c, gelf_getshdr.c, gelf_getsym.c,
+       gelf_getsyminfo.c, gelf_getsymshndx.c, gelf_getverdaux.c,
+       gelf_getverdef.c, gelf_getvernaux.c, gelf_getverneed.c,
+       gelf_getversym.c, gelf_update_auxv.c, gelf_update_dyn.c,
+       gelf_update_ehdr.c, gelf_update_lib.c, gelf_update_move.c,
+       gelf_update_phdr.c, gelf_update_rel.c, gelf_update_rela.c,
+       gelf_update_sym.c, gelf_update_syminfo.c, gelf_update_symshndx.c,
+       gelf_update_verdaux.c, gelf_update_verdef.c,
+       gelf_update_vernaux.c, gelf_update_verneed.c,
+       gelf_update_versym.c:
+               Change rwlock_{rd,wr,un}lock calls to RWLOCK_{RD,WR,UN}LOCK.
+
+2008-08-04  Petr Machata  <pmachata@redhat.com>
+
+       * libelfP.h (RWLOCK_RDLOCK, RWLOCK_WRLOCK, RWLOCK_UNLOCK): New macros.
+
 2008-07-28  Roland McGrath  <roland@redhat.com>
 
        * elf.h: Update from glibc.
index 5bbb42206e9b8c4b3fefb4403519c96c230c50f4..2458ecbda0c175583e8e8afbdbc0b714f227c2f6 100644 (file)
@@ -105,11 +105,16 @@ if !MUDFLAP
 libelf_pic_a_SOURCES =
 am_libelf_pic_a_OBJECTS = $(libelf_a_SOURCES:.c=.os)
 
+libelf_so_LDLIBS =
+if USE_TLS
+libelf_so_LDLIBS += -lpthread
+endif
+
 libelf_so_SOURCES =
 libelf.so: libelf_pic.a libelf.map
        $(LINK) -shared -o $@ -Wl,--whole-archive,$<,--no-whole-archive \
                -Wl,--version-script,$(srcdir)/libelf.map,--no-undefined \
-               -Wl,--soname,$@.$(VERSION),-z,-defs,-z,relro
+               -Wl,--soname,$@.$(VERSION),-z,-defs,-z,relro $(libelf_so_LDLIBS)
        if readelf -d $@ | fgrep -q TEXTREL; then exit 1; fi
        ln -fs $@ $@.$(VERSION)
 
index 757188c1466a462db9a0f409979f8b9aeb2a0ed2..c00bfbc51cc9ca9f714b362518929bbb68a9d2dd 100644 (file)
@@ -57,6 +57,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "libelfP.h"
 
 static inline Elf_Kind
 __attribute__ ((unused))
@@ -117,7 +118,7 @@ static void
 __attribute__ ((unused))
 libelf_acquire_all (Elf *elf)
 {
-  rwlock_wrlock (elf->lock);
+  RWLOCK_WRLOCK (elf->lock);
 
   if (elf->kind == ELF_K_AR)
     {
@@ -149,7 +150,33 @@ libelf_release_all (Elf *elf)
        }
     }
 
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
+}
+
+/* Convert given lock LOCK with lock state FROM to lock state
+   LS_WRLOCKED. */
+static void
+__attribute__ ((unused))
+rwlock_to_wrlock(lockstat_t from, rwlock_define (,*lock))
+{
+  if (from == LS_WRLOCKED)
+    return;
+  if (from == LS_RDLOCKED)
+    RWLOCK_UNLOCK (*lock);
+  RWLOCK_WRLOCK (*lock);
+}
+
+/* Convert given lock LOCK with lock state LS_WRLOCKED to lock state
+   TO. */
+static void
+__attribute__ ((unused))
+rwlock_from_wrlock(lockstat_t to, rwlock_define (,*lock))
+{
+  if (to == LS_WRLOCKED)
+    return;
+  RWLOCK_UNLOCK (*lock);
+  if (to == LS_RDLOCKED)
+    RWLOCK_RDLOCK (*lock);
 }
 
 
index 0e4ab9f71efbc1aa72b6089cb83d172d8639c024..ddc978dceee20ef429a4c539a0aee4304a95573a 100644 (file)
@@ -150,7 +150,7 @@ elfw2(LIBELFBITS,checksum) (elf)
        }
 
       /* Iterate through the list of data blocks.  */
-      while ((data = INTUSE(elf_getdata) (scn, data)) != NULL)
+      while ((data = __elf_getdata_internal (scn, data, LS_UNLOCKED)) != NULL)
        /* If the file byte order is the same as the host byte order
           process the buffer directly.  If the data is just a stream
           of bytes which the library will not convert we can use it
index bdb2cc417ca69ac16762f31d23d7ee57137bc7d8..e5c218a78f4dbdcfc77d88fb1d6e2ee10a1f8878 100644 (file)
@@ -63,8 +63,9 @@
 
 
 ElfW2(LIBELFBITS,Ehdr) *
-elfw2(LIBELFBITS,getehdr) (elf)
+__elfw2(LIBELFBITS,getehdr_internal) (elf, locked)
      Elf *elf;
+     lockstat_t locked;
 {
   ElfW2(LIBELFBITS,Ehdr) *result;
 
@@ -77,7 +78,8 @@ elfw2(LIBELFBITS,getehdr) (elf)
       return NULL;
     }
 
-  rwlock_rdlock (elf->lock);
+  if (locked == LS_UNLOCKED)
+    RWLOCK_RDLOCK (elf->lock);
 
   if (elf->class == 0)
     elf->class = ELFW(ELFCLASS,LIBELFBITS);
@@ -91,8 +93,18 @@ elfw2(LIBELFBITS,getehdr) (elf)
   result = elf->state.ELFW(elf,LIBELFBITS).ehdr;
 
  out:
-  rwlock_unlock (elf->lock);
+  if (locked == LS_UNLOCKED)
+    RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
-INTDEF(elfw2(LIBELFBITS,getehdr))
+
+ElfW2(LIBELFBITS,Ehdr) *
+elfw2(LIBELFBITS,getehdr) (elf)
+     Elf *elf;
+{
+  if (elf == NULL)
+    return NULL;
+
+  return __elfw2(LIBELFBITS,getehdr_internal) (elf, LS_UNLOCKED);
+}
index 6908724533adfbd0a4187ff4de9400396b7b9d69..972132e460daffec10c172661c455780e9868055 100644 (file)
@@ -67,7 +67,8 @@
 
 
 ElfW2(LIBELFBITS,Phdr) *
-elfw2(LIBELFBITS,getphdr) (elf)
+__elfw2(LIBELFBITS,getphdr_internal) (elf, locked)
+     lockstat_t locked;
      Elf *elf;
 {
   ElfW2(LIBELFBITS,Phdr) *result;
@@ -88,7 +89,7 @@ elfw2(LIBELFBITS,getphdr) (elf)
   if (likely (result != NULL))
     return result;
 
-  rwlock_wrlock (elf->lock);
+  rwlock_to_wrlock (locked, &elf->lock);
 
   if (elf->class == 0)
     elf->class = ELFW(ELFCLASS,LIBELFBITS);
@@ -234,8 +235,16 @@ elfw2(LIBELFBITS,getphdr) (elf)
     }
 
  out:
-  rwlock_unlock (elf->lock);
-
+  rwlock_from_wrlock (locked, &elf->lock);
   return result;
 }
-INTDEF(elfw2(LIBELFBITS,getphdr))
+
+ElfW2(LIBELFBITS,Phdr) *
+elfw2(LIBELFBITS,getphdr) (elf)
+     Elf *elf;
+{
+  if (elf == NULL)
+    return NULL;
+
+  return __elfw2(LIBELFBITS,getphdr_internal) (elf, LS_UNLOCKED);
+}
index c7f75bbb4f312b2d9d7999812ae34b1ed43e942c..8d65875203ed7f7c9f22892f07affa4ab028b55c 100644 (file)
 
 
 ElfW2(LIBELFBITS,Shdr) *
-elfw2(LIBELFBITS,getshdr) (scn)
+__elfw2(LIBELFBITS,getshdr_internal) (scn, locked)
      Elf_Scn *scn;
+     lockstat_t locked;
 {
+  /* XXX: no read locking here, figure out why is it not necessary. */
   ElfW2(LIBELFBITS,Shdr) *result;
 
   if (scn == NULL)
@@ -93,7 +95,7 @@ elfw2(LIBELFBITS,getshdr) (scn)
       Elf *elf = scn->elf;
       ElfW2(LIBELFBITS,Ehdr) *ehdr = elf->state.ELFW(elf,LIBELFBITS).ehdr;
 
-      rwlock_wrlock (elf->lock);
+      rwlock_to_wrlock (locked, &elf->lock);
 
       /* Try again, maybe the data is there now.  */
       result = scn->shdr.ELFW(e,LIBELFBITS);
@@ -101,7 +103,7 @@ elfw2(LIBELFBITS,getshdr) (scn)
        goto out;
 
       size_t shnum;
-      if (INTUSE (elf_getshnum) (elf, &shnum) != 0)
+      if (__elf_getshnum_internal (elf, &shnum, LS_WRLOCKED) != 0)
        goto out;
       size_t size = shnum * sizeof (ElfW2(LIBELFBITS,Shdr));
 
@@ -235,9 +237,15 @@ elfw2(LIBELFBITS,getshdr) (scn)
       assert (result != NULL);
 
     out:
-      rwlock_unlock (elf->lock);
+      rwlock_from_wrlock (locked, &elf->lock);
     }
 
   return result;
 }
-INTDEF(elfw2(LIBELFBITS,getshdr))
+
+ElfW2(LIBELFBITS,Shdr) *
+elfw2(LIBELFBITS,getshdr) (scn)
+     Elf_Scn *scn;
+{
+  return __elfw2(LIBELFBITS,getshdr_internal) (scn, LS_UNLOCKED);
+}
index 4e20056f2d70258a2729286a2285902a49204cf3..0ef68c5ded1cdc07a080c8669281f471de9ffec5 100644 (file)
@@ -77,7 +77,7 @@ elfw2(LIBELFBITS,newehdr) (elf)
       return NULL;
     }
 
-  rwlock_wrlock (elf->lock);
+  RWLOCK_WRLOCK (elf->lock);
 
   if (elf->class == 0)
     elf->class = ELFW(ELFCLASS,LIBELFBITS);
@@ -106,7 +106,7 @@ elfw2(LIBELFBITS,newehdr) (elf)
   result = elf->state.ELFW(elf,LIBELFBITS).ehdr;
 
  out:
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index d1b16088dbdafff083debe83c1cdf084c427b3a6..bc9378521c2f6f77415f0aa1f6aa110f0c4095ad 100644 (file)
@@ -79,7 +79,7 @@ elfw2(LIBELFBITS,newphdr) (elf, count)
       return NULL;
     }
 
-  rwlock_wrlock (elf->lock);
+  RWLOCK_WRLOCK (elf->lock);
 
   if (elf->class == 0)
     elf->class = ELFW(ELFCLASS,LIBELFBITS);
@@ -164,7 +164,7 @@ elfw2(LIBELFBITS,newphdr) (elf, count)
     }
 
  out:
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index 86eff8b10b97a7b51979d4ec1cc54dbc999b1fac..2f9e1ced752b9023b0d7137ace016e6d7ad6613d 100644 (file)
@@ -86,7 +86,7 @@ elfw2(LIBELFBITS,offscn) (elf, offset)
       && unlikely (elfw2(LIBELFBITS,getshdr) (&runp->data[0]) == NULL))
     return NULL;
 
-  rwlock_rdlock (elf->lock);
+  RWLOCK_RDLOCK (elf->lock);
 
   Elf_Scn *result = NULL;
 
@@ -114,7 +114,7 @@ elfw2(LIBELFBITS,offscn) (elf, offset)
     }
 
  out:
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index b3299fe41f45879e65f7741d01b27fbfff82b4d7..dd50fb29db353b030cc4aa6351340dd050744e48 100644 (file)
@@ -133,12 +133,15 @@ ELFW(default_ehdr,LIBELFBITS) (Elf *elf, ElfW2(LIBELFBITS,Ehdr) *ehdr,
 
 off_t
 internal_function
-__elfw2(LIBELFBITS,updatenull) (Elf *elf, int *change_bop, size_t shnum)
+__elfw2(LIBELFBITS,updatenull) (Elf *elf, int *change_bop,
+                               size_t shnum, lockstat_t locked)
 {
-  ElfW2(LIBELFBITS,Ehdr) *ehdr = INTUSE(elfw2(LIBELFBITS,getehdr)) (elf);
+  ElfW2(LIBELFBITS,Ehdr) *ehdr;
   int changed = 0;
   int ehdr_flags = 0;
 
+  ehdr = __elfw2(LIBELFBITS,getehdr_internal) (elf, locked);
+
   /* Set the default values.  */
   if (ELFW(default_ehdr,LIBELFBITS) (elf, ehdr, shnum, change_bop) != 0)
     return -1;
@@ -150,7 +153,7 @@ __elfw2(LIBELFBITS,updatenull) (Elf *elf, int *change_bop, size_t shnum)
   if (elf->state.ELFW(elf,LIBELFBITS).phdr == NULL
       && (ehdr->e_type == ET_EXEC || ehdr->e_type == ET_DYN
          || ehdr->e_type == ET_CORE))
-    (void) INTUSE(elfw2(LIBELFBITS,getphdr)) (elf);
+    (void) __elfw2(LIBELFBITS,getphdr_internal) (elf, locked);
   if (elf->state.ELFW(elf,LIBELFBITS).phdr != NULL)
     {
       /* Only executables, shared objects, and core files have a program
@@ -204,7 +207,7 @@ __elfw2(LIBELFBITS,updatenull) (Elf *elf, int *change_bop, size_t shnum)
       /* Load the section headers if necessary.  This loads the
         headers for all sections.  */
       if (list->data[1].shdr.ELFW(e,LIBELFBITS) == NULL)
-       (void) INTUSE(elfw2(LIBELFBITS,getshdr)) (&list->data[1]);
+       (void) __elfw2(LIBELFBITS,getshdr_internal) (&list->data[1], locked);
 
       do
        {
@@ -265,7 +268,8 @@ __elfw2(LIBELFBITS,updatenull) (Elf *elf, int *change_bop, size_t shnum)
              update_if_changed (shdr->sh_entsize, sh_entsize,
                                 scn->shdr_flags);
 
-             if (scn->data_read == 0 && __libelf_set_rawdata (scn) != 0)
+             if (scn->data_read == 0
+                 && __libelf_set_rawdata (scn, locked) != 0)
                /* Something went wrong.  The error value is already set.  */
                return -1;
 
@@ -364,7 +368,7 @@ __elfw2(LIBELFBITS,updatenull) (Elf *elf, int *change_bop, size_t shnum)
                    {
                      /* The position of the section in the file
                         changed.  Create the section data list.  */
-                     if (INTUSE(elf_getdata) (scn, NULL) == NULL)
+                     if (__elf_getdata_internal (scn, NULL, locked) == NULL)
                        return -1;
                    }
 
index b95b06bf997908f773170e35ac08665e260348da..1ce8c6a2014cc860d9e195e422b4b42712045d33 100644 (file)
@@ -1005,7 +1005,7 @@ elf_begin (fildes, cmd, ref)
 
   if (ref != NULL)
     /* Make sure the descriptor is not suddenly going away.  */
-    rwlock_rdlock (ref->lock);
+    RWLOCK_RDLOCK (ref->lock);
   else if (unlikely (fcntl (fildes, F_GETFL) == -1 && errno == EBADF))
     {
       /* We cannot do anything productive without a file descriptor.  */
@@ -1077,7 +1077,7 @@ elf_begin (fildes, cmd, ref)
 
   /* Release the lock.  */
   if (ref != NULL)
-    rwlock_unlock (ref->lock);
+    RWLOCK_UNLOCK (ref->lock);
 
   return retval;
 }
index 8b699fa6c0fce4c784e0d948bb429782fdd24fd2..3ace80d6d757a9d90ee885a05cf420451b4de9ed 100644 (file)
@@ -68,7 +68,7 @@ elf_clone (Elf *elf, Elf_Cmd cmd)
     return NULL;
 
   /* Make sure the descriptor is not suddenly going away.  */
-  rwlock_rdlock (elf->lock);
+  RWLOCK_RDLOCK (elf->lock);
 
   if (cmd != ELF_C_EMPTY)
     // XXX TODO handle ELF_C_READ/WRITE etc
@@ -96,7 +96,7 @@ elf_clone (Elf *elf, Elf_Cmd cmd)
 
   /* Release the lock.  */
  out:
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return retval;
 }
index fd5b47b967caa915ace13f8cb17d04732de73496..6c4fec3b4186bb68e1b1ed58cbaccd89d52defbf 100644 (file)
@@ -73,7 +73,7 @@ elf_cntl (elf, cmd)
       return -1;
     }
 
-  rwlock_wrlock (elf->lock);
+  RWLOCK_WRLOCK (elf->lock);
 
   switch (cmd)
     {
@@ -98,7 +98,7 @@ elf_cntl (elf, cmd)
       break;
     }
 
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index 5112eaea41157c11f3206f149042411094bf3bfb..1329ea16600ef9c1c04d0e7e044edd871db8ca69 100644 (file)
@@ -71,13 +71,13 @@ elf_end (elf)
     return 0;
 
   /* Make sure we are alone.  */
-  rwlock_wrlock (elf->lock);
+  RWLOCK_WRLOCK (elf->lock);
 
   if (elf->ref_count != 0 && --elf->ref_count != 0)
     {
       /* Not yet the last activation.  */
       int result = elf->ref_count;
-      rwlock_unlock (elf->lock);
+      RWLOCK_UNLOCK (elf->lock);
       return result;
     }
 
@@ -106,9 +106,9 @@ elf_end (elf)
         solve this problem by giving free the child lock.  The
         state of REF_COUNT==0 is handled all over the library, so
         this should be ok.  */
-      rwlock_unlock (elf->lock);
-      rwlock_rdlock (parent->lock);
-      rwlock_wrlock (elf->lock);
+      RWLOCK_UNLOCK (elf->lock);
+      RWLOCK_RDLOCK (parent->lock);
+      RWLOCK_WRLOCK (elf->lock);
 
       if (parent->state.ar.children == elf)
        parent->state.ar.children = elf->next;
@@ -122,7 +122,7 @@ elf_end (elf)
          child->next = elf->next;
        }
 
-      rwlock_unlock (parent->lock);
+      RWLOCK_UNLOCK (parent->lock);
     }
 
   /* This was the last activation.  Free all resources.  */
index e6ecaadc724b9a8da1b507b83c30b3d5002b828d..595980571f50c9e355ff7829f4c303d0467228d5 100644 (file)
@@ -94,7 +94,7 @@ elf_getarsym (elf, ptr)
   if (result == NULL)
     {
       /* We have not yet read the index.  */
-      rwlock_wrlock (elf->lock);
+      RWLOCK_WRLOCK (elf->lock);
 
       /* In case we find no index remember this for the next call.  */
       elf->state.ar.ar_sym = (Elf_Arsym *) -1l;
@@ -268,7 +268,7 @@ elf_getarsym (elf, ptr)
       result = elf->state.ar.ar_sym;
 
     out:
-      rwlock_unlock (elf->lock);
+      RWLOCK_UNLOCK (elf->lock);
     }
 
   if (ptr != NULL)
index ae5b41df0d0a0ea0bbfd81dc224aadb302b7b3fc..dc10a689e69a6425dbea601320979a1752ef7efb 100644 (file)
@@ -189,7 +189,7 @@ convert_data (Elf_Scn *scn, int version __attribute__ ((unused)), int eclass,
 /* Store the information for the raw data in the `rawdata' element.  */
 int
 internal_function
-__libelf_set_rawdata (Elf_Scn *scn)
+__libelf_set_rawdata (Elf_Scn *scn, lockstat_t locked)
 {
   size_t offset;
   size_t size;
@@ -199,7 +199,8 @@ __libelf_set_rawdata (Elf_Scn *scn)
 
   if (elf->class == ELFCLASS32)
     {
-      Elf32_Shdr *shdr = scn->shdr.e32 ?: INTUSE(elf32_getshdr) (scn);
+      Elf32_Shdr *shdr
+       = scn->shdr.e32 ?: __elf32_getshdr_internal (scn, locked);
 
       if (shdr == NULL)
        /* Something went terribly wrong.  */
@@ -212,7 +213,8 @@ __libelf_set_rawdata (Elf_Scn *scn)
     }
   else
     {
-      Elf64_Shdr *shdr = scn->shdr.e64 ?: INTUSE(elf64_getshdr) (scn);
+      Elf64_Shdr *shdr
+       = scn->shdr.e64 ?: __elf64_getshdr_internal (scn, locked);
 
       if (shdr == NULL)
        /* Something went terribly wrong.  */
@@ -234,8 +236,8 @@ __libelf_set_rawdata (Elf_Scn *scn)
       if (type == SHT_HASH)
        {
          GElf_Ehdr ehdr_mem;
-
-         entsize = SH_ENTSIZE_HASH (INTUSE(gelf_getehdr) (elf, &ehdr_mem));
+         GElf_Ehdr *ehdr = __gelf_getehdr_internal (elf, &ehdr_mem, locked);
+         entsize = SH_ENTSIZE_HASH (ehdr);
        }
       else
        {
@@ -311,10 +313,9 @@ __libelf_set_rawdata (Elf_Scn *scn)
   if (type == SHT_HASH && elf->class == ELFCLASS64)
     {
       GElf_Ehdr ehdr_mem;
-
+      GElf_Ehdr *ehdr = __gelf_getehdr_internal (elf, &ehdr_mem, locked);
       scn->rawdata.d.d_type
-       = (SH_ENTSIZE_HASH (INTUSE(gelf_getehdr) (elf, &ehdr_mem)) == 4
-          ? ELF_T_WORD : ELF_T_XWORD);
+       = (SH_ENTSIZE_HASH (ehdr) == 4 ? ELF_T_WORD : ELF_T_XWORD);
     }
   else
     scn->rawdata.d.d_type = shtype_map[LIBELF_EV_IDX][TYPEIDX (type)];
@@ -341,9 +342,10 @@ __libelf_set_rawdata (Elf_Scn *scn)
 
 
 Elf_Data *
-elf_getdata (scn, data)
+__elf_getdata_internal (scn, data, locked)
      Elf_Scn *scn;
      Elf_Data *data;
+     lockstat_t locked;
 {
   Elf_Data *result = NULL;
   Elf *elf;
@@ -360,7 +362,8 @@ elf_getdata (scn, data)
   /* We will need this multiple times later on.  */
   elf = scn->elf;
 
-  rwlock_rdlock (elf->lock);
+  if (locked == LS_UNLOCKED)
+    RWLOCK_RDLOCK (elf->lock);
 
   /* If `data' is not NULL this means we are not addressing the initial
      data in the file.  But this also means this data is already read
@@ -414,13 +417,12 @@ elf_getdata (scn, data)
          lock.  Therefore give up the read lock and then get the write
          lock.  But this means that the data could meanwhile be
          modified, therefore start the tests again.  */
-      rwlock_unlock (elf->lock);
-      rwlock_wrlock (elf->lock);
+      rwlock_to_wrlock (LS_RDLOCKED, &elf->lock);
 
       /* Read the data from the file.  There is always a file (or
         memory region) associated with this descriptor since
         otherwise the `data_read' flag would be set.  */
-      if (scn->data_read == 0 && __libelf_set_rawdata (scn) != 0)
+      if (scn->data_read == 0 && __libelf_set_rawdata (scn, LS_WRLOCKED) != 0)
        /* Something went wrong.  The error value is already set.  */
        goto out;
     }
@@ -453,8 +455,19 @@ elf_getdata (scn, data)
     result = &scn->data_list.data.d;
 
  out:
-  rwlock_unlock (elf->lock);
+  if (locked == LS_UNLOCKED)
+    RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
-INTDEF(elf_getdata)
+
+Elf_Data *
+elf_getdata (scn, data)
+     Elf_Scn *scn;
+     Elf_Data *data;
+{
+  if (scn == NULL)
+    return NULL;
+
+  return __elf_getdata_internal (scn, data, LS_UNLOCKED);
+}
index 5c14a580e629578d5002500566cc155151f52921..5bcceb6368e346648ad2bc423ea26046ebb84b26 100644 (file)
@@ -73,7 +73,7 @@ elf_getscn (elf, idx)
       return NULL;
     }
 
-  rwlock_rdlock (elf->lock);
+  RWLOCK_RDLOCK (elf->lock);
 
   Elf_Scn *result = NULL;
 
@@ -103,7 +103,7 @@ elf_getscn (elf, idx)
        }
     }
 
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index bf26a9b0062bf6d7cf1d832403bb0386bd5ca923..10402d83f51b52b872979c061741b5705bdea23f 100644 (file)
 
 
 int
-elf_getshnum (elf, dst)
+__elf_getshnum_internal (elf, dst, locked)
      Elf *elf;
      size_t *dst;
+     lockstat_t locked;
 {
   int result = 0;
   int idx;
@@ -76,7 +77,8 @@ elf_getshnum (elf, dst)
       return -1;
     }
 
-  rwlock_rdlock (elf->lock);
+  if (locked == LS_UNLOCKED)
+    RWLOCK_RDLOCK (elf->lock);
 
   idx = elf->state.elf.scns_last->cnt;
   if (idx != 0
@@ -90,8 +92,19 @@ elf_getshnum (elf, dst)
   else
     *dst = 0;
 
-  rwlock_unlock (elf->lock);
+  if (locked == LS_UNLOCKED)
+    RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
-INTDEF(elf_getshnum)
+
+int
+elf_getshnum (elf, dst)
+     Elf *elf;
+     size_t *dst;
+{
+  if (elf == NULL)
+    return -1;
+
+  return __elf_getshnum_internal (elf, dst, LS_UNLOCKED);
+}
index 52516a8e0355d2f6c8620670d05271784ea782d9..9d0d27b8acbd99d80a63da75dce8d8fb7a01853f 100644 (file)
@@ -79,7 +79,7 @@ elf_getshstrndx (elf, dst)
       return -1;
     }
 
-  rwlock_rdlock (elf->lock);
+  RWLOCK_RDLOCK (elf->lock);
 
   /* We rely here on the fact that the `elf' element is a common prefix
      of `elf32' and `elf64'.  */
@@ -196,7 +196,7 @@ elf_getshstrndx (elf, dst)
     }
 
  out:
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index db17ea582b746c96861fea634cbf5bf016e0df50..1f42204d073db497624d7762d70c473d5407aa94 100644 (file)
@@ -83,7 +83,7 @@ elf_newdata (Elf_Scn *scn)
       return NULL;
     }
 
-  rwlock_wrlock (scn->elf->lock);
+  RWLOCK_WRLOCK (scn->elf->lock);
 
   if (scn->data_read && scn->data_list_rear == NULL)
     {
@@ -122,7 +122,7 @@ elf_newdata (Elf_Scn *scn)
   scn->data_list_rear = result;
 
  out:
-  rwlock_unlock (scn->elf->lock);
+  RWLOCK_UNLOCK (scn->elf->lock);
 
   /* Please note that the following is thread safe and is also defined
      for RESULT == NULL since it still return NULL.  */
index aefab3345e3ac1621153a82af116c5c83516c552..da4ca723586252a1fb2b0d0702e02be7c22758e6 100644 (file)
@@ -80,7 +80,7 @@ elf_newscn (elf)
   assert (offsetof (Elf, state.elf32.scns)
          == offsetof (Elf, state.elf64.scns));
 
-  rwlock_wrlock (elf->lock);
+  RWLOCK_WRLOCK (elf->lock);
 
  again:
   if (elf->state.elf.scns_last->cnt < elf->state.elf.scns_last->max)
@@ -170,7 +170,7 @@ elf_newscn (elf)
   result->flags |= ELF_F_DIRTY;
 
  out:
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index a1842bb3b4a4e961b4b4060d50567d26f85340df..0a21c76f7992bd85256576a6a3ac9bce09f0fb8e 100644 (file)
@@ -69,7 +69,7 @@ elf_nextscn (elf, scn)
   if (elf == NULL)
     return NULL;
 
-  rwlock_rdlock (elf->lock);
+  RWLOCK_RDLOCK (elf->lock);
 
   if (scn == NULL)
     {
@@ -103,7 +103,7 @@ elf_nextscn (elf, scn)
        }
     }
 
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index b8bb0f4bb25073600bbd5af2f005d897aeff62b3..b8be27c7c3322a1fd7dba8e903f0010a4f0bdfda 100644 (file)
@@ -88,7 +88,7 @@ elf_rawdata (scn, data)
       /* First thing we do is to read the data from the file.  There is
         always a file (or memory region) associated with this descriptor
         since otherwise the `data_read' flag would be set.  */
-      if (__libelf_set_rawdata (scn) != 0)
+      if (__libelf_set_rawdata (scn, LS_UNLOCKED) != 0)
        /* Something went wrong.  The error value is already set.  */
        return NULL;
     }
index 8f171b21c494a6da672f78b71a918c90ba064757..71daea4bc9eada9039b08a36083310ea276ba388 100644 (file)
@@ -90,12 +90,12 @@ __libelf_readall (elf)
      Elf *elf;
 {
   /* Get the file.  */
-  rwlock_wrlock (elf->lock);
+  RWLOCK_WRLOCK (elf->lock);
 
   if (elf->map_address == NULL && unlikely (elf->fildes == -1))
     {
       __libelf_seterrno (ELF_E_INVALID_HANDLE);
-      rwlock_unlock (elf->lock);
+      RWLOCK_UNLOCK (elf->lock);
       return NULL;
     }
 
@@ -147,7 +147,7 @@ __libelf_readall (elf)
       libelf_release_all (elf);
     }
 
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return (char *) elf->map_address;
 }
index c1ea60de5a6522cc39a50e22deada8084936148f..6fb0c50c504fecd175642c2cfde09bd0fd84d323 100644 (file)
@@ -73,7 +73,7 @@ elf_strptr (elf, idx, offset)
       return NULL;
     }
 
-  rwlock_rdlock (elf->lock);
+  RWLOCK_RDLOCK (elf->lock);
 
   char *result = NULL;
   Elf_Scn *strscn;
@@ -142,7 +142,7 @@ elf_strptr (elf, idx, offset)
 
   if (strscn->rawdata_base == NULL && ! strscn->data_read
       /* Read the section data.  */
-      && __libelf_set_rawdata (strscn) != 0)
+      && __libelf_set_rawdata (strscn, LS_RDLOCKED) != 0)
     goto out;
 
   if (likely (strscn->rawdata_base != NULL))
@@ -166,7 +166,7 @@ elf_strptr (elf, idx, offset)
     }
 
  out:
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index 24e813fb6ebc6aa68aa6d3125f80167c6f64b9ed..8d605e05b01639869e7e21cfb0528f9d1cd3c4e8 100644 (file)
@@ -174,7 +174,7 @@ elf_update (elf, cmd)
       return -1;
     }
 
-  rwlock_wrlock (elf->lock);
+  RWLOCK_WRLOCK (elf->lock);
 
   /* Make sure we have an ELF header.  */
   if (elf->state.elf.ehdr == NULL)
@@ -193,8 +193,8 @@ elf_update (elf, cmd)
      will come right after the ELF header.  The count the size of all
      sections and finally place the section table.  */
   size = (elf->class == ELFCLASS32
-         ? __elf32_updatenull (elf, &change_bo, shnum)
-         : __elf64_updatenull (elf, &change_bo, shnum));
+         ? __elf32_updatenull (elf, &change_bo, shnum, LS_WRLOCKED)
+         : __elf64_updatenull (elf, &change_bo, shnum, LS_WRLOCKED));
   if (likely (size != -1)
       /* See whether we actually have to write out the data.  */
       && (cmd == ELF_C_WRITE || cmd == ELF_C_WRITE_MMAP))
@@ -218,7 +218,7 @@ elf_update (elf, cmd)
     }
 
  out:
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return size;
 }
index 036bdccf70997534b9fb78db9092788a5f7203d9..450e81b163b33578fc9f7209851d5e7ff1d11cf3 100644 (file)
@@ -79,7 +79,7 @@ gelf_getauxv (data, ndx, dst)
 
   elf = data_scn->s->elf;
 
-  rwlock_rdlock (elf->lock);
+  RWLOCK_RDLOCK (elf->lock);
 
   /* This is the one place where we have to take advantage of the fact
      that an `Elf_Data' pointer is also a pointer to `Elf_Data_Scn'.
@@ -124,7 +124,7 @@ gelf_getauxv (data, ndx, dst)
   result = dst;
 
  out:
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index 82f8e3285205dfb60b0108e3e05daedbb7fdb3b3..c032e5b2dc0b85c348a28e23aed08c271f5445d6 100644 (file)
@@ -80,7 +80,7 @@ gelf_getdyn (data, ndx, dst)
 
   elf = data_scn->s->elf;
 
-  rwlock_rdlock (elf->lock);
+  RWLOCK_RDLOCK (elf->lock);
 
   /* This is the one place where we have to take advantage of the fact
      that an `Elf_Data' pointer is also a pointer to `Elf_Data_Scn'.
@@ -126,7 +126,7 @@ gelf_getdyn (data, ndx, dst)
   result = dst;
 
  out:
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index f56d65a97d29ac5a8ae2adec4d9ae14d7070d2b1..ddc7707262ae20db9cd09e2ef8a4b7598959e1fd 100644 (file)
 
 
 GElf_Ehdr *
-gelf_getehdr (elf, dest)
+__gelf_getehdr_internal (elf, dest, locked)
      Elf *elf;
      GElf_Ehdr *dest;
+     lockstat_t locked;
 {
   GElf_Ehdr *result = NULL;
 
@@ -76,7 +77,8 @@ gelf_getehdr (elf, dest)
       return NULL;
     }
 
-  rwlock_rdlock (elf->lock);
+  if (locked == LS_UNLOCKED)
+    RWLOCK_RDLOCK (elf->lock);
 
   /* The following is an optimization: the ehdr element is at the same
      position in both the elf32 and elf64 structure.  */
@@ -114,8 +116,19 @@ gelf_getehdr (elf, dest)
   else
     result = memcpy (dest, elf->state.elf64.ehdr, sizeof (*dest));
 
-  rwlock_unlock (elf->lock);
+  if (locked == LS_UNLOCKED)
+    RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
-INTDEF(gelf_getehdr)
+
+GElf_Ehdr *
+gelf_getehdr (elf, dest)
+     Elf *elf;
+     GElf_Ehdr *dest;
+{
+  if (elf == NULL)
+    return NULL;
+
+  return __gelf_getehdr_internal (elf, dest, LS_UNLOCKED);
+}
index aa91a73bdf3b9e0d5be3b1b5787d32a3f3f54593..75a4a4ade782f1e3937370f4d1f77accc0aaef54 100644 (file)
@@ -76,7 +76,7 @@ gelf_getlib (data, ndx, dst)
 
   Elf_Data_Scn *data_scn = (Elf_Data_Scn *) data;
 
-  rwlock_rdlock (data_scn->s->elf->lock);
+  RWLOCK_RDLOCK (data_scn->s->elf->lock);
 
   /* The on disk format of Elf32_Lib and Elf64_Lib is identical.  So
      we can simplify things significantly.  */
@@ -95,7 +95,7 @@ gelf_getlib (data, ndx, dst)
       result = dst;
     }
 
-  rwlock_unlock (data_scn->s->elf->lock);
+  RWLOCK_UNLOCK (data_scn->s->elf->lock);
 
   return result;
 }
index 6e769484a051da5abdeb6f9272d64da615aa54bd..728c54eba5c930ad1fb9ca796ab7e3b5e357de52 100644 (file)
@@ -90,11 +90,11 @@ gelf_getmove (data, ndx, dst)
     }
 
   elf = ((Elf_Data_Scn *) data)->s->elf;
-  rwlock_rdlock (elf->lock);
+  RWLOCK_RDLOCK (elf->lock);
 
   *dst = ((GElf_Move *) data->d_buf)[ndx];
 
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   result = dst;
 
index e4900185fd1a7b2a177029c30ec75545e79749a8..6867aeb4267d10b4f3704aa6b58e1b6a897abb6f 100644 (file)
@@ -79,7 +79,7 @@ gelf_getnote (data, offset, result, name_offset, desc_offset)
   assert (sizeof (GElf_Nhdr) == sizeof (Elf32_Nhdr));
   assert (sizeof (GElf_Nhdr) == sizeof (Elf64_Nhdr));
 
-  rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
+  RWLOCK_RDLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
 
   /* The data is already in the correct form.  Just make sure the
      offset is OK.  */
@@ -113,7 +113,7 @@ gelf_getnote (data, offset, result, name_offset, desc_offset)
        }
     }
 
-  rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock);
+  RWLOCK_UNLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
 
   return offset;
 }
index da83ccf7140f3a3e8eb42c507438622d5a023abf..286b253e32bd8104309f2d79864636c2715c4d08 100644 (file)
@@ -81,7 +81,7 @@ gelf_getphdr (elf, ndx, dst)
       return NULL;
     }
 
-  rwlock_rdlock (elf->lock);
+  RWLOCK_RDLOCK (elf->lock);
 
   if (elf->class == ELFCLASS32)
     {
@@ -90,7 +90,7 @@ gelf_getphdr (elf, ndx, dst)
 
       if (phdr == NULL)
        {
-         phdr = INTUSE(elf32_getphdr) (elf);
+         phdr = __elf32_getphdr_internal (elf, LS_RDLOCKED);
          if (phdr == NULL)
            /* The error number is already set.  */
            goto out;
@@ -126,7 +126,7 @@ gelf_getphdr (elf, ndx, dst)
 
       if (phdr == NULL)
        {
-         phdr = INTUSE(elf64_getphdr) (elf);
+         phdr = __elf64_getphdr_internal (elf, LS_RDLOCKED);
          if (phdr == NULL)
            /* The error number is already set.  */
            goto out;
@@ -144,7 +144,7 @@ gelf_getphdr (elf, ndx, dst)
     }
 
  out:
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index f3775bd9de940b7b9a1317cb68562225c761366b..74a5595a5047e9275fcfcb78d156865a75d52ba4 100644 (file)
@@ -88,7 +88,7 @@ gelf_getrel (data, ndx, dst)
      The interface is broken so that it requires this hack.  */
   scn = data_scn->s;
 
-  rwlock_rdlock (scn->elf->lock);
+  RWLOCK_RDLOCK (scn->elf->lock);
 
   if (scn->elf->class == ELFCLASS32)
     {
@@ -123,7 +123,7 @@ gelf_getrel (data, ndx, dst)
                         sizeof (Elf64_Rel));
     }
 
-  rwlock_unlock (scn->elf->lock);
+  RWLOCK_UNLOCK (scn->elf->lock);
 
   return result;
 }
index 0275c375f172f6b16c35d6b7a030885864536045..f62bd2866737ee351019e2f5b5e21f4b748a116f 100644 (file)
@@ -88,7 +88,7 @@ gelf_getrela (data, ndx, dst)
      The interface is broken so that it requires this hack.  */
   scn = data_scn->s;
 
-  rwlock_rdlock (scn->elf->lock);
+  RWLOCK_RDLOCK (scn->elf->lock);
 
   if (scn->elf->class == ELFCLASS32)
     {
@@ -124,7 +124,7 @@ gelf_getrela (data, ndx, dst)
                         sizeof (Elf64_Rela));
     }
 
-  rwlock_unlock (scn->elf->lock);
+  RWLOCK_UNLOCK (scn->elf->lock);
 
   return result;
 }
index 7f01a8fc094e9d19502803db6cf753c8796399be..f5457a7ad348bc10396697487ef18918d2c03b94 100644 (file)
@@ -74,12 +74,13 @@ gelf_getshdr (scn, dst)
       return NULL;
     }
 
-  rwlock_rdlock (scn->elf->lock);
+  RWLOCK_RDLOCK (scn->elf->lock);
 
   if (scn->elf->class == ELFCLASS32)
     {
       /* Copy the elements one-by-one.  */
-      Elf32_Shdr *shdr = scn->shdr.e32 ?: INTUSE(elf32_getshdr) (scn);
+      Elf32_Shdr *shdr
+       = scn->shdr.e32 ?: __elf32_getshdr_internal (scn, LS_RDLOCKED);
 
       if (shdr == NULL)
        {
@@ -104,7 +105,8 @@ gelf_getshdr (scn, dst)
     }
   else
     {
-      Elf64_Shdr *shdr = scn->shdr.e64 ?: INTUSE(elf64_getshdr) (scn);
+      Elf64_Shdr *shdr
+       = scn->shdr.e64 ?: __elf64_getshdr_internal (scn, LS_RDLOCKED);
 
       if (shdr == NULL)
        {
@@ -117,7 +119,7 @@ gelf_getshdr (scn, dst)
     }
 
  out:
-  rwlock_unlock (scn->elf->lock);
+  RWLOCK_UNLOCK (scn->elf->lock);
 
   return result;
 }
index 162061f7ddd6e682498db1f9287855798650ad97..4f2a2bec9d53faa2a1282f6a27cfdfce7340cafe 100644 (file)
@@ -77,7 +77,7 @@ gelf_getsym (data, ndx, dst)
       return NULL;
     }
 
-  rwlock_rdlock (data_scn->s->elf->lock);
+  RWLOCK_RDLOCK (data_scn->s->elf->lock);
 
   /* This is the one place where we have to take advantage of the fact
      that an `Elf_Data' pointer is also a pointer to `Elf_Data_Scn'.
@@ -131,7 +131,7 @@ gelf_getsym (data, ndx, dst)
   result = dst;
 
  out:
-  rwlock_unlock (data_scn->s->elf->lock);
+  RWLOCK_UNLOCK (data_scn->s->elf->lock);
 
   return result;
 }
index 2c07526af97cccebe765f88439dc705c6fd80a61..c5a312c4036c2884cf9db2b86c9d0c4f1160dfe3 100644 (file)
@@ -80,7 +80,7 @@ gelf_getsyminfo (data, ndx, dst)
   assert (sizeof (GElf_Syminfo) == sizeof (Elf32_Syminfo));
   assert (sizeof (GElf_Syminfo) == sizeof (Elf64_Syminfo));
 
-  rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
+  RWLOCK_RDLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
 
   /* The data is already in the correct form.  Just make sure the
      index is OK.  */
@@ -95,7 +95,7 @@ gelf_getsyminfo (data, ndx, dst)
   result = dst;
 
  out:
-  rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock);
+  RWLOCK_UNLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
 
   return result;
 }
index a9cfc181e188aff2427c5c1e97718f20ab0b0a4b..7fa096801664af380754dbd2ca40065010e558ba 100644 (file)
@@ -84,7 +84,7 @@ gelf_getsymshndx (symdata, shndxdata, ndx, dst, dstshndx)
       return NULL;
     }
 
-  rwlock_rdlock (symdata_scn->s->elf->lock);
+  RWLOCK_RDLOCK (symdata_scn->s->elf->lock);
 
   /* The user is not required to pass a data descriptor for an extended
      section index table.  */
@@ -155,7 +155,7 @@ gelf_getsymshndx (symdata, shndxdata, ndx, dst, dstshndx)
   result = dst;
 
  out:
-  rwlock_unlock (symdata_scn->s->elf->lock);
+  RWLOCK_UNLOCK (symdata_scn->s->elf->lock);
 
   return result;
 }
index b8bcf14ebd696b2bd25c2939134746e3f70778d0..df796a8a6a795b2ec05df406369aa99cc85ba23e 100644 (file)
@@ -81,7 +81,7 @@ gelf_getverdaux (data, offset, dst)
   assert (sizeof (GElf_Verdaux) == sizeof (Elf32_Verdaux));
   assert (sizeof (GElf_Verdaux) == sizeof (Elf64_Verdaux));
 
-  rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
+  RWLOCK_RDLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
 
   /* The data is already in the correct form.  Just make sure the
      index is OK.  */
@@ -97,7 +97,7 @@ gelf_getverdaux (data, offset, dst)
                                      sizeof (GElf_Verdaux));
 
 
-  rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock);
+  RWLOCK_UNLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
 
   return result;
 }
index 05cc2e892da5418aa7151b66826be51f9a0e93c4..babfa993dc31a5a5092580458d5581e0b3d55ba5 100644 (file)
@@ -81,7 +81,7 @@ gelf_getverdef (data, offset, dst)
   assert (sizeof (GElf_Verdef) == sizeof (Elf32_Verdef));
   assert (sizeof (GElf_Verdef) == sizeof (Elf64_Verdef));
 
-  rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
+  RWLOCK_RDLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
 
   /* The data is already in the correct form.  Just make sure the
      index is OK.  */
@@ -96,7 +96,7 @@ gelf_getverdef (data, offset, dst)
     result = (GElf_Verdef *) memcpy (dst, (char *) data->d_buf + offset,
                                     sizeof (GElf_Verdef));
 
-  rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock);
+  RWLOCK_UNLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
 
   return result;
 }
index 45d3300fa52865b0ed2191df32d3f58af3b763bf..070e97ec2f5a1df66546035c346dac0c23128480 100644 (file)
@@ -84,7 +84,7 @@ gelf_getvernaux (data, offset, dst)
   assert (sizeof (GElf_Vernaux) == sizeof (Elf32_Vernaux));
   assert (sizeof (GElf_Vernaux) == sizeof (Elf64_Vernaux));
 
-  rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
+  RWLOCK_RDLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
 
   /* The data is already in the correct form.  Just make sure the
      index is OK.  */
@@ -99,7 +99,7 @@ gelf_getvernaux (data, offset, dst)
     result = (GElf_Vernaux *) memcpy (dst, (char *) data->d_buf + offset,
                                      sizeof (GElf_Verneed));
 
-  rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock);
+  RWLOCK_UNLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
 
   return result;
 }
index e82a055d68255c1ab0f6e49dbbea21789e7540a0..3e2f1486a36a50efffa9be1a97803b16b442b54e 100644 (file)
@@ -84,7 +84,7 @@ gelf_getverneed (data, offset, dst)
   assert (sizeof (GElf_Verneed) == sizeof (Elf32_Vernaux));
   assert (sizeof (GElf_Verneed) == sizeof (Elf64_Vernaux));
 
-  rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
+  RWLOCK_RDLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
 
   /* The data is already in the correct form.  Just make sure the
      index is OK.  */
@@ -99,7 +99,7 @@ gelf_getverneed (data, offset, dst)
     result = (GElf_Verneed *) memcpy (dst, (char *) data->d_buf + offset,
                                      sizeof (GElf_Verneed));
 
-  rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock);
+  RWLOCK_UNLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
 
   return result;
 }
index 397b7edbf64483b919796b14ec28a1aa7b261ee7..011a54af871648ac5871773b4ce47ffcb9a1b12d 100644 (file)
@@ -88,7 +88,7 @@ gelf_getversym (data, ndx, dst)
   assert (sizeof (GElf_Versym) == sizeof (Elf32_Versym));
   assert (sizeof (GElf_Versym) == sizeof (Elf64_Versym));
 
-  rwlock_rdlock (scn->elf->lock);
+  RWLOCK_RDLOCK (scn->elf->lock);
 
   /* The data is already in the correct form.  Just make sure the
      index is OK.  */
@@ -104,7 +104,7 @@ gelf_getversym (data, ndx, dst)
       result = dst;
     }
 
-  rwlock_unlock (scn->elf->lock);
+  RWLOCK_UNLOCK (scn->elf->lock);
 
   return result;
 }
index b294ead7f163925a92f1cc2e95f1a10af4234813..dbcde82d0b27bf992403ea7cbdf4b0089a941d0a 100644 (file)
@@ -84,7 +84,7 @@ gelf_update_auxv (data, ndx, src)
     }
 
   scn = data_scn->s;
-  rwlock_wrlock (scn->elf->lock);
+  RWLOCK_WRLOCK (scn->elf->lock);
 
   if (scn->elf->class == ELFCLASS32)
     {
@@ -129,7 +129,7 @@ gelf_update_auxv (data, ndx, src)
   scn->flags |= ELF_F_DIRTY;
 
  out:
-  rwlock_unlock (scn->elf->lock);
+  RWLOCK_UNLOCK (scn->elf->lock);
 
   return result;
 }
index 10bfb6abeaef99c2851583fefd5a0781ee9e9524..fce00bb9d474a2969e585c9bb30423501b380c79 100644 (file)
@@ -85,7 +85,7 @@ gelf_update_dyn (data, ndx, src)
     }
 
   scn = data_scn->s;
-  rwlock_wrlock (scn->elf->lock);
+  RWLOCK_WRLOCK (scn->elf->lock);
 
   if (scn->elf->class == ELFCLASS32)
     {
@@ -131,7 +131,7 @@ gelf_update_dyn (data, ndx, src)
   scn->flags |= ELF_F_DIRTY;
 
  out:
-  rwlock_unlock (scn->elf->lock);
+  RWLOCK_UNLOCK (scn->elf->lock);
 
   return result;
 }
index 4d5c2b6cb3c82e7816fdb69e7056010c7a0b8983..2da292c381a1e584b4a6d28de80947cce78d32ba 100644 (file)
@@ -72,7 +72,7 @@ gelf_update_ehdr (Elf *elf, GElf_Ehdr *src)
       return 0;
     }
 
-  rwlock_wrlock (elf->lock);
+  RWLOCK_WRLOCK (elf->lock);
 
   if (elf->class == ELFCLASS32)
     {
@@ -130,7 +130,7 @@ gelf_update_ehdr (Elf *elf, GElf_Ehdr *src)
   result = 1;
 
  out:
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index 9571016fbb95e13180b82c3ae901270de085138d..46409f3345a2a448221b4ee5d43ddaf20c66a8ef 100644 (file)
@@ -83,7 +83,7 @@ gelf_update_lib (data, ndx, src)
     }
 
   Elf_Scn *scn = data_scn->s;
-  rwlock_wrlock (scn->elf->lock);
+  RWLOCK_WRLOCK (scn->elf->lock);
 
   /* Check whether we have to resize the data buffer.  */
   int result = 0;
@@ -99,7 +99,7 @@ gelf_update_lib (data, ndx, src)
       scn->flags |= ELF_F_DIRTY;
     }
 
-  rwlock_unlock (scn->elf->lock);
+  RWLOCK_UNLOCK (scn->elf->lock);
 
   return result;
 }
index fd67be10f1c5d7696c08e7649dc1949c8ca639d6..11bc8342d1ee447371e385915925ac5f4128d84d 100644 (file)
@@ -89,14 +89,14 @@ gelf_update_move (data, ndx, src)
       return 0;
     }
 
-  rwlock_wrlock (data_scn->s->elf->lock);
+  RWLOCK_WRLOCK (data_scn->s->elf->lock);
 
   ((GElf_Move *) data_scn->d.d_buf)[ndx] = *src;
 
   /* Mark the section as modified.  */
   data_scn->s->flags |= ELF_F_DIRTY;
 
-  rwlock_unlock (data_scn->s->elf->lock);
+  RWLOCK_UNLOCK (data_scn->s->elf->lock);
 
   return 1;
 }
index 70bf0a5ea91c79d4d8ee05171a82a73d8a204b27..3305acbec3cf44ff724baf43c528f85c371754d8 100644 (file)
@@ -72,7 +72,7 @@ gelf_update_phdr (Elf *elf, int ndx, GElf_Phdr *src)
       return 0;
     }
 
-  rwlock_wrlock (elf->lock);
+  RWLOCK_WRLOCK (elf->lock);
 
   if (elf->class == ELFCLASS32)
     {
@@ -94,7 +94,7 @@ gelf_update_phdr (Elf *elf, int ndx, GElf_Phdr *src)
 
       if (phdr == NULL)
        {
-         phdr = INTUSE(elf32_getphdr) (elf);
+         phdr = __elf32_getphdr_internal (elf, LS_WRLOCKED);
          if (phdr == NULL)
            /* The error number is already set.  */
            goto out;
@@ -127,7 +127,7 @@ gelf_update_phdr (Elf *elf, int ndx, GElf_Phdr *src)
 
       if (phdr == NULL)
        {
-         phdr = INTUSE(elf64_getphdr) (elf);
+         phdr = __elf64_getphdr_internal (elf, LS_WRLOCKED);
          if (phdr == NULL)
            /* The error number is already set.  */
            goto out;
@@ -147,7 +147,7 @@ gelf_update_phdr (Elf *elf, int ndx, GElf_Phdr *src)
   result = 1;
 
  out:
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index 049b71a15bdf0629b1214f1bcfcbb5ee82875e08..b40ba27a2e55df1f9bc871b4b7e75717c7a7a328 100644 (file)
@@ -82,7 +82,7 @@ gelf_update_rel (Elf_Data *dst, int ndx, GElf_Rel *src)
     }
 
   scn = data_scn->s;
-  rwlock_wrlock (scn->elf->lock);
+  RWLOCK_WRLOCK (scn->elf->lock);
 
   if (scn->elf->class == ELFCLASS32)
     {
@@ -129,7 +129,7 @@ gelf_update_rel (Elf_Data *dst, int ndx, GElf_Rel *src)
   scn->flags |= ELF_F_DIRTY;
 
  out:
-  rwlock_unlock (scn->elf->lock);
+  RWLOCK_UNLOCK (scn->elf->lock);
 
   return result;
 }
index dc99c6810bb46e235cf8c2bf987b966afb5cc2bf..86553bdb87738534caeb3d2ffba33c41bc4c3d2b 100644 (file)
@@ -82,7 +82,7 @@ gelf_update_rela (Elf_Data *dst, int ndx, GElf_Rela *src)
     }
 
   scn = data_scn->s;
-  rwlock_wrlock (scn->elf->lock);
+  RWLOCK_WRLOCK (scn->elf->lock);
 
   if (scn->elf->class == ELFCLASS32)
     {
@@ -132,7 +132,7 @@ gelf_update_rela (Elf_Data *dst, int ndx, GElf_Rela *src)
   scn->flags |= ELF_F_DIRTY;
 
  out:
-  rwlock_unlock (scn->elf->lock);
+  RWLOCK_UNLOCK (scn->elf->lock);
 
   return result;
 }
index 50ef454ae45056879023e39aec54e63ba13d7af0..dccf6ade50004e8ed30e75631f187eda5d6cfa1d 100644 (file)
@@ -68,11 +68,12 @@ gelf_update_shdr (Elf_Scn *scn, GElf_Shdr *src)
     return 0;
 
   elf = scn->elf;
-  rwlock_wrlock (elf->lock);
+  RWLOCK_WRLOCK (elf->lock);
 
   if (elf->class == ELFCLASS32)
     {
-      Elf32_Shdr *shdr = scn->shdr.e32 ?: INTUSE(elf32_getshdr) (scn);
+      Elf32_Shdr *shdr
+       = scn->shdr.e32 ?: __elf32_getshdr_internal (scn, LS_WRLOCKED);
 
       if (shdr == NULL)
        {
@@ -106,7 +107,8 @@ gelf_update_shdr (Elf_Scn *scn, GElf_Shdr *src)
     }
   else
     {
-      Elf64_Shdr *shdr = scn->shdr.e64 ?: INTUSE(elf64_getshdr) (scn);
+      Elf64_Shdr *shdr
+       = scn->shdr.e64 ?: __elf64_getshdr_internal (scn, LS_WRLOCKED);
 
       if (shdr == NULL)
        {
@@ -121,7 +123,7 @@ gelf_update_shdr (Elf_Scn *scn, GElf_Shdr *src)
   result = 1;
 
  out:
-  rwlock_unlock (elf->lock);
+  RWLOCK_UNLOCK (elf->lock);
 
   return result;
 }
index fff45fdb9024450a3dc95f3bf98cabd4fa2fe225..d484e03af38b75a2fccb51f06e0d574416d428d3 100644 (file)
@@ -86,7 +86,7 @@ gelf_update_sym (data, ndx, src)
     }
 
   scn = data_scn->s;
-  rwlock_wrlock (scn->elf->lock);
+  RWLOCK_WRLOCK (scn->elf->lock);
 
   if (scn->elf->class == ELFCLASS32)
     {
@@ -140,7 +140,7 @@ gelf_update_sym (data, ndx, src)
   scn->flags |= ELF_F_DIRTY;
 
  out:
-  rwlock_unlock (scn->elf->lock);
+  RWLOCK_UNLOCK (scn->elf->lock);
 
   return result;
 }
index a0e176dc9d5633e57f1e727ace50a8c10a1b6222..83e92ceeda4cbb575f657ba61627805a2db4e105 100644 (file)
@@ -90,7 +90,7 @@ gelf_update_syminfo (data, ndx, src)
   assert (sizeof (GElf_Syminfo) == sizeof (Elf64_Syminfo));
 
   scn = data_scn->s;
-  rwlock_wrlock (scn->elf->lock);
+  RWLOCK_WRLOCK (scn->elf->lock);
 
   /* Check whether we have to resize the data buffer.  */
   if (unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data_scn->d.d_size))
@@ -107,7 +107,7 @@ gelf_update_syminfo (data, ndx, src)
   scn->flags |= ELF_F_DIRTY;
 
  out:
-  rwlock_unlock (scn->elf->lock);
+  RWLOCK_UNLOCK (scn->elf->lock);
 
   return result;
 }
index 2d393c1fa0cb836dab5fc87b7047c50da1880143..5931b6bc58545f81c05069cdbd19aeb847f496fb 100644 (file)
@@ -93,7 +93,7 @@ gelf_update_symshndx (symdata, shndxdata, ndx, src, srcshndx)
   scn = symdata_scn->s;
   /* We simply have to believe the user that the two sections belong to
      the same ELF file.  */
-  rwlock_wrlock (scn->elf->lock);
+  RWLOCK_WRLOCK (scn->elf->lock);
 
   /* The user is not required to pass a data descriptor for an extended
      section index table.  */
@@ -170,7 +170,7 @@ gelf_update_symshndx (symdata, shndxdata, ndx, src, srcshndx)
   scn->flags |= ELF_F_DIRTY;
 
  out:
-  rwlock_unlock (scn->elf->lock);
+  RWLOCK_UNLOCK (scn->elf->lock);
 
   return result;
 }
index 17866efc8b0779e32446e4d7c7b235eef128b4c3..f1875c2d22cfa0999d048e7a2d21fcf411bdfdea 100644 (file)
@@ -89,14 +89,14 @@ gelf_update_verdaux (data, offset, src)
       return 0;
     }
 
-  rwlock_wrlock (data_scn->s->elf->lock);
+  RWLOCK_WRLOCK (data_scn->s->elf->lock);
 
   memcpy ((char *) data_scn->d.d_buf + offset, src, sizeof (GElf_Verdaux));
 
   /* Mark the section as modified.  */
   data_scn->s->flags |= ELF_F_DIRTY;
 
-  rwlock_unlock (data_scn->s->elf->lock);
+  RWLOCK_UNLOCK (data_scn->s->elf->lock);
 
   return 1;
 }
index cd19cb753089a807ca26adc0fcdd35ce32a3f2dc..94c805b0e054f0a540563b7e69f538b4c69f435c 100644 (file)
@@ -89,14 +89,14 @@ gelf_update_verdef (data, offset, src)
       return 0;
     }
 
-  rwlock_wrlock (data_scn->s->elf->lock);
+  RWLOCK_WRLOCK (data_scn->s->elf->lock);
 
   memcpy ((char *) data_scn->d.d_buf + offset, src, sizeof (GElf_Verdef));
 
   /* Mark the section as modified.  */
   data_scn->s->flags |= ELF_F_DIRTY;
 
-  rwlock_unlock (data_scn->s->elf->lock);
+  RWLOCK_UNLOCK (data_scn->s->elf->lock);
 
   return 1;
 }
index 2be69e1e483e5ab2dd5ee3be1410ac1a8141a332..c7a341a70fa2afdff2995dcd9a6ded78253f7cc9 100644 (file)
@@ -89,14 +89,14 @@ gelf_update_vernaux (data, offset, src)
       return 0;
     }
 
-  rwlock_wrlock (data_scn->s->elf->lock);
+  RWLOCK_WRLOCK (data_scn->s->elf->lock);
 
   memcpy ((char *) data_scn->d.d_buf + offset, src, sizeof (GElf_Vernaux));
 
   /* Mark the section as modified.  */
   data_scn->s->flags |= ELF_F_DIRTY;
 
-  rwlock_unlock (data_scn->s->elf->lock);
+  RWLOCK_UNLOCK (data_scn->s->elf->lock);
 
   return 1;
 }
index 95f2d18f4c0651796b1639b75b0dd97a189a385e..ae23fdb41d3b80540ffde642d303f26f095c2244 100644 (file)
@@ -89,14 +89,14 @@ gelf_update_verneed (data, offset, src)
       return 0;
     }
 
-  rwlock_wrlock (data_scn->s->elf->lock);
+  RWLOCK_WRLOCK (data_scn->s->elf->lock);
 
   memcpy ((char *) data_scn->d.d_buf + offset, src, sizeof (GElf_Verneed));
 
   /* Mark the section as modified.  */
   data_scn->s->flags |= ELF_F_DIRTY;
 
-  rwlock_unlock (data_scn->s->elf->lock);
+  RWLOCK_UNLOCK (data_scn->s->elf->lock);
 
   return 1;
 }
index 905c8f7820821faa306899ced6e6f3b2d67d71cc..c2ec6e9f211d1a5615c7d37ac8d7ba626ff3c022 100644 (file)
@@ -89,14 +89,14 @@ gelf_update_versym (data, ndx, src)
       return 0;
     }
 
-  rwlock_wrlock (data_scn->s->elf->lock);
+  RWLOCK_WRLOCK (data_scn->s->elf->lock);
 
   ((GElf_Versym *) data_scn->d.d_buf)[ndx] = *src;
 
   /* Mark the section as modified.  */
   data_scn->s->flags |= ELF_F_DIRTY;
 
-  rwlock_unlock (data_scn->s->elf->lock);
+  RWLOCK_UNLOCK (data_scn->s->elf->lock);
 
   return 1;
 }
index 5e3d57cb17b0fe9535053c13ad8afc14c23783f2..7dfd8dd3ec3cd9940d10e149f78812116a3266f4 100644 (file)
 #ifndef _LIBELFP_H
 #define _LIBELFP_H 1
 
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
 #include <ar.h>
 #include <gelf.h>
+
+#include <errno.h>
 #include <stdint.h>
+#include <stdio.h>
+#include <string.h>
 
 /* gettext helper macros.  */
 #define _(Str) dgettext ("libelf", Str)
@@ -410,6 +418,15 @@ struct Elf
   /* There absolutely never must be anything following the union.  */
 };
 
+/* For _locked calls.  This gives the callee insight into how is the
+   object locked.  Some functions, e.g. elf32_getshdr, are called from
+   both callers of both rwlock_wrlock and rwlock_rdlock. */
+typedef enum
+{
+  LS_UNLOCKED = 0,
+  LS_RDLOCKED,
+  LS_WRLOCKED
+} lockstat_t;
 
 /* Type of the conversion functions.  These functions will convert the
    byte order.  */
@@ -488,13 +505,16 @@ extern char *__libelf_readall (Elf *elf) internal_function;
 extern int __libelf_readsections (Elf *elf) internal_function;
 
 /* Store the information for the raw data in the `rawdata_list' element.  */
-extern int __libelf_set_rawdata (Elf_Scn *scn) internal_function;
+extern int __libelf_set_rawdata (Elf_Scn *scn, lockstat_t locked)
+  internal_function;
 
 
 /* Helper functions for elf_update.  */
-extern off_t __elf32_updatenull (Elf *elf, int *change_bop, size_t shnum)
+extern off_t __elf32_updatenull (Elf *elf, int *change_bop, size_t shnum,
+                                lockstat_t locked)
      internal_function;
-extern off_t __elf64_updatenull (Elf *elf, int *change_bop, size_t shnum)
+extern off_t __elf64_updatenull (Elf *elf, int *change_bop, size_t shnum,
+                                lockstat_t locked)
      internal_function;
 
 extern int __elf32_updatemmap (Elf *elf, int change_bo, size_t shnum)
@@ -511,12 +531,16 @@ extern int __elf64_updatefile (Elf *elf, int change_bo, size_t shnum)
 extern int __elf_end_internal (Elf *__elf);
 extern Elf *__elf_begin_internal (int __fildes, Elf_Cmd __cmd, Elf *__ref)
      attribute_hidden;
-extern Elf32_Ehdr *__elf32_getehdr_internal (Elf *__elf) attribute_hidden;
-extern Elf64_Ehdr *__elf64_getehdr_internal (Elf *__elf) attribute_hidden;
+extern Elf32_Ehdr *__elf32_getehdr_internal (Elf *__elf, lockstat_t locked)
+  attribute_hidden;
+extern Elf64_Ehdr *__elf64_getehdr_internal (Elf *__elf, lockstat_t locked)
+  attribute_hidden;
 extern Elf32_Ehdr *__elf32_newehdr_internal (Elf *__elf) attribute_hidden;
 extern Elf64_Ehdr *__elf64_newehdr_internal (Elf *__elf) attribute_hidden;
-extern Elf32_Phdr *__elf32_getphdr_internal (Elf *__elf) attribute_hidden;
-extern Elf64_Phdr *__elf64_getphdr_internal (Elf *__elf) attribute_hidden;
+extern Elf32_Phdr *__elf32_getphdr_internal (Elf *__elf, lockstat_t locked)
+     attribute_hidden;
+extern Elf64_Phdr *__elf64_getphdr_internal (Elf *__elf, lockstat_t locked)
+     attribute_hidden;
 extern Elf32_Phdr *__elf32_newphdr_internal (Elf *__elf, size_t __cnt)
      attribute_hidden;
 extern Elf64_Phdr *__elf64_newphdr_internal (Elf *__elf, size_t __cnt)
@@ -525,18 +549,22 @@ extern Elf_Scn *__elf32_offscn_internal (Elf *__elf, Elf32_Off __offset)
   attribute_hidden;
 extern Elf_Scn *__elf64_offscn_internal (Elf *__elf, Elf64_Off __offset)
   attribute_hidden;
-extern int __elf_getshnum_internal (Elf *__elf, size_t *__dst)
+extern int __elf_getshnum_internal (Elf *__elf, size_t *__dst,
+                                   lockstat_t locked)
      attribute_hidden;
 extern int __elf_getshstrndx_internal (Elf *__elf, size_t *__dst)
      attribute_hidden;
-extern Elf32_Shdr *__elf32_getshdr_internal (Elf_Scn *__scn) attribute_hidden;
-extern Elf64_Shdr *__elf64_getshdr_internal (Elf_Scn *__scn) attribute_hidden;
+extern Elf32_Shdr *__elf32_getshdr_internal (Elf_Scn *__scn, lockstat_t locked)
+     attribute_hidden;
+extern Elf64_Shdr *__elf64_getshdr_internal (Elf_Scn *__scn, lockstat_t locked)
+     attribute_hidden;
 extern Elf_Scn *__elf_getscn_internal (Elf *__elf, size_t __index)
      attribute_hidden;
 extern Elf_Scn *__elf_nextscn_internal (Elf *__elf, Elf_Scn *__scn)
      attribute_hidden;
 extern int __elf_scnshndx_internal (Elf_Scn *__scn) attribute_hidden;
-extern Elf_Data *__elf_getdata_internal (Elf_Scn *__scn, Elf_Data *__data)
+extern Elf_Data *__elf_getdata_internal (Elf_Scn *__scn, Elf_Data *__data,
+                                        lockstat_t locked)
      attribute_hidden;
 extern Elf_Data *__elf_rawdata_internal (Elf_Scn *__scn, Elf_Data *__data)
      attribute_hidden;
@@ -566,7 +594,9 @@ extern long int __elf32_checksum_internal (Elf *__elf) attribute_hidden;
 extern long int __elf64_checksum_internal (Elf *__elf) attribute_hidden;
 
 
-extern GElf_Ehdr *__gelf_getehdr_internal (Elf *__elf, GElf_Ehdr *__dest);
+extern GElf_Ehdr *__gelf_getehdr_internal (Elf *__elf, GElf_Ehdr *__dest,
+                                          lockstat_t locked)
+     attribute_hidden;
 extern size_t __gelf_fsize_internal (Elf *__elf, Elf_Type __type,
                                     size_t __count, unsigned int __version)
      attribute_hidden;
@@ -596,4 +626,34 @@ extern uint32_t __libelf_crc32 (uint32_t crc, unsigned char *buf, size_t len)
 /* Align offset to 4 bytes as needed for note name and descriptor data.  */
 #define NOTE_ALIGN(n)  (((n) + 3) & -4U)
 
+#ifdef NDEBUG
+# define LIBELF_CHECKED_LOCK(V, S) ((void)(V))
+#else
+/* Checked locking primitives.  Prints out an error to stderr if the
+   locking or unlocking function returns an error code.  A development
+   aid similar to assert, the user is not supposed to ever see any of
+   these.  */
+# if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
+#  error The XSI-compliant version of strerror_r() is provided, but in following, \
+  the GNU version is assumed.  Please rewrite.
+# endif
+
+# define LIBELF_CHECKED_LOCK(V, S)                             \
+  do {                                                         \
+    int err = (V);                                             \
+    if (err != 0)                                              \
+      {                                                                \
+       char __buf[128];                                        \
+       char *__ptr = strerror_r (err, __buf, sizeof __buf);    \
+       fprintf (stderr, "%s:%d: %s: %s\n",                     \
+                __FILE__, __LINE__, (S), __ptr);               \
+      }                                                                \
+  } while (0)
+
+#endif
+
+#define RWLOCK_RDLOCK(LOCK) LIBELF_CHECKED_LOCK (rwlock_rdlock (LOCK), "rwlock_rdlock")
+#define RWLOCK_WRLOCK(LOCK) LIBELF_CHECKED_LOCK (rwlock_wrlock (LOCK), "rwlock_wrlock")
+#define RWLOCK_UNLOCK(LOCK) LIBELF_CHECKED_LOCK (rwlock_unlock (LOCK), "rwlock_unlock")
+
 #endif  /* libelfP.h */
index f1fe17630a588cca03f18808b5aa51560544fe43..de18b8f59631d745418332ad753310900c4e6724 100644 (file)
@@ -141,7 +141,7 @@ nlist (const char *filename, struct nlist *nl)
   /* SHDR->SH_LINK now contains the index of the string section.  */
 
   /* Get the data for the symbol section.  */
-  data = INTUSE(elf_getdata) (symscn, NULL);
+  data = __elf_getdata_internal (symscn, NULL, LS_UNLOCKED);
   if (data == NULL)
     goto fail_close;