From patchwork Tue Oct 10 13:42:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 77416 X-Patchwork-Delegate: amerey@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C749386191E for ; Tue, 10 Oct 2023 13:44:18 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id C5BE53857713 for ; Tue, 10 Oct 2023 13:43:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5BE53857713 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from r6.localdomain (82-217-174-174.cable.dynamic.v4.ziggo.nl [82.217.174.174]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 85091301FE8B; Tue, 10 Oct 2023 15:43:35 +0200 (CEST) Received: by r6.localdomain (Postfix, from userid 1000) id 3DDCF340402; Tue, 10 Oct 2023 15:43:34 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: hsm2@rice.edu, Mark Wielaard Subject: [PATCH 14/16] libdw,libdwfl: Use eu-search for thread-safety Date: Tue, 10 Oct 2023 15:42:58 +0200 Message-ID: <20231010134300.53830-14-mark@klomp.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231010134300.53830-1-mark@klomp.org> References: <301fac87e83ebbbd677750579ae9a3429b461bdf.camel@klomp.org> <20231010134300.53830-1-mark@klomp.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3033.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org From: Heather McIntyre * libdw/cie.c: Add eu-search.h and remove search.h. Change calls of tsearch/tfind to eu_tsearch/eu_tfind. * libdw/dwarf_getlocation.c: Likewise. * libdw/dwarf_getmacros.c: Likewise. * libdw/dwarf_getsrclines.c: Likewise. * libdw/fde.c: Likewise. * libdwfl/cu.c: Likewise. Signed-off-by: Heather S. McIntyre Signed-off-by: Mark Wielaard --- libdw/cie.c | 8 ++++---- libdw/dwarf_getlocation.c | 16 ++++++++-------- libdw/dwarf_getmacros.c | 6 +++--- libdw/dwarf_getsrclines.c | 6 +++--- libdw/fde.c | 6 +++--- libdwfl/cu.c | 4 ++-- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/libdw/cie.c b/libdw/cie.c index 1b0aae7c..758daef5 100644 --- a/libdw/cie.c +++ b/libdw/cie.c @@ -33,7 +33,7 @@ #include "cfi.h" #include "encoded-value.h" #include -#include +#include #include @@ -144,7 +144,7 @@ intern_new_cie (Dwarf_CFI *cache, Dwarf_Off offset, const Dwarf_CIE *info) cie->initial_state = NULL; /* Add the new entry to the search tree. */ - if (tsearch (cie, &cache->cie_tree, &compare_cie) == NULL) + if (eu_tsearch (cie, &cache->cie_tree, &compare_cie) == NULL) { free (cie); __libdw_seterrno (DWARF_E_NOMEM); @@ -160,7 +160,7 @@ internal_function __libdw_find_cie (Dwarf_CFI *cache, Dwarf_Off offset) { const struct dwarf_cie cie_key = { .offset = offset }; - struct dwarf_cie **found = tfind (&cie_key, &cache->cie_tree, &compare_cie); + struct dwarf_cie **found = eu_tfind (&cie_key, &cache->cie_tree, &compare_cie); if (found != NULL) return *found; @@ -189,7 +189,7 @@ internal_function __libdw_intern_cie (Dwarf_CFI *cache, Dwarf_Off offset, const Dwarf_CIE *info) { const struct dwarf_cie cie_key = { .offset = offset }; - struct dwarf_cie **found = tfind (&cie_key, &cache->cie_tree, &compare_cie); + struct dwarf_cie **found = eu_tfind (&cie_key, &cache->cie_tree, &compare_cie); if (found == NULL) /* We have not read this CIE yet. Enter it. */ (void) intern_new_cie (cache, offset, info); diff --git a/libdw/dwarf_getlocation.c b/libdw/dwarf_getlocation.c index 553fdc98..e26afe37 100644 --- a/libdw/dwarf_getlocation.c +++ b/libdw/dwarf_getlocation.c @@ -31,7 +31,7 @@ #endif #include -#include +#include #include #include @@ -137,7 +137,7 @@ loc_compare (const void *p1, const void *p2) /* For each DW_OP_implicit_value, we store a special entry in the cache. This points us directly to the block data for later fetching. - Returns zero on success, -1 on bad DWARF or 1 if tsearch failed. */ + Returns zero on success, -1 on bad DWARF or 1 if eu_tsearch failed. */ static int store_implicit_value (Dwarf *dbg, void **cache, Dwarf_Op *op) { @@ -154,7 +154,7 @@ store_implicit_value (Dwarf *dbg, void **cache, Dwarf_Op *op) block->addr = op; block->data = (unsigned char *) data; block->length = op->number; - if (unlikely (tsearch (block, cache, loc_compare) == NULL)) + if (unlikely (eu_tsearch (block, cache, loc_compare) == NULL)) return 1; return 0; } @@ -167,7 +167,7 @@ dwarf_getlocation_implicit_value (Dwarf_Attribute *attr, const Dwarf_Op *op, return -1; struct loc_block_s fake = { .addr = (void *) op }; - struct loc_block_s **found = tfind (&fake, &attr->cu->locs, loc_compare); + struct loc_block_s **found = eu_tfind (&fake, &attr->cu->locs, loc_compare); if (unlikely (found == NULL)) { __libdw_seterrno (DWARF_E_NO_BLOCK); @@ -211,7 +211,7 @@ is_constant_offset (Dwarf_Attribute *attr, /* Check whether we already cached this location. */ struct loc_s fake = { .addr = attr->valp }; - struct loc_s **found = tfind (&fake, &attr->cu->locs, loc_compare); + struct loc_s **found = eu_tfind (&fake, &attr->cu->locs, loc_compare); if (found == NULL) { @@ -235,7 +235,7 @@ is_constant_offset (Dwarf_Attribute *attr, newp->loc = result; newp->nloc = 1; - found = tsearch (newp, &attr->cu->locs, loc_compare); + found = eu_tsearch (newp, &attr->cu->locs, loc_compare); } assert ((*found)->nloc == 1); @@ -266,7 +266,7 @@ __libdw_intern_expression (Dwarf *dbg, bool other_byte_order, /* Check whether we already looked at this list. */ struct loc_s fake = { .addr = block->data }; - struct loc_s **found = tfind (&fake, cache, loc_compare); + struct loc_s **found = eu_tfind (&fake, cache, loc_compare); if (found != NULL) { /* We already saw it. */ @@ -655,7 +655,7 @@ __libdw_intern_expression (Dwarf *dbg, bool other_byte_order, newp->addr = block->data; newp->loc = result; newp->nloc = *listlen; - (void) tsearch (newp, cache, loc_compare); + (void) eu_tsearch (newp, cache, loc_compare); /* We did it. */ return 0; diff --git a/libdw/dwarf_getmacros.c b/libdw/dwarf_getmacros.c index a3a78884..d150f05e 100644 --- a/libdw/dwarf_getmacros.c +++ b/libdw/dwarf_getmacros.c @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include @@ -293,7 +293,7 @@ cache_op_table (Dwarf *dbg, int sec_index, Dwarf_Off macoff, Dwarf_Die *cudie) { Dwarf_Macro_Op_Table fake = { .offset = macoff, .sec_index = sec_index }; - Dwarf_Macro_Op_Table **found = tfind (&fake, &dbg->macro_ops, + Dwarf_Macro_Op_Table **found = eu_tfind (&fake, &dbg->macro_ops, macro_op_compare); if (found != NULL) return *found; @@ -305,7 +305,7 @@ cache_op_table (Dwarf *dbg, int sec_index, Dwarf_Off macoff, if (table == NULL) return NULL; - Dwarf_Macro_Op_Table **ret = tsearch (table, &dbg->macro_ops, + Dwarf_Macro_Op_Table **ret = eu_tsearch (table, &dbg->macro_ops, macro_op_compare); if (unlikely (ret == NULL)) { diff --git a/libdw/dwarf_getsrclines.c b/libdw/dwarf_getsrclines.c index df003c5f..356284a0 100644 --- a/libdw/dwarf_getsrclines.c +++ b/libdw/dwarf_getsrclines.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include "dwarf.h" #include "libdwP.h" @@ -1138,7 +1138,7 @@ __libdw_getsrclines (Dwarf *dbg, Dwarf_Off debug_line_offset, Dwarf_Lines **linesp, Dwarf_Files **filesp) { struct files_lines_s fake = { .debug_line_offset = debug_line_offset }; - struct files_lines_s **found = tfind (&fake, &dbg->files_lines, + struct files_lines_s **found = eu_tfind (&fake, &dbg->files_lines, files_lines_compare); if (found == NULL) { @@ -1160,7 +1160,7 @@ __libdw_getsrclines (Dwarf *dbg, Dwarf_Off debug_line_offset, node->debug_line_offset = debug_line_offset; - found = tsearch (node, &dbg->files_lines, files_lines_compare); + found = eu_tsearch (node, &dbg->files_lines, files_lines_compare); if (found == NULL) { __libdw_seterrno (DWARF_E_NOMEM); diff --git a/libdw/fde.c b/libdw/fde.c index 73d551b6..55065528 100644 --- a/libdw/fde.c +++ b/libdw/fde.c @@ -31,7 +31,7 @@ #endif #include "cfi.h" -#include +#include #include #include "encoded-value.h" @@ -122,7 +122,7 @@ intern_fde (Dwarf_CFI *cache, const Dwarf_FDE *entry) fde->instructions += cie->fde_augmentation_data_size; /* Add the new entry to the search tree. */ - struct dwarf_fde **tres = tsearch (fde, &cache->fde_tree, &compare_fde); + struct dwarf_fde **tres = eu_tsearch (fde, &cache->fde_tree, &compare_fde); if (tres == NULL) { free (fde); @@ -252,7 +252,7 @@ __libdw_find_fde (Dwarf_CFI *cache, Dwarf_Addr address) /* Look for a cached FDE covering this address. */ const struct dwarf_fde fde_key = { .start = address, .end = 0 }; - struct dwarf_fde **found = tfind (&fde_key, &cache->fde_tree, &compare_fde); + struct dwarf_fde **found = eu_tfind (&fde_key, &cache->fde_tree, &compare_fde); if (found != NULL) return *found; diff --git a/libdwfl/cu.c b/libdwfl/cu.c index b1afb19a..71838011 100644 --- a/libdwfl/cu.c +++ b/libdwfl/cu.c @@ -33,7 +33,7 @@ #include "libdwflP.h" #include "libdwP.h" #include "memory-access.h" -#include +#include static inline Dwarf_Arange * @@ -198,7 +198,7 @@ intern_cu (Dwfl_Module *mod, Dwarf_Off cuoff, struct dwfl_cu **result) struct dwfl_cu key; key.die.cu = die->cu; - struct dwfl_cu **found = tsearch (&key, &mod->lazy_cu_root, &compare_cukey); + struct dwfl_cu **found = eu_tsearch (&key, &mod->lazy_cu_root, &compare_cukey); if (unlikely (found == NULL)) return DWFL_E_NOMEM;