aboutsummaryrefslogtreecommitdiff
path: root/libctf
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2019-12-13 14:48:07 +0000
committerNick Alcock <nick.alcock@oracle.com>2020-06-26 15:56:39 +0100
commit2e428e74401480c562a203ba6b6923ce8c7811fa (patch)
tree6b267631b666ead5ad4af1e8f1dfe30e961f7c8c /libctf
parent2f6ecaed667d1597c67991224948e0a3da427cc9 (diff)
downloadgdb-2e428e74401480c562a203ba6b6923ce8c7811fa.zip
gdb-2e428e74401480c562a203ba6b6923ce8c7811fa.tar.gz
gdb-2e428e74401480c562a203ba6b6923ce8c7811fa.tar.bz2
libctf: avoid nonportable __thread in CTF archive handling
This keeps archive searching threadsafe using the new bsearch_r that was just added to libiberty. PR25120 libctf/ * ctf-archive.c (search_nametbl): No longer global: declare... (ctf_arc_open_by_name_internal): ... here. Use bsearch_r. (search_modent_by_name): Take and use ARG for the nametbl.
Diffstat (limited to 'libctf')
-rw-r--r--libctf/ChangeLog7
-rw-r--r--libctf/ctf-archive.c17
2 files changed, 15 insertions, 9 deletions
diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index 5e473a7..62c2cc5 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,5 +1,12 @@
2020-06-26 Nick Alcock <nick.alcock@oracle.com>
+ PR libctf/25120
+ * ctf-archive.c (search_nametbl): No longer global: declare...
+ (ctf_arc_open_by_name_internal): ... here. Use bsearch_r.
+ (search_modent_by_name): Take and use ARG for the nametbl.
+
+2020-06-26 Nick Alcock <nick.alcock@oracle.com>
+
* ctf-impl.h (ctf_new_archive_internal): Declare.
(ctf_arc_bufopen): Remove.
(ctf_archive_internal) <ctfi_free_symsect>: New.
diff --git a/libctf/ctf-archive.c b/libctf/ctf-archive.c
index d27b27e..ac13d6d 100644
--- a/libctf/ctf-archive.c
+++ b/libctf/ctf-archive.c
@@ -44,9 +44,6 @@ static int arc_mmap_writeout (int fd, void *header, size_t headersz,
const char **errmsg);
static int arc_mmap_unmap (void *header, size_t headersz, const char **errmsg);
-/* bsearch() internal state. */
-static __thread char *search_nametbl;
-
/* Write out a CTF archive to the start of the file referenced by the passed-in
fd. The entries in CTF_FILES are referenced by name: the names are passed in
the names array, which must have CTF_FILES entries.
@@ -332,13 +329,14 @@ sort_modent_by_name (const void *one, const void *two, void *n)
&nametbl[le64toh (b->name_offset)]);
}
-/* bsearch() function to search for a given name in the sorted array of struct
+/* bsearch_r() function to search for a given name in the sorted array of struct
ctf_archive_modents. */
static int
-search_modent_by_name (const void *key, const void *ent)
+search_modent_by_name (const void *key, const void *ent, void *arg)
{
const char *k = key;
const struct ctf_archive_modent *v = ent;
+ const char *search_nametbl = arg;
return strcmp (k, &search_nametbl[le64toh (v->name_offset)]);
}
@@ -503,6 +501,7 @@ ctf_arc_open_by_name_internal (const struct ctf_archive *arc,
const char *name, int *errp)
{
struct ctf_archive_modent *modent;
+ const char *search_nametbl;
if (name == NULL)
name = _CTF_SECTION; /* The default name. */
@@ -512,10 +511,10 @@ ctf_arc_open_by_name_internal (const struct ctf_archive *arc,
modent = (ctf_archive_modent_t *) ((char *) arc
+ sizeof (struct ctf_archive));
- search_nametbl = (char *) arc + le64toh (arc->ctfa_names);
- modent = bsearch (name, modent, le64toh (arc->ctfa_nfiles),
- sizeof (struct ctf_archive_modent),
- search_modent_by_name);
+ search_nametbl = (const char *) arc + le64toh (arc->ctfa_names);
+ modent = bsearch_r (name, modent, le64toh (arc->ctfa_nfiles),
+ sizeof (struct ctf_archive_modent),
+ search_modent_by_name, (void *) search_nametbl);
/* This is actually a common case and normal operation: no error
debug output. */