summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2008-08-16 03:09:13 +0000
committerUlrich Drepper <drepper@redhat.com>2008-08-16 03:09:13 +0000
commitd56e232fb8f8cd97a336ed612c89145ec121f785 (patch)
tree5bd8fe5f1f73bb258eecd2cd4dae5c30a33a016e
parent1d8bb25cac06b5af57f8733e5ea7a068a79edfe0 (diff)
propagate from branch 'com.redhat.elfutils.pmachata.threads' (head 8bd3bc10eb015c96f7bafcc6a22c973620b57dd8)
to branch 'com.redhat.elfutils' (head c5a11b6b3329382f1b5ffd0020f0d93c64176f20)
-rw-r--r--configure.ac21
-rw-r--r--libasm/Makefile.am7
-rw-r--r--libdwfl/ChangeLog6
-rw-r--r--libelf/ChangeLog82
-rw-r--r--libelf/Makefile.am7
-rw-r--r--libelf/common.h31
-rw-r--r--libelf/elf32_checksum.c2
-rw-r--r--libelf/elf32_getehdr.c20
-rw-r--r--libelf/elf32_getphdr.c19
-rw-r--r--libelf/elf32_getshdr.c18
-rw-r--r--libelf/elf32_newehdr.c4
-rw-r--r--libelf/elf32_newphdr.c4
-rw-r--r--libelf/elf32_offscn.c4
-rw-r--r--libelf/elf32_updatenull.c16
-rw-r--r--libelf/elf_begin.c4
-rw-r--r--libelf/elf_clone.c4
-rw-r--r--libelf/elf_cntl.c4
-rw-r--r--libelf/elf_end.c12
-rw-r--r--libelf/elf_getarsym.c4
-rw-r--r--libelf/elf_getdata.c43
-rw-r--r--libelf/elf_getscn.c4
-rw-r--r--libelf/elf_getshnum.c21
-rw-r--r--libelf/elf_getshstrndx.c4
-rw-r--r--libelf/elf_newdata.c4
-rw-r--r--libelf/elf_newscn.c4
-rw-r--r--libelf/elf_nextscn.c4
-rw-r--r--libelf/elf_rawdata.c2
-rw-r--r--libelf/elf_readall.c6
-rw-r--r--libelf/elf_strptr.c6
-rw-r--r--libelf/elf_update.c8
-rw-r--r--libelf/gelf_getauxv.c4
-rw-r--r--libelf/gelf_getdyn.c4
-rw-r--r--libelf/gelf_getehdr.c21
-rw-r--r--libelf/gelf_getlib.c4
-rw-r--r--libelf/gelf_getmove.c4
-rw-r--r--libelf/gelf_getnote.c4
-rw-r--r--libelf/gelf_getphdr.c8
-rw-r--r--libelf/gelf_getrel.c4
-rw-r--r--libelf/gelf_getrela.c4
-rw-r--r--libelf/gelf_getshdr.c10
-rw-r--r--libelf/gelf_getsym.c4
-rw-r--r--libelf/gelf_getsyminfo.c4
-rw-r--r--libelf/gelf_getsymshndx.c4
-rw-r--r--libelf/gelf_getverdaux.c4
-rw-r--r--libelf/gelf_getverdef.c4
-rw-r--r--libelf/gelf_getvernaux.c4
-rw-r--r--libelf/gelf_getverneed.c4
-rw-r--r--libelf/gelf_getversym.c4
-rw-r--r--libelf/gelf_update_auxv.c4
-rw-r--r--libelf/gelf_update_dyn.c4
-rw-r--r--libelf/gelf_update_ehdr.c4
-rw-r--r--libelf/gelf_update_lib.c4
-rw-r--r--libelf/gelf_update_move.c4
-rw-r--r--libelf/gelf_update_phdr.c8
-rw-r--r--libelf/gelf_update_rel.c4
-rw-r--r--libelf/gelf_update_rela.c4
-rw-r--r--libelf/gelf_update_shdr.c10
-rw-r--r--libelf/gelf_update_sym.c4
-rw-r--r--libelf/gelf_update_syminfo.c4
-rw-r--r--libelf/gelf_update_symshndx.c4
-rw-r--r--libelf/gelf_update_verdaux.c4
-rw-r--r--libelf/gelf_update_verdef.c4
-rw-r--r--libelf/gelf_update_vernaux.c4
-rw-r--r--libelf/gelf_update_verneed.c4
-rw-r--r--libelf/gelf_update_versym.c4
-rw-r--r--libelf/libelfP.h84
-rw-r--r--libelf/nlist.c2
67 files changed, 459 insertions, 179 deletions
diff --git a/configure.ac b/configure.ac
index c883b8df..4008efda 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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
diff --git a/libasm/Makefile.am b/libasm/Makefile.am
index bd5779e8..2b39eaef 100644
--- a/libasm/Makefile.am
+++ b/libasm/Makefile.am
@@ -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)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 28c6ee3c..231f8af4 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -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>.
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 8e07b9de..193cb033 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -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.
diff --git a/libelf/Makefile.am b/libelf/Makefile.am
index 5bbb4220..2458ecbd 100644
--- a/libelf/Makefile.am
+++ b/libelf/Makefile.am
@@ -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)
diff --git a/libelf/common.h b/libelf/common.h
index 757188c1..c00bfbc5 100644
--- a/libelf/common.h
+++ b/libelf/common.h
@@ -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);
}
diff --git a/libelf/elf32_checksum.c b/libelf/elf32_checksum.c
index 0e4ab9f7..ddc978dc 100644
--- a/libelf/elf32_checksum.c
+++ b/libelf/elf32_checksum.c
@@ -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
diff --git a/libelf/elf32_getehdr.c b/libelf/elf32_getehdr.c
index bdb2cc41..e5c218a7 100644
--- a/libelf/elf32_getehdr.c
+++ b/libelf/elf32_getehdr.c
@@ -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);
+}
diff --git a/libelf/elf32_getphdr.c b/libelf/elf32_getphdr.c
index 69087245..972132e4 100644
--- a/libelf/elf32_getphdr.c
+++ b/libelf/elf32_getphdr.c
@@ -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);
+}
diff --git a/libelf/elf32_getshdr.c b/libelf/elf32_getshdr.c
index c7f75bbb..8d658752 100644
--- a/libelf/elf32_getshdr.c
+++ b/libelf/elf32_getshdr.c
@@ -66,9 +66,11 @@
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);
+}
diff --git a/libelf/elf32_newehdr.c b/libelf/elf32_newehdr.c
index 4e20056f..0ef68c5d 100644
--- a/libelf/elf32_newehdr.c
+++ b/libelf/elf32_newehdr.c
@@ -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;
}
diff --git a/libelf/elf32_newphdr.c b/libelf/elf32_newphdr.c
index d1b16088..bc937852 100644
--- a/libelf/elf32_newphdr.c
+++ b/libelf/elf32_newphdr.c
@@ -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;
}
diff --git a/libelf/elf32_offscn.c b/libelf/elf32_offscn.c
index 86eff8b1..2f9e1ced 100644
--- a/libelf/elf32_offscn.c
+++ b/libelf/elf32_offscn.c
@@ -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;
}
diff --git a/libelf/elf32_updatenull.c b/libelf/elf32_updatenull.c
index b3299fe4..dd50fb29 100644
--- a/libelf/elf32_updatenull.c
+++ b/libelf/elf32_updatenull.c
@@ -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;
}
diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
index b95b06bf..1ce8c6a2 100644
--- a/libelf/elf_begin.c
+++ b/libelf/elf_begin.c
@@ -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;
}
diff --git a/libelf/elf_clone.c b/libelf/elf_clone.c
index 8b699fa6..3ace80d6 100644
--- a/libelf/elf_clone.c
+++ b/libelf/elf_clone.c
@@ -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;
}
diff --git a/libelf/elf_cntl.c b/libelf/elf_cntl.c
index fd5b47b9..6c4fec3b 100644
--- a/libelf/elf_cntl.c
+++ b/libelf/elf_cntl.c
@@ -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;
}
diff --git a/libelf/elf_end.c b/libelf/elf_end.c
index 5112eaea..1329ea16 100644
--- a/libelf/elf_end.c
+++ b/libelf/elf_end.c
@@ -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. */
diff --git a/libelf/elf_getarsym.c b/libelf/elf_getarsym.c
index e6ecaadc..59598057 100644
--- a/libelf/elf_getarsym.c
+++ b/libelf/elf_getarsym.c
@@ -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)
diff --git a/libelf/elf_getdata.c b/libelf/elf_getdata.c
index ae5b41df..dc10a689 100644
--- a/libelf/elf_getdata.c
+++ b/libelf/elf_getdata.c
@@ -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);
+}
diff --git a/libelf/elf_getscn.c b/libelf/elf_getscn.c
index 5c14a580..5bcceb63 100644
--- a/libelf/elf_getscn.c
+++ b/libelf/elf_getscn.c
@@ -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;
}
diff --git a/libelf/elf_getshnum.c b/libelf/elf_getshnum.c
index bf26a9b0..10402d83 100644
--- a/libelf/elf_getshnum.c
+++ b/libelf/elf_getshnum.c
@@ -60,9 +60,10 @@
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);
+}
diff --git a/libelf/elf_getshstrndx.c b/libelf/elf_getshstrndx.c
index 52516a8e..9d0d27b8 100644
--- a/libelf/elf_getshstrndx.c
+++ b/libelf/elf_getshstrndx.c
@@ -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;
}
diff --git a/libelf/elf_newdata.c b/libelf/elf_newdata.c
index db17ea58..1f42204d 100644
--- a/libelf/elf_newdata.c
+++ b/libelf/elf_newdata.c
@@ -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. */
diff --git a/libelf/elf_newscn.c b/libelf/elf_newscn.c
index aefab334..da4ca723 100644
--- a/libelf/elf_newscn.c
+++ b/libelf/elf_newscn.c
@@ -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;
}
diff --git a/libelf/elf_nextscn.c b/libelf/elf_nextscn.c
index a1842bb3..0a21c76f 100644
--- a/libelf/elf_nextscn.c
+++ b/libelf/elf_nextscn.c
@@ -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;
}
diff --git a/libelf/elf_rawdata.c b/libelf/elf_rawdata.c
index b8bb0f4b..b8be27c7 100644
--- a/libelf/elf_rawdata.c
+++ b/libelf/elf_rawdata.c
@@ -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;
}
diff --git a/libelf/elf_readall.c b/libelf/elf_readall.c
index 8f171b21..71daea4b 100644
--- a/libelf/elf_readall.c
+++ b/libelf/elf_readall.c
@@ -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;
}
diff --git a/libelf/elf_strptr.c b/libelf/elf_strptr.c
index c1ea60de..6fb0c50c 100644
--- a/libelf/elf_strptr.c
+++ b/libelf/elf_strptr.c
@@ -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;
}
diff --git a/libelf/elf_update.c b/libelf/elf_update.c
index 24e813fb..8d605e05 100644
--- a/libelf/elf_update.c
+++ b/libelf/elf_update.c
@@ -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;
}
diff --git a/libelf/gelf_getauxv.c b/libelf/gelf_getauxv.c
index 036bdccf..450e81b1 100644
--- a/libelf/gelf_getauxv.c
+++ b/libelf/gelf_getauxv.c
@@ -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;
}
diff --git a/libelf/gelf_getdyn.c b/libelf/gelf_getdyn.c
index 82f8e328..c032e5b2 100644
--- a/libelf/gelf_getdyn.c
+++ b/libelf/gelf_getdyn.c
@@ -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;
}
diff --git a/libelf/gelf_getehdr.c b/libelf/gelf_getehdr.c
index f56d65a9..ddc77072 100644
--- a/libelf/gelf_getehdr.c
+++ b/libelf/gelf_getehdr.c
@@ -61,9 +61,10 @@
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);
+}
diff --git a/libelf/gelf_getlib.c b/libelf/gelf_getlib.c
index aa91a73b..75a4a4ad 100644
--- a/libelf/gelf_getlib.c
+++ b/libelf/gelf_getlib.c
@@ -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;
}
diff --git a/libelf/gelf_getmove.c b/libelf/gelf_getmove.c
index 6e769484..728c54eb 100644
--- a/libelf/gelf_getmove.c
+++ b/libelf/gelf_getmove.c
@@ -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;
diff --git a/libelf/gelf_getnote.c b/libelf/gelf_getnote.c
index e4900185..6867aeb4 100644
--- a/libelf/gelf_getnote.c
+++ b/libelf/gelf_getnote.c
@@ -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;
}
diff --git a/libelf/gelf_getphdr.c b/libelf/gelf_getphdr.c
index da83ccf7..286b253e 100644
--- a/libelf/gelf_getphdr.c
+++ b/libelf/gelf_getphdr.c
@@ -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;
}
diff --git a/libelf/gelf_getrel.c b/libelf/gelf_getrel.c
index f3775bd9..74a5595a 100644
--- a/libelf/gelf_getrel.c
+++ b/libelf/gelf_getrel.c
@@ -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;
}
diff --git a/libelf/gelf_getrela.c b/libelf/gelf_getrela.c
index 0275c375..f62bd286 100644
--- a/libelf/gelf_getrela.c
+++ b/libelf/gelf_getrela.c
@@ -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;
}
diff --git a/libelf/gelf_getshdr.c b/libelf/gelf_getshdr.c
index 7f01a8fc..f5457a7a 100644
--- a/libelf/gelf_getshdr.c
+++ b/libelf/gelf_getshdr.c
@@ -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;
}
diff --git a/libelf/gelf_getsym.c b/libelf/gelf_getsym.c
index 162061f7..4f2a2bec 100644
--- a/libelf/gelf_getsym.c
+++ b/libelf/gelf_getsym.c
@@ -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;
}
diff --git a/libelf/gelf_getsyminfo.c b/libelf/gelf_getsyminfo.c
index 2c07526a..c5a312c4 100644
--- a/libelf/gelf_getsyminfo.c
+++ b/libelf/gelf_getsyminfo.c
@@ -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;
}
diff --git a/libelf/gelf_getsymshndx.c b/libelf/gelf_getsymshndx.c
index a9cfc181..7fa09680 100644
--- a/libelf/gelf_getsymshndx.c
+++ b/libelf/gelf_getsymshndx.c
@@ -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;
}
diff --git a/libelf/gelf_getverdaux.c b/libelf/gelf_getverdaux.c
index b8bcf14e..df796a8a 100644
--- a/libelf/gelf_getverdaux.c
+++ b/libelf/gelf_getverdaux.c
@@ -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;
}
diff --git a/libelf/gelf_getverdef.c b/libelf/gelf_getverdef.c
index 05cc2e89..babfa993 100644
--- a/libelf/gelf_getverdef.c
+++ b/libelf/gelf_getverdef.c
@@ -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;
}
diff --git a/libelf/gelf_getvernaux.c b/libelf/gelf_getvernaux.c
index 45d3300f..070e97ec 100644
--- a/libelf/gelf_getvernaux.c
+++ b/libelf/gelf_getvernaux.c
@@ -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;
}
diff --git a/libelf/gelf_getverneed.c b/libelf/gelf_getverneed.c
index e82a055d..3e2f1486 100644
--- a/libelf/gelf_getverneed.c
+++ b/libelf/gelf_getverneed.c
@@ -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;
}
diff --git a/libelf/gelf_getversym.c b/libelf/gelf_getversym.c
index 397b7edb..011a54af 100644
--- a/libelf/gelf_getversym.c
+++ b/libelf/gelf_getversym.c
@@ -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;
}
diff --git a/libelf/gelf_update_auxv.c b/libelf/gelf_update_auxv.c
index b294ead7..dbcde82d 100644
--- a/libelf/gelf_update_auxv.c
+++ b/libelf/gelf_update_auxv.c
@@ -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;
}
diff --git a/libelf/gelf_update_dyn.c b/libelf/gelf_update_dyn.c
index 10bfb6ab..fce00bb9 100644
--- a/libelf/gelf_update_dyn.c
+++ b/libelf/gelf_update_dyn.c
@@ -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;
}
diff --git a/libelf/gelf_update_ehdr.c b/libelf/gelf_update_ehdr.c
index 4d5c2b6c..2da292c3 100644
--- a/libelf/gelf_update_ehdr.c
+++ b/libelf/gelf_update_ehdr.c
@@ -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;
}
diff --git a/libelf/gelf_update_lib.c b/libelf/gelf_update_lib.c
index 9571016f..46409f33 100644
--- a/libelf/gelf_update_lib.c
+++ b/libelf/gelf_update_lib.c
@@ -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;
}
diff --git a/libelf/gelf_update_move.c b/libelf/gelf_update_move.c
index fd67be10..11bc8342 100644
--- a/libelf/gelf_update_move.c
+++ b/libelf/gelf_update_move.c
@@ -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;
}
diff --git a/libelf/gelf_update_phdr.c b/libelf/gelf_update_phdr.c
index 70bf0a5e..3305acbe 100644
--- a/libelf/gelf_update_phdr.c
+++ b/libelf/gelf_update_phdr.c
@@ -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;
}
diff --git a/libelf/gelf_update_rel.c b/libelf/gelf_update_rel.c
index 049b71a1..b40ba27a 100644
--- a/libelf/gelf_update_rel.c
+++ b/libelf/gelf_update_rel.c
@@ -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;
}
diff --git a/libelf/gelf_update_rela.c b/libelf/gelf_update_rela.c
index dc99c681..86553bdb 100644
--- a/libelf/gelf_update_rela.c
+++ b/libelf/gelf_update_rela.c
@@ -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;
}
diff --git a/libelf/gelf_update_shdr.c b/libelf/gelf_update_shdr.c
index 50ef454a..dccf6ade 100644
--- a/libelf/gelf_update_shdr.c
+++ b/libelf/gelf_update_shdr.c
@@ -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;
}
diff --git a/libelf/gelf_update_sym.c b/libelf/gelf_update_sym.c
index fff45fdb..d484e03a 100644
--- a/libelf/gelf_update_sym.c
+++ b/libelf/gelf_update_sym.c
@@ -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;
}
diff --git a/libelf/gelf_update_syminfo.c b/libelf/gelf_update_syminfo.c
index a0e176dc..83e92cee 100644
--- a/libelf/gelf_update_syminfo.c
+++ b/libelf/gelf_update_syminfo.c
@@ -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;
}
diff --git a/libelf/gelf_update_symshndx.c b/libelf/gelf_update_symshndx.c
index 2d393c1f..5931b6bc 100644
--- a/libelf/gelf_update_symshndx.c
+++ b/libelf/gelf_update_symshndx.c
@@ -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;
}
diff --git a/libelf/gelf_update_verdaux.c b/libelf/gelf_update_verdaux.c
index 17866efc..f1875c2d 100644
--- a/libelf/gelf_update_verdaux.c
+++ b/libelf/gelf_update_verdaux.c
@@ -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;
}
diff --git a/libelf/gelf_update_verdef.c b/libelf/gelf_update_verdef.c
index cd19cb75..94c805b0 100644
--- a/libelf/gelf_update_verdef.c
+++ b/libelf/gelf_update_verdef.c
@@ -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;
}
diff --git a/libelf/gelf_update_vernaux.c b/libelf/gelf_update_vernaux.c
index 2be69e1e..c7a341a7 100644
--- a/libelf/gelf_update_vernaux.c
+++ b/libelf/gelf_update_vernaux.c
@@ -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;
}
diff --git a/libelf/gelf_update_verneed.c b/libelf/gelf_update_verneed.c
index 95f2d18f..ae23fdb4 100644
--- a/libelf/gelf_update_verneed.c
+++ b/libelf/gelf_update_verneed.c
@@ -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;
}
diff --git a/libelf/gelf_update_versym.c b/libelf/gelf_update_versym.c
index 905c8f78..c2ec6e9f 100644
--- a/libelf/gelf_update_versym.c
+++ b/libelf/gelf_update_versym.c
@@ -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;
}
diff --git a/libelf/libelfP.h b/libelf/libelfP.h
index 5e3d57cb..7dfd8dd3 100644
--- a/libelf/libelfP.h
+++ b/libelf/libelfP.h
@@ -51,9 +51,17 @@
#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 */
diff --git a/libelf/nlist.c b/libelf/nlist.c
index f1fe1763..de18b8f5 100644
--- a/libelf/nlist.c
+++ b/libelf/nlist.c
@@ -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;