From patchwork Mon Jan 20 03:20:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105069 X-Patchwork-Delegate: mark@klomp.org 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 EEA8F3858C5F for ; Mon, 20 Jan 2025 03:21:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EEA8F3858C5F Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=eXMLhBmQ X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 59BFC3858D28 for ; Mon, 20 Jan 2025 03:20:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 59BFC3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 59BFC3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343247; cv=none; b=h2Rmhqs5Of91a9j0ZqEE330h3rGj6fFq1R7ehRvvusI0Tnl2KfnaQ9ct7V8uGBmwtfDInmTnVqhXcqQHup0gD92G9mnRu4e2lwQDC7ONfAFXMKA6GpcgYJtQoFaj+ygDX0N68xcDcQIWce8QgjCy7ka6Gagd7PRMoWM5taJPMZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343247; c=relaxed/simple; bh=smUljLOUcVYEp+HL49/UQcm/3kXPNrnN2Gg0orfPSrI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FJB7Ri0j1qRA9XqeK/ksLQ4LJfk8uTHHU78dGFn8Lg6sCekW1DZeTKX7bGS4oiptCO0hiY8r26TGbOU41dDZystGTSTFgb7LSlPVIbgfRaKoscwQr7pv+tKpGfJ1ckTgCeI5gfvagBQXMbNGC/ilekO/Z0hAvPkry/OVQ+cA9qE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 59BFC3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343247; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=p4F3S67bwWIRMgGaGQxsWkep6YI/+H2EAxdwzzQG7Jc=; b=eXMLhBmQsmcUYU6YZmwYe7PWucpHRTaGeYrPQh3NTa+ndDhA/6vl3H4fS6x9wF3ElezECW 0PPH8NcV3dQZpccCHNMtX3Ii4v2m0YQ2+EYYhMnQBTXpkqdpXZCYIDdLkSk/Mr7V/Hdc1F L0niVJ9e1044JYeXG2gldXpyktb2q1A= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-567-VUxDFfh8N6inAkTteFJW-g-1; Sun, 19 Jan 2025 22:20:45 -0500 X-MC-Unique: VUxDFfh8N6inAkTteFJW-g-1 X-Mimecast-MFC-AGG-ID: VUxDFfh8N6inAkTteFJW-g Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F093219560AB for ; Mon, 20 Jan 2025 03:20:44 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 02147195608A; Mon, 20 Jan 2025 03:20:43 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Aaron Merey Subject: [PATCH 01/15] Add eu_search_tree_init Date: Sun, 19 Jan 2025 22:20:27 -0500 Message-ID: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: EZD3jQtILNT1-au4O8pa_wwxdC6z7m0EZZefv3qfDD8_1737343245 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 * libdw/dwarf_begin_elf.c (dwarf_begin_elf): Initialize eu_search_trees. Signed-off-by: Aaron Merey --- libdw/dwarf_begin_elf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c index e4826dda..c8292913 100644 --- a/libdw/dwarf_begin_elf.c +++ b/libdw/dwarf_begin_elf.c @@ -580,6 +580,12 @@ dwarf_begin_elf (Elf *elf, Dwarf_Cmd cmd, Elf_Scn *scngrp) return NULL; } rwlock_init (result->dwarf_lock); + eu_search_tree_init (&result->cu_tree); + eu_search_tree_init (&result->tu_tree); + eu_search_tree_init (&result->split_tree); + eu_search_tree_init (&result->macro_ops_tree); + eu_search_tree_init (&result->files_lines_tree); + result->mem_stacks = 0; result->mem_tails = NULL; From patchwork Mon Jan 20 03:20:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105073 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 3A9453858408 for ; Mon, 20 Jan 2025 03:22:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A9453858408 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OTbFSPk/ X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 8B9F53858D21 for ; Mon, 20 Jan 2025 03:20:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8B9F53858D21 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8B9F53858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343248; cv=none; b=Pfk50CaBWM5xvUcrPib1hFcO2AiUrYS34Wbca06qEVnc93jD9wlUUuVLcqARIpsoIBwOPeD+7L2Mm8HADqSmZLUoLOPkb4wMb7JHalOLT/sOZgo19HrHOQlSJx5LbVI4gIkILHpb7Maa2lquBuawzAfSHIZqSOcMK9sioC/asxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343248; c=relaxed/simple; bh=bkqnpc4Sh8bXfgXL9XKfsmhEpw/h4TkrfeKeYE63FbU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EcR5YoKMXMXcPExwZV0RqURnQJxjSfYE+sGRGFt3415TLzznIjnRunSp7SAa1WOIOhJsdy3dkPWFnbXZAB2ugHqS+hMmT8UgPVUSKs+cm1Psd+gw7UBofrH3GXmBAmP+93ykf0cUbKaCSLTSvFix05JWCn6TyQa4u0SpDwTrhAc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B9F53858D21 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343248; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SWpVNdlNK7ZLOTtNoJe4pX/2Ev+TNWZa5j+Sq1u0S8c=; b=OTbFSPk/tnY3BjD+WQDTMgH22AFPIVw/XVeVLL/X1JWrSTMPB9TJI8D+UxnZYqfI6oERMt 21LhYFmIUh6Hp7HGVoqfAzUJjjsDG5r9tJx3Xpo2noCRKGubKWtmVMVtZKIvxHHaNWYZ3/ WBzP0mpKqyCWhtGcznPi4DLIZrGrxh4= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-133-42mdLT_lN5mT2n4v2lB2xg-1; Sun, 19 Jan 2025 22:20:46 -0500 X-MC-Unique: 42mdLT_lN5mT2n4v2lB2xg-1 X-Mimecast-MFC-AGG-ID: 42mdLT_lN5mT2n4v2lB2xg Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 011D81955DCC for ; Mon, 20 Jan 2025 03:20:46 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 54986195608A; Mon, 20 Jan 2025 03:20:45 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Aaron Merey Subject: [PATCH 02/15] Change type of dwarf_lock from rwlock to mutex Date: Sun, 19 Jan 2025 22:20:28 -0500 Message-ID: <20250120032041.280173-2-amerey@redhat.com> In-Reply-To: <20250120032041.280173-1-amerey@redhat.com> References: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Nlqn69ssy5gQjj7y0hG_Y7kMh8ovtU8QP0kNvmxzzM4_1737343246 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 Change type of dwarf_lock to mutex in order to take advantage of built-in support for recursive locking. * lib/locks.h: Add macros for locking, unlocking, initializing and destroying mutexes. * libdw/dwarf_begin_elf.c (dwarf_end): Replace rwlock macro with mutex macro. * libdw/dwarf_formref_die.c (dwarf_formref_die): Ditto. * libdw/dwarf_getalt.c (dwarf_getalt): Ditto. * libdw/dwarf_setalt.c (dwarf_setalt): Ditto. * libdw/libdwP.h (struct Dwarf): Ditto. * libdw/libdw_findcu.c (__libdw_findcu): Ditto. Signed-off-by: Aaron Merey --- If performance suffers too much from serializing all accesses to Dwarf objects, we could instead consider using an rwlock with a custom wrapper that implements recursive locking. lib/locks.h | 16 ++++++++++++++++ libdw/dwarf_begin_elf.c | 2 +- libdw/dwarf_end.c | 2 +- libdw/dwarf_formref_die.c | 4 ++-- libdw/dwarf_getalt.c | 10 +++++----- libdw/dwarf_setalt.c | 4 ++-- libdw/libdwP.h | 2 +- libdw/libdw_findcu.c | 4 ++-- 8 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/locks.h b/lib/locks.h index 90fe3f1b..9c17eca7 100644 --- a/lib/locks.h +++ b/lib/locks.h @@ -43,6 +43,17 @@ # define rwlock_rdlock(lock) RWLOCK_CALL (rdlock (&lock)) # define rwlock_wrlock(lock) RWLOCK_CALL (wrlock (&lock)) # define rwlock_unlock(lock) RWLOCK_CALL (unlock (&lock)) +# define mutex_define(class,name) class pthread_mutex_t name +# define MUTEX_CALL(call) \ + ({ int _err = pthread_mutex_ ## call; assert_perror (_err); }) +# define mutex_init(lock) \ + ({ pthread_mutexattr_t _attr; \ + pthread_mutexattr_init (&_attr); \ + pthread_mutexattr_settype (&_attr, PTHREAD_MUTEX_RECURSIVE); \ + MUTEX_CALL (init (&lock, &_attr)); }) +# define mutex_lock(_lock) MUTEX_CALL (lock (&_lock)) +# define mutex_unlock(lock) MUTEX_CALL (unlock (&lock)) +# define mutex_fini(lock) MUTEX_CALL (destroy (&lock)) # define once(once_control, init_routine) \ ONCE_CALL (once (&once_control, init_routine)) #else @@ -55,6 +66,11 @@ # define rwlock_rdlock(lock) ((void) (lock)) # define rwlock_wrlock(lock) ((void) (lock)) # define rwlock_unlock(lock) ((void) (lock)) +# define mutex_define(class,name) class int name +# define mutex_init(lock) ((void) (lock)) +# define mutex_lock(lock) ((void) (lock)) +# define mutex_unlock(lock) ((void) (lock)) +# define mutex_fini(lock) ((void) (lock)) # define once_define(class,name) # define once(once_control, init_routine) init_routine() #endif /* USE_LOCKS */ diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c index c8292913..8a3a939b 100644 --- a/libdw/dwarf_begin_elf.c +++ b/libdw/dwarf_begin_elf.c @@ -579,7 +579,7 @@ dwarf_begin_elf (Elf *elf, Dwarf_Cmd cmd, Elf_Scn *scngrp) __libdw_seterrno (DWARF_E_NOMEM); /* no memory. */ return NULL; } - rwlock_init (result->dwarf_lock); + mutex_init (result->dwarf_lock); eu_search_tree_init (&result->cu_tree); eu_search_tree_init (&result->tu_tree); eu_search_tree_init (&result->split_tree); diff --git a/libdw/dwarf_end.c b/libdw/dwarf_end.c index ee3ed74e..92389c07 100644 --- a/libdw/dwarf_end.c +++ b/libdw/dwarf_end.c @@ -129,7 +129,7 @@ dwarf_end (Dwarf *dwarf) if (dwarf->mem_tails != NULL) free (dwarf->mem_tails); pthread_rwlock_destroy (&dwarf->mem_rwl); - rwlock_fini (dwarf->dwarf_lock); + mutex_fini (dwarf->dwarf_lock); /* Free the pubnames helper structure. */ free (dwarf->pubnames_sets); diff --git a/libdw/dwarf_formref_die.c b/libdw/dwarf_formref_die.c index 69d1bf1c..85c484f6 100644 --- a/libdw/dwarf_formref_die.c +++ b/libdw/dwarf_formref_die.c @@ -92,9 +92,9 @@ dwarf_formref_die (Dwarf_Attribute *attr, Dwarf_Die *result) bool scan_debug_types = false; do { - rwlock_wrlock(attr->cu->dbg->dwarf_lock); + mutex_lock (attr->cu->dbg->dwarf_lock); cu = __libdw_intern_next_unit (attr->cu->dbg, scan_debug_types); - rwlock_unlock(attr->cu->dbg->dwarf_lock); + mutex_unlock (attr->cu->dbg->dwarf_lock); if (cu == NULL) { diff --git a/libdw/dwarf_getalt.c b/libdw/dwarf_getalt.c index 26433b81..f4b8ad02 100644 --- a/libdw/dwarf_getalt.c +++ b/libdw/dwarf_getalt.c @@ -170,12 +170,12 @@ dwarf_getalt (Dwarf *main) if (main == NULL) return NULL; - rwlock_wrlock(main->dwarf_lock); + mutex_lock (main->dwarf_lock); /* Only try once. */ if (main->alt_dwarf == (void *) -1) { - rwlock_unlock (main->dwarf_lock); + mutex_unlock (main->dwarf_lock); return NULL; } @@ -185,7 +185,7 @@ dwarf_getalt (Dwarf *main) if (main->alt_dwarf != NULL) { result = main->alt_dwarf; - rwlock_unlock (main->dwarf_lock); + mutex_unlock (main->dwarf_lock); return result; } @@ -195,12 +195,12 @@ dwarf_getalt (Dwarf *main) if (main->alt_dwarf == NULL) { main->alt_dwarf = (void *) -1; - rwlock_unlock (main->dwarf_lock); + mutex_unlock (main->dwarf_lock); return NULL; } result = main->alt_dwarf; - rwlock_unlock (main->dwarf_lock); + mutex_unlock (main->dwarf_lock); return result; } diff --git a/libdw/dwarf_setalt.c b/libdw/dwarf_setalt.c index f98a457c..d8790fd3 100644 --- a/libdw/dwarf_setalt.c +++ b/libdw/dwarf_setalt.c @@ -35,7 +35,7 @@ void dwarf_setalt (Dwarf *main, Dwarf *alt) { - rwlock_wrlock (main->dwarf_lock); + mutex_lock (main->dwarf_lock); if (main->alt_fd != -1) { @@ -45,6 +45,6 @@ dwarf_setalt (Dwarf *main, Dwarf *alt) } main->alt_dwarf = alt; - rwlock_unlock (main->dwarf_lock); + mutex_unlock (main->dwarf_lock); } INTDEF (dwarf_setalt) diff --git a/libdw/libdwP.h b/libdw/libdwP.h index d6bab606..db5abeec 100644 --- a/libdw/libdwP.h +++ b/libdw/libdwP.h @@ -266,7 +266,7 @@ struct Dwarf /* The dwarf_lock is a read-write lock designed to ensure thread-safe access and modification of an entire Dwarf object. */ - rwlock_define(, dwarf_lock); + mutex_define(, dwarf_lock); /* Internal memory handling. This is basically a simplified thread-local reimplementation of obstacks. Unfortunately the standard obstack diff --git a/libdw/libdw_findcu.c b/libdw/libdw_findcu.c index bbbbee5d..613f61c8 100644 --- a/libdw/libdw_findcu.c +++ b/libdw/libdw_findcu.c @@ -249,7 +249,7 @@ __libdw_findcu (Dwarf *dbg, Dwarf_Off start, bool v4_debug_types) if (found != NULL) return *found; - rwlock_wrlock (dbg->dwarf_lock); + mutex_lock (dbg->dwarf_lock); if (start < *next_offset) __libdw_seterrno (DWARF_E_INVALID_DWARF); @@ -276,7 +276,7 @@ __libdw_findcu (Dwarf *dbg, Dwarf_Off start, bool v4_debug_types) } } - rwlock_unlock (dbg->dwarf_lock); + mutex_unlock (dbg->dwarf_lock); return result; } From patchwork Mon Jan 20 03:20:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105071 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 472C5385841C for ; Mon, 20 Jan 2025 03:22:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 472C5385841C Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Eo8Xavmd X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 83BD53858D38 for ; Mon, 20 Jan 2025 03:20:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83BD53858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 83BD53858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343249; cv=none; b=iiQasO+vSMNZqkAgDvQI+ER0mzBuykf3WEorhMKFGQkE4Iou3eIiXFUPLg+mMpFTWW6fsRQCrdOHIAeDxeK6PYIzNdE+7onAVlfDtJScKzldWHZ4iqffcsV5bTN6wwHgjsIIA3KtPwVBRMOTKQS0b2wP+XrnkMwlPCGjqIkSiMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343249; c=relaxed/simple; bh=ICMHdugfpKyG73c9CuK/X/Znwm6JbaTGtYupVy5bto8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=AHyuif5XBcFk2o3AljS+KWJ0g+jS7DDgXz9YHArRcRPeQuNWaI0kR3gBuqHZnN1gnY08T510kJAN9X9Sp9kCF0SNaLcZXIwXvTKKVLfHVY4dXFS/VuO4h7AYZ1P6CK+rb8LD9Fu0nxCO1/ND8P7oKhzqiPCPVtarptk8pOuwtF8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83BD53858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343249; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pz+VBLN1fu52ppQJdrOKvmYe5dl5t7SyK/Jznp55uEo=; b=Eo8Xavmdnj7d3ZMlQ53ez6da4JvAHicpkFiaiGlQR58PL2rTMVWLcnCm36vOwT448ku9nr Gh7X4BpAcvW0kZhjpa7QFQtNKEpSpF4ie+bDYK8+/C35/KyTUF+vqDvL9y/2rfPG0tWMB2 gqShq8VKzQM1gDQb3BfJ5vHYbDigzTI= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680-NStO__knO46dWAJHDlzAQQ-1; Sun, 19 Jan 2025 22:20:47 -0500 X-MC-Unique: NStO__knO46dWAJHDlzAQQ-1 X-Mimecast-MFC-AGG-ID: NStO__knO46dWAJHDlzAQQ Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F1B9219560AB for ; Mon, 20 Jan 2025 03:20:46 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 46A1D195608A; Mon, 20 Jan 2025 03:20:46 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Aaron Merey Subject: [PATCH 03/15] dwarf_filesrc.c: Add locking Date: Sun, 19 Jan 2025 22:20:29 -0500 Message-ID: <20250120032041.280173-3-amerey@redhat.com> In-Reply-To: <20250120032041.280173-1-amerey@redhat.com> References: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: L4j68nQ4UshocRIs4vTYXeOoLD7wP2fl65O6bu8lk5w_1737343247 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 * libdw/dwarf_filesrc.c (dwarf_filesrc): Use dwarf_lock. Signed-off-by: Aaron Merey --- libdw/dwarf_filesrc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libdw/dwarf_filesrc.c b/libdw/dwarf_filesrc.c index d866ce72..a0881f36 100644 --- a/libdw/dwarf_filesrc.c +++ b/libdw/dwarf_filesrc.c @@ -38,14 +38,23 @@ const char * dwarf_filesrc (Dwarf_Files *file, size_t idx, Dwarf_Word *mtime, Dwarf_Word *length) { - if (file == NULL || idx >= file->nfiles) + if (file == NULL) return NULL; + mutex_lock (file->dbg->dwarf_lock); + if (idx >= file->nfiles) + { + mutex_unlock (file->dbg->dwarf_lock); + return NULL; + } + if (mtime != NULL) *mtime = file->info[idx].mtime; if (length != NULL) *length = file->info[idx].length; - return file->info[idx].name; + const char *res = file->info[idx].name; + mutex_unlock (file->dbg->dwarf_lock); + return res; } From patchwork Mon Jan 20 03:20:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105072 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 200C53858416 for ; Mon, 20 Jan 2025 03:22:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 200C53858416 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Dx2W9Bhv X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 52D5B3858D39 for ; Mon, 20 Jan 2025 03:20:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 52D5B3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 52D5B3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343250; cv=none; b=ieUlGq2rGJ0qzEubpyRQ2eta3iAZ46QJwDhLm9vrtJ5NfDs2O1UkTQnswzS4KbQSHF4eb8fx5Gjz5evLsq2EoAolYYd+N/IleyXOSxJHTF8/iHLN8yhPfgvEHadX4daw7dcss5L3kDmfN0oBKgp16QPs496Pzk6j2wIa7k0xUL8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343250; c=relaxed/simple; bh=svNkZ5Wg5qWNrZxrJ8mdxKIsJxQza1rn2IMzDbYBlhE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vYKZGtEMF9v71RDaovu1pAW9gf7nP58JQQ2vcGu+9xCSmDRoZ1f/0oKehVnNIYUGGXeXMtnGr+CPjBsbeM8vYZDYvkMUzY9sD8KkInlOvq+knB16enz90Jblre8n9DUtE5/m+c6SQ7kwlN5IIzAldAM3qeuFH7YmBBBSMbVoZvw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 52D5B3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343250; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Y77BQJgNPSciCf+g4R8xzTuyJmo4HCgLMGISeUOINY=; b=Dx2W9BhvJwv1JmSBwB5Lou6tTFa+1x3fo9e9TGeicUMs+m2h8sKR5+Q0UbOteo9Im+qDaa RX1hdC70s1ol6fl/kpNdafOMiAQeClFtRG099S4DJVBDS/SCWwLHmaXLlmsGgyKSq6mSfk 8bOlH0IA0oJerm98w3rGAZP/RSDlBfA= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-277-pO10hHl1N9-7-qinIVCV-A-1; Sun, 19 Jan 2025 22:20:48 -0500 X-MC-Unique: pO10hHl1N9-7-qinIVCV-A-1 X-Mimecast-MFC-AGG-ID: pO10hHl1N9-7-qinIVCV-A Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E782919560AA for ; Mon, 20 Jan 2025 03:20:47 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 44596195608A; Mon, 20 Jan 2025 03:20:47 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Aaron Merey Subject: [PATCH 04/15] dwarf_getsrcfiles.c: Add locking Date: Sun, 19 Jan 2025 22:20:30 -0500 Message-ID: <20250120032041.280173-4-amerey@redhat.com> In-Reply-To: <20250120032041.280173-1-amerey@redhat.com> References: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: SjUDd2xQj_z_a-D215s24AgOhXkxr6GuWg-FgKJPj4M_1737343248 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 * libdw/dwarf_getsrcfiles.c (dwarf_getsrcfiles): Use dwarf_lock. Signed-off-by: Aaron Merey --- libdw/dwarf_getsrcfiles.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libdw/dwarf_getsrcfiles.c b/libdw/dwarf_getsrcfiles.c index 24e4b7d2..3029ce69 100644 --- a/libdw/dwarf_getsrcfiles.c +++ b/libdw/dwarf_getsrcfiles.c @@ -47,9 +47,10 @@ dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files, size_t *nfiles) } int res = -1; + struct Dwarf_CU *const cu = cudie->cu; + mutex_lock (cudie->cu->dbg->dwarf_lock); /* Get the information if it is not already known. */ - struct Dwarf_CU *const cu = cudie->cu; if (cu->files == NULL) { /* For split units there might be a simple file table (without lines). @@ -96,7 +97,10 @@ dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files, size_t *nfiles) Dwarf_Off debug_line_offset; if (__libdw_formptr (stmt_list, IDX_debug_line, DWARF_E_NO_DEBUG_LINE, NULL, &debug_line_offset) == NULL) - return -1; + { + mutex_unlock (cudie->cu->dbg->dwarf_lock); + return -1; + } res = __libdw_getsrcfiles (cu->dbg, debug_line_offset, __libdw_getcompdir (cudie), @@ -115,8 +119,7 @@ dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files, size_t *nfiles) *nfiles = cu->files->nfiles; } - // XXX Eventually: unlocking here. - + mutex_unlock (cudie->cu->dbg->dwarf_lock); return res; } INTDEF (dwarf_getsrcfiles) From patchwork Mon Jan 20 03:20:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105070 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 87DB43858C5F for ; Mon, 20 Jan 2025 03:21:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 87DB43858C5F Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QyeJq8BW X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 1B8383858CD1 for ; Mon, 20 Jan 2025 03:20:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B8383858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1B8383858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343251; cv=none; b=lhnv78VijeNLFdQvOckz5qGmIJbiFi7UdCSzUvjh0A5YL921YKQ6n16Klqm2bJCrfSwPkmdQG/jJmIqW57hZpQDX8c4xrsALvUZvnGQLnEGIHycz6/I3b+ZFqY5ldgUVwCmD9f4U5c0x/vAU7kHfR9Uls54Mjry61S7FjibuHHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343251; c=relaxed/simple; bh=bh9qO27CkoAwcX61XWLhNyjwweIWvgONu08pLEaK/WQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=LqmEN6weFIhLY4k9OABKvPCCzcq2DgcYJgHeyxX7dvV+KNeGqyqOiIvZmlzopDsGwoq9KKbzXovONzIZpswKn5gqIcsnVmm2Xv/ZtAIuleimpWbuQVlgHnIWFa438mEw7aP9seVCXLaqoYSS2gpg0V/QzrFdwdQeZ7DFmVhL/Kg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B8383858CD1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343250; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o3xfrmt4ZO5E7Vo9TEqsH4WJIfObbSezCgAgps4n/0o=; b=QyeJq8BWHg0KVkNkTZDbJZqi4eIF/qRGy7GnaRS0Dmr4hkp4bHBfJztZVUEPw8KYVi2Kky Rdid/kHKpfUbcJG9Ue29usGn+un9BTLT8J4S0uKuyofqxdP5zK3YcN8fMPJXZy7A89+zlY qeqJuTAW7tVyWM5u+A4Oliexvf7zhFA= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-688-cPxbLwzUNOOkJMtobC1vIQ-1; Sun, 19 Jan 2025 22:20:49 -0500 X-MC-Unique: cPxbLwzUNOOkJMtobC1vIQ-1 X-Mimecast-MFC-AGG-ID: cPxbLwzUNOOkJMtobC1vIQ Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DBB98195608F for ; Mon, 20 Jan 2025 03:20:48 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3AB21195608A; Mon, 20 Jan 2025 03:20:48 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Aaron Merey Subject: [PATCH 05/15] dwarf_getsrclines.c: Add locking Date: Sun, 19 Jan 2025 22:20:31 -0500 Message-ID: <20250120032041.280173-5-amerey@redhat.com> In-Reply-To: <20250120032041.280173-1-amerey@redhat.com> References: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 5tIlBkQqHbJsfYGxecOZSt7Eat1vQs8AT-fddE5g4pg_1737343249 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 * libdw/dwarf_getsrclines.c (dwarf_getsrclines): Use dwarf_lock. Signed-off-by: Aaron Merey --- libdw/dwarf_getsrclines.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/libdw/dwarf_getsrclines.c b/libdw/dwarf_getsrclines.c index da78db67..fb2c431b 100644 --- a/libdw/dwarf_getsrclines.c +++ b/libdw/dwarf_getsrclines.c @@ -1197,8 +1197,6 @@ read_srclines (Dwarf *dbg, + nnewfiles * sizeof (Dwarf_Fileinfo) + (ndirs + 1) * sizeof (char *), 1); - - /* Copy prevfiles to newfiles. */ for (size_t n = 0; n < nprevfiles; n++) newfiles->info[n] = prevfiles->info[n]; @@ -1442,8 +1440,10 @@ dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines, size_t *nlines) return -1; } - /* Get the information if it is not already known. */ struct Dwarf_CU *const cu = cudie->cu; + mutex_lock (cu->dbg->dwarf_lock); + + /* Get the information if it is not already known. */ if (cu->lines == NULL) { /* For split units always pick the lines from the skeleton. */ @@ -1464,10 +1464,13 @@ dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines, size_t *nlines) *lines = cu->lines; *nlines = cu->lines->nlines; } + + mutex_unlock (cu->dbg->dwarf_lock); return res; } __libdw_seterrno (DWARF_E_NO_DEBUG_LINE); + mutex_unlock (cu->dbg->dwarf_lock); return -1; } @@ -1485,12 +1488,18 @@ dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines, size_t *nlines) Dwarf_Off debug_line_offset; if (__libdw_formptr (stmt_list, IDX_debug_line, DWARF_E_NO_DEBUG_LINE, NULL, &debug_line_offset) == NULL) - return -1; + { + mutex_unlock (cu->dbg->dwarf_lock); + return -1; + } if (__libdw_getsrclines (cu->dbg, debug_line_offset, __libdw_getcompdir (cudie), cu->address_size, &cu->lines, &cu->files) < 0) - return -1; + { + mutex_unlock (cu->dbg->dwarf_lock); + return -1; + } } else if (cu->lines == (void *) -1l) return -1; @@ -1498,8 +1507,7 @@ dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines, size_t *nlines) *lines = cu->lines; *nlines = cu->lines->nlines; - // XXX Eventually: unlocking here. - + mutex_unlock (cu->dbg->dwarf_lock); return 0; } INTDEF(dwarf_getsrclines) From patchwork Mon Jan 20 03:20:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105074 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 254283858C5F for ; Mon, 20 Jan 2025 03:22:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 254283858C5F Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YKsV0YVK X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 738C23858C5F for ; Mon, 20 Jan 2025 03:20:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 738C23858C5F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 738C23858C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343252; cv=none; b=m2/pSBKRKC2R8HMh8SB1Wb0bijHwjlhQM0n4kDFE2IlKBdE5+mkJ9giA7LYKS9VNkH9aVdY8I+WfXte5dDXJfl/hZt0qhMAjwRPkNkfihFPpD5MCGvhrNccwgaxN4Fwg/kkMmqF1y0XbSucyO4mmvpmf9fqQUuq0ukTIJCfVMRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343252; c=relaxed/simple; bh=PoUWqmeInt8wn5t4FDa+6jRRIwWA5JEDzszNQfK+mio=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Rzqs9iOUrLdIvlYgJQfyGmPIKLKuvkObFvSkVBY8PdpjAjRMtLaQCwvGhJTP5gQKrwXSmli0GrjXJc7BXFtzondWe+Qe6vfF/kDmqKQ3FpXtmxqEYouxAeZxF6p08BgmrrQuE8/KIsmWRzjhSYPkP7SosNzHxZJTVuwMkFRZbfc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 738C23858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343252; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GgRfUBaQ4Wmm9y9oIeuvx4cNw/ap9HzQEcrS5Et6Zq4=; b=YKsV0YVKANjdOw8s3DInrFyjvDMoOGijFrdkel78pFD32l4Xnb5Y9T44HB1Mu+lZzLbcFP KVMUYA9j0qiZL9qcX9y5alboAbhZmPPNecz3wIHCCuAnq/an8ajKi0kgWM17nm9a9iM7pl DY0dlGivlT04GiwxOXY5T0E+YBQkQR0= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-97PPEXUjO-eGJL09u9x-dQ-1; Sun, 19 Jan 2025 22:20:50 -0500 X-MC-Unique: 97PPEXUjO-eGJL09u9x-dQ-1 X-Mimecast-MFC-AGG-ID: 97PPEXUjO-eGJL09u9x-dQ Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E0F6019560AF for ; Mon, 20 Jan 2025 03:20:49 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2E00A1956094; Mon, 20 Jan 2025 03:20:49 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Aaron Merey Subject: [PATCH 06/15] Add Dwarf member to Dwarf_Lines and Dwarf_Files Date: Sun, 19 Jan 2025 22:20:32 -0500 Message-ID: <20250120032041.280173-6-amerey@redhat.com> In-Reply-To: <20250120032041.280173-1-amerey@redhat.com> References: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 3Zakr_h-jxfO8jEzjQNzbf2kMzEH9ot-IZuM8GLZYYU_1737343250 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 * libdw/dwarf_getsrclines.c (read_srcfiles): Initialize dbg member. * libdw/libdwP.h (struct Dwarf_Files_s): Add Dwarf member. (struct Dwarf_Lines_s): Ditto. Signed-off-by: Aaron Merey --- libdw/dwarf_getsrclines.c | 4 ++++ libdw/libdwP.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/libdw/dwarf_getsrclines.c b/libdw/dwarf_getsrclines.c index fb2c431b..6ae5abc7 100644 --- a/libdw/dwarf_getsrclines.c +++ b/libdw/dwarf_getsrclines.c @@ -717,6 +717,7 @@ read_srcfiles (Dwarf *dbg, if (unlikely (files == NULL)) goto no_mem; + files->dbg = dbg; const char **dirs = (void *) &files->info[nfilelist]; struct filelist *fileslist = filelist; @@ -1197,6 +1198,8 @@ read_srclines (Dwarf *dbg, + nnewfiles * sizeof (Dwarf_Fileinfo) + (ndirs + 1) * sizeof (char *), 1); + newfiles->dbg = dbg; + /* Copy prevfiles to newfiles. */ for (size_t n = 0; n < nprevfiles; n++) newfiles->info[n] = prevfiles->info[n]; @@ -1254,6 +1257,7 @@ read_srclines (Dwarf *dbg, The buffers overlap, so we've clobbered the early elements of SORTLINES by the time we're reading the later ones. */ Dwarf_Lines *lines = buf; + lines->dbg = dbg; lines->nlines = state.nlinelist; for (size_t i = 0; i < state.nlinelist; ++i) { diff --git a/libdw/libdwP.h b/libdw/libdwP.h index db5abeec..7655e3ec 100644 --- a/libdw/libdwP.h +++ b/libdw/libdwP.h @@ -304,6 +304,7 @@ struct Dwarf_Abbrev /* Files in line information records. */ struct Dwarf_Files_s { + Dwarf *dbg; unsigned int ndirs; unsigned int nfiles; struct Dwarf_Fileinfo_s @@ -345,6 +346,7 @@ struct Dwarf_Line_s struct Dwarf_Lines_s { + Dwarf *dbg; size_t nlines; struct Dwarf_Line_s info[0]; }; From patchwork Mon Jan 20 03:20:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105079 X-Patchwork-Delegate: mark@klomp.org 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 32E6F3858406 for ; Mon, 20 Jan 2025 03:24:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32E6F3858406 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OOGHemCc X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 8FD4A3858C35 for ; Mon, 20 Jan 2025 03:20:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8FD4A3858C35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8FD4A3858C35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343253; cv=none; b=TFjs4XMoOCRVj2NG3ilyNMrUTh+6J8dmJsOXY3hfCKgVDqe2ZbpEBoYwAWC3OX7cmcyuJUsu61sSfq94ay53glCFVU33aeC8Mw/zVoXx54GhR7sxT5IOYgYGgKnefk4YUfXP/2abBPlPs7YaFQPdMY5ct10OhkW67pHZ3rpL07k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343253; c=relaxed/simple; bh=GSPBZgQ+GwV50dVV8QaxI++wYYCg09YEkFswKo4i980=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=eBMJYhBTVZyDEPtbnx35D31R+qtNTEhd5bRwKCxgFTR/NxxWhlx1qttG4X/Aff8+xzQDBqbWkqITPCdwLMP9VYXkErKwwSghM8GSPSVGWxrrt6WHhEN8syKb9zv6TuVV/DotSvFloaETNeLYRy6f6lv921gDL8R2GilExrbOgkU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8FD4A3858C35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ikck9WEa8Zt/PR/5KyGD80jPNGk2y9/tZS2CAKgLegY=; b=OOGHemCctsVxNbHGPaBxhYD+jI23r+vkv00ZB6U1VjrZMRdohmG+PDofuvsikYVeyhWp4j 1ofGeJ+ue3dSBq42dZeQgC9QzvPBncQqtbgbAjRxuq7VefUh83pwpgYR0ztf1TgaPxY7Ot Ine0DYpuebaeqJr13IMZYMJH8bzLmKc= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-345-yAmryPdJPNiEnlyPObfOvw-1; Sun, 19 Jan 2025 22:20:51 -0500 X-MC-Unique: yAmryPdJPNiEnlyPObfOvw-1 X-Mimecast-MFC-AGG-ID: yAmryPdJPNiEnlyPObfOvw Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1BA1A19560BB for ; Mon, 20 Jan 2025 03:20:51 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3679E1956094; Mon, 20 Jan 2025 03:20:50 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Aaron Merey Subject: [PATCH 07/15] dwarf_lineaddr.c: Add locking Date: Sun, 19 Jan 2025 22:20:33 -0500 Message-ID: <20250120032041.280173-7-amerey@redhat.com> In-Reply-To: <20250120032041.280173-1-amerey@redhat.com> References: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: wAUrWEbjoIojKL2cZ0S_8PPfKRR3IyWDntmR_3kWOsM_1737343251 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 * libdw/dwarf_lineaddr.c (dwarf_lineaddr): Use dwarf_lock. Signed-off-by: Aaron Merey --- libdw/dwarf_lineaddr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libdw/dwarf_lineaddr.c b/libdw/dwarf_lineaddr.c index 4e1952d3..bf81966c 100644 --- a/libdw/dwarf_lineaddr.c +++ b/libdw/dwarf_lineaddr.c @@ -40,7 +40,9 @@ dwarf_lineaddr (Dwarf_Line *line, Dwarf_Addr *addrp) if (line == NULL) return -1; + mutex_lock (line->files->dbg->dwarf_lock); *addrp = line->addr; + mutex_unlock (line->files->dbg->dwarf_lock); return 0; } From patchwork Mon Jan 20 03:20:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105083 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 299EF3858D39 for ; Mon, 20 Jan 2025 03:25:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 299EF3858D39 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Cwny/W2r X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 794CF385840B for ; Mon, 20 Jan 2025 03:20:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 794CF385840B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 794CF385840B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343254; cv=none; b=HC39hzPzzdR3PBEIXeDSewGtCkzc96ULbH/jhZRLOrEERQf3HVdS87jegwCCQa6A1hRPb8nE+SNQtR3CdJP1qnI220dYvj4OVeHQW1BU6HdqHQwQrThCVA4htxF1Sb3VkPWOrriZc4oPJXjE07es/HOgOfQuU03mBUQj1LSNFxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343254; c=relaxed/simple; bh=9wOuVroPG/PZJNNG9RSEQVIOaUsvtTOoElguwNf6ksk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wblMzJ6+L9N+5+tNXReZMjXECs3JcUN0SYyfgLdRJRg1A+kGSpvy59uJ+WNUSgsZYg/xS5K4+Ovndqw9ONhCaLwJJpfRVmaPcvkTtSKef3zy5lRUa2m7+y6VtFEio+X9bO+po9565KNX7usfl78PyjkSn2iJs788SwbCLIvbpiM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 794CF385840B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343254; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xuISjRs34czMUuIfgT9Yol1O9AOzpEXy6bmK4j6HxHc=; b=Cwny/W2rBWyllDUC8GzRUHd/bJcAfRcE/PYD2AWMJxA8PjyLQ7MqYz69Peqgl32UWC62G7 e0Kj9B44hEP4bolr0VNnKTpEa+5j8PaKUE27OyLTn12ZrMnruyo80w9qYbcG0+KaZw5G7B 61e9/f8XzoZ9n/9oClfXPt3kZAMmlto= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-VMd0g_UANlmZWtTN1RuKag-1; Sun, 19 Jan 2025 22:20:52 -0500 X-MC-Unique: VMd0g_UANlmZWtTN1RuKag-1 X-Mimecast-MFC-AGG-ID: VMd0g_UANlmZWtTN1RuKag Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 00DDA1955DCD for ; Mon, 20 Jan 2025 03:20:52 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4589E195608A; Mon, 20 Jan 2025 03:20:51 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Aaron Merey Subject: [PATCH 08/15] dwarf_offdie.c: Add locking Date: Sun, 19 Jan 2025 22:20:34 -0500 Message-ID: <20250120032041.280173-8-amerey@redhat.com> In-Reply-To: <20250120032041.280173-1-amerey@redhat.com> References: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: HOZxWWmQOktAtnlhFrnZ4pTMfzwvhLZcwZHFE845VBA_1737343252 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 * libdw/dwarf_offdie.c (__libdw_offdie): Use dwarf_lock. Signed-off-by: Aaron Merey --- libdw/dwarf_offdie.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libdw/dwarf_offdie.c b/libdw/dwarf_offdie.c index 883720de..74eac420 100644 --- a/libdw/dwarf_offdie.c +++ b/libdw/dwarf_offdie.c @@ -43,11 +43,13 @@ __libdw_offdie (Dwarf *dbg, Dwarf_Off offset, Dwarf_Die *result, if (dbg == NULL) return NULL; + mutex_lock (dbg->dwarf_lock); Elf_Data *const data = dbg->sectiondata[debug_types ? IDX_debug_types : IDX_debug_info]; if (data == NULL || offset >= data->d_size) { __libdw_seterrno (DWARF_E_INVALID_DWARF); + mutex_unlock (dbg->dwarf_lock); return NULL; } @@ -66,6 +68,7 @@ __libdw_offdie (Dwarf *dbg, Dwarf_Off offset, Dwarf_Die *result, result = NULL; } + mutex_unlock (dbg->dwarf_lock); return result; } From patchwork Mon Jan 20 03:20:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105078 X-Patchwork-Delegate: mark@klomp.org 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 1BF533858CD1 for ; Mon, 20 Jan 2025 03:23:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1BF533858CD1 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=PkwP7pwV X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 9D5FC3858CDA for ; Mon, 20 Jan 2025 03:20:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D5FC3858CDA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9D5FC3858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343255; cv=none; b=S6cyX3kpDG6eebshZEQ9wdyjwry6WtLHXH3XdWacHQNcj22pJ+y4ZmtaRxVeih5NinsQkaJxB5IF2gdmzjV5YZMLMEKOuRow4nFY8gVRgygSA7dgwO8usfIRdPHLDzecQXRKk6SSsJfezRF8H/hDaRMEaAoVt24Wxoum82qJ4Mk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343255; c=relaxed/simple; bh=XTI32zh/7UtQNdWlmGjTAOCqWHKxGYqRlmDGMm5BcgU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=bA/orT9JiXtfVnilxbSA35hx/IUg0MHxxXRg2oHjxfCGmzzCX9rbADBSJBoZNlsErdOxaU+NwQ8f368Gxj/WBuSHSJYLLc+ZaKU6iPXjIuyfBOv0TiNuy74cBtgb36YTbdmg8uYbLjc/m9ZVjQGdsqzM2xZd3VX6Fzl5I9f7GIE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D5FC3858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343255; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lRssHVOJeZpL5OyzLtfi2Jup9MOqIPFoc4GJ45pa9Iw=; b=PkwP7pwV9mjPMtoqTXjra2IbYa2wvzc5gq8iitrNqXsrYroAzzmksPlXFpT2eyvwLSXlGa r3I9CYhao6mPDRKt49e4ZyNw1YqgLT5FfMfXSUyjvq08et65O3DMQag1Y/qN2Wh6wU4VO0 FWnROwgf9xX7uK0F+BULZS8e0QNAJEA= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-413-IT_lTjlvOjqVz31quRjm3Q-1; Sun, 19 Jan 2025 22:20:53 -0500 X-MC-Unique: IT_lTjlvOjqVz31quRjm3Q-1 X-Mimecast-MFC-AGG-ID: IT_lTjlvOjqVz31quRjm3Q Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F17E219560B3 for ; Mon, 20 Jan 2025 03:20:52 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 48AE01956094; Mon, 20 Jan 2025 03:20:52 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Aaron Merey Subject: [PATCH 09/15] dwarf_onesrcline.c: Add locking Date: Sun, 19 Jan 2025 22:20:35 -0500 Message-ID: <20250120032041.280173-9-amerey@redhat.com> In-Reply-To: <20250120032041.280173-1-amerey@redhat.com> References: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: vNVtMnCNtJRZZR199nGBtLjXDZU7RhX-d2tt9RO9WTk_1737343253 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 * libdw/dwarf_onesrcline.c (dwarf_onesrcline): Use dwarf_lock. Signed-off-by: Aaron Merey --- libdw/dwarf_onesrcline.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libdw/dwarf_onesrcline.c b/libdw/dwarf_onesrcline.c index 5d3c3ded..1a16269a 100644 --- a/libdw/dwarf_onesrcline.c +++ b/libdw/dwarf_onesrcline.c @@ -40,11 +40,16 @@ dwarf_onesrcline (Dwarf_Lines *lines, size_t idx) if (lines == NULL) return NULL; + mutex_lock (lines->dbg->dwarf_lock); + if (idx >= lines->nlines) { __libdw_seterrno (DWARF_E_INVALID_LINE_IDX); return NULL; } - return &lines->info[idx]; + Dwarf_Line *result = &lines->info[idx]; + mutex_unlock (lines->dbg->dwarf_lock); + + return result; } From patchwork Mon Jan 20 03:20:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105075 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 39FC13858C50 for ; Mon, 20 Jan 2025 03:22:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39FC13858C50 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QaK8MTKt X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id B9473385840E for ; Mon, 20 Jan 2025 03:20:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9473385840E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B9473385840E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343256; cv=none; b=OQraIhuGGyXBj/w6J3Lvjw7E3pf3o6DmLlCjrOs7vigug7GTxplJPcwD7Azv58Zdxz0QRjxahOGw0jMNg3noOj6+3cLfrF9t8+ajy/J6RPTosgo1hRiPRwly2hLzCuinNRIixGOROEbDX4sY4DOofr3zTvfmSVkSHHLUYKIEMcA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343256; c=relaxed/simple; bh=Ups8/Gx9bYSDp9kqhUTEdmp2w8crMdGNsXhPtDWyB54=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=VxBeKszYiEkn2wPXbP8oYdE/v+WAVwyE57cx6K1/qADXMX5U+Kz5ZyqJjvkIbhsgXuwqqFom1ieUy858YC9PyiOxSXW3KagggPiUf8iTdmGsYeLF6mYn83oW4PDP7w03IhAOY8eAn7zoQYM2FfbbQR6SLqf3JPjQNvyPQISBK18= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B9473385840E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m4+9MGYcdM8OcsaqimsKRZzf2cqm4pwpkeBJVrlPnps=; b=QaK8MTKtvE5qyLgYCIkT0Azqle3Zqghne8gsUSGkW98LUdFw4D7hcXvnhiXGB3UpTISb+/ NawLK2PqD0L5jcz0ffCwVKy7qsk2enyVHFsK4rcmlKYQDbDy9+G+dwmlUNjSeEkLM6D0JT 4A6k4Vlw2KLAJzRfhzj8vCUunL0sS1E= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-184-S7nDSLEQO22jnd4nbPoC6A-1; Sun, 19 Jan 2025 22:20:54 -0500 X-MC-Unique: S7nDSLEQO22jnd4nbPoC6A-1 X-Mimecast-MFC-AGG-ID: S7nDSLEQO22jnd4nbPoC6A Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EF61A1955DCC for ; Mon, 20 Jan 2025 03:20:53 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 43666195608A; Mon, 20 Jan 2025 03:20:53 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Aaron Merey Subject: [PATCH 10/15] Add configure option --enable-helgrind Date: Sun, 19 Jan 2025 22:20:36 -0500 Message-ID: <20250120032041.280173-10-amerey@redhat.com> In-Reply-To: <20250120032041.280173-1-amerey@redhat.com> References: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: e1xe_U26lAiFgexyafZ6iHnOtEzA1OOnYntYGg9WT24_1737343254 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 Like --enable-valgrind but uses helgrind instead of memcheck. If both --enable-valgrind and --enable-helgrind are given then helgrind takes priority. * configure.ac: Add --enable-helgrind option. * tests/Makefile.am: If USE_HELGRIND is true, then include --tool=helgrind in the valgrind command that tests are run under. Signed-off-by: Aaron Merey --- configure.ac | 10 ++++++++-- tests/Makefile.am | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 1da2a12c..a78cd36f 100644 --- a/configure.ac +++ b/configure.ac @@ -363,10 +363,15 @@ if test "$use_address" = yes; then fi AM_CONDITIONAL(USE_ADDRESS_SANITIZER, test "$use_address" = yes) +AC_ARG_ENABLE([helgrind], +AS_HELP_STRING([--enable-helgrind],[run all tests under the valgrind tool helgrind]), +[use_helgrind=$enableval], [use_helgrind=no]) + AC_ARG_ENABLE([valgrind], AS_HELP_STRING([--enable-valgrind],[run all tests under valgrind]), [use_valgrind=$enableval], [use_valgrind=no]) -if test "$use_valgrind" = yes; then + +if test "$use_valgrind" = yes -o "$use_helgrind" = yes; then if test "$use_address" = yes; then AC_MSG_ERROR([cannot enable valgrind and sanitize address together]) fi @@ -375,7 +380,8 @@ if test "$use_valgrind" = yes; then AC_MSG_ERROR([valgrind not found]) fi fi -AM_CONDITIONAL(USE_VALGRIND, test "$use_valgrind" = yes) +AM_CONDITIONAL(USE_VALGRIND, test "$use_valgrind" = yes -o "$use_helgrind" = yes) +AM_CONDITIONAL(USE_HELGRIND, test "$use_helgrind" = yes) AC_ARG_WITH([valgrind], AS_HELP_STRING([--with-valgrind],[include directory for Valgrind headers]), diff --git a/tests/Makefile.am b/tests/Makefile.am index 8f087798..e4fe72f0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -691,8 +691,12 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ testfile-sysroot.tar.bz2 run-sysroot.sh run-debuginfod-seekable.sh +if USE_HELGRIND +valgrind_cmd = valgrind -q --tool=helgrind --error-exitcode=1 +else if USE_VALGRIND -valgrind_cmd=valgrind -q --leak-check=full --error-exitcode=1 +valgrind_cmd = valgrind -q --leak-check=full --error-exitcode=1 +endif endif From patchwork Mon Jan 20 03:20:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105077 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 4060F3858C52 for ; Mon, 20 Jan 2025 03:23:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4060F3858C52 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bCyFjU5O X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 72DF73858410 for ; Mon, 20 Jan 2025 03:20:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 72DF73858410 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 72DF73858410 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343257; cv=none; b=Z6QXZ2y7aijGrYB5+TDCf7PLlxYvFO63vzT3Z0ePBf1S15XgbVBQsgcfR0mf3+WnTKhvTiLVkxegqnLvrILYgrfIRMfX/rgloq8SdLXpnMNUUsLg9+mypCjRed3OQAnaJDGsUwO8Q1bBrgu9xwqDTEKSlFyhjr5+nU1P4ntv43U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343257; c=relaxed/simple; bh=h7vPp2G5RMFxmTkjfOGSGlUcfOQKLe6KK4jmnnmodtk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=UYuBjazoL+5NUPTw9ZSkPdFuJCBUHQC1bZbI0l0iApkqyKYso8b1P2X6/DwAw+m9X19/2tR13PI2FPjSD2jbEFnUjUOolMl+noasAQVIs4nLwj2+I7WadxXtr7/+a+GB7ZfhEfKE6Cam9r494aw+0KPo67j2fa8tgNbPjhb1eAQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 72DF73858410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343257; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kDrvwkyV2XsUWmDO7x5EB5R8InZTk0UwK0ZvOFsg/EU=; b=bCyFjU5O9/47m09Fe5QZ0NnJ6EhoA3qRXmjGl9JJGUcXWZFPE2fJMlBprHm0pCYMnBXN1T fXFNJE/L86MlSoUczcMFdS+DRw1r/XV+pjGnL6H5AHJ1EAu1Z7dNoe25mFEEjmxtRiFExg Ws8iRFLthMIu6+vWXaaRie1s1XnFG7E= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-447-mELOXZEaNaenBLscnx8WSg-1; Sun, 19 Jan 2025 22:20:55 -0500 X-MC-Unique: mELOXZEaNaenBLscnx8WSg-1 X-Mimecast-MFC-AGG-ID: mELOXZEaNaenBLscnx8WSg Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F252D19560AA for ; Mon, 20 Jan 2025 03:20:54 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 421FE195608A; Mon, 20 Jan 2025 03:20:54 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Aaron Merey Subject: [PATCH 11/15] Add tests/thread-safety-subr.sh Date: Sun, 19 Jan 2025 22:20:37 -0500 Message-ID: <20250120032041.280173-11-amerey@redhat.com> In-Reply-To: <20250120032041.280173-1-amerey@redhat.com> References: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: daSgvwcmlO7H3FZ9eGV6Cbj7F1BcOQZ76YpFYJBPbQg_1737343255 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 thread-safety-subr.sh contains subroutine check_thread_safety_enabled which skips further testing when either USE_LOCKS is false or when attempting to use valgrind with address or memory sanitizer enabled. * tests/Makefile.am (EXTRA_DIST): Add thread-safety-subr.sh. * tests/thread-safety-subr.sh: New file. Signed-off-by: Aaron Merey --- tests/Makefile.am | 1 + tests/thread-safety-subr.sh | 53 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/thread-safety-subr.sh diff --git a/tests/Makefile.am b/tests/Makefile.am index e4fe72f0..9ca97b6f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -689,6 +689,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ testfile-dwp-cu-index-overflow.source \ testfile-define-file.bz2 \ testfile-sysroot.tar.bz2 run-sysroot.sh run-debuginfod-seekable.sh + thread-safety-subr.sh if USE_HELGRIND diff --git a/tests/thread-safety-subr.sh b/tests/thread-safety-subr.sh new file mode 100644 index 00000000..9d361850 --- /dev/null +++ b/tests/thread-safety-subr.sh @@ -0,0 +1,53 @@ +#! /bin/sh +# Subroutines for thread safety testing +# Copyright (C) 2024 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. $srcdir/test-subr.sh + +# Verify that thread safety tests can be run. If not, skip further testing. +check_thread_safety_enabled() +{ + # Extract build settings. + USE_LOCKS=$(grep '^#define USE_LOCKS' \ + ${abs_builddir}/../config.h | awk '{print $3}') + USE_ADDRESS_SANITIZER=$(grep 'USE_ADDRESS_SANITIZER_TRUE' \ + ${abs_builddir}/../config.status | awk -F'=' '{print $2}') + USE_MEMORY_SANITIZER=$(grep 'USE_MEMORY_SANITIZER_TRUE' \ + ${abs_builddir}/../config.status | awk -F'=' '{print $2}') + + # Test will only be run if USE_LOCKS is defined. Otherwise, skip. + if [[ "$USE_LOCKS" != 1 ]]; then + echo "USE_LOCKS is not defined. Skipping test." + exit 77 + fi + + if [[ "x$VALGRIND_CMD" == "x" ]]; then + return 0 + fi + + # Cannot use Valgrind and Address Sanitizer together. + if [[ "$USE_ADDRESS_SANITIZER" != "\"#\"" ]]; then + echo "Address Sanitizer is enabled. Skipping test." + exit 77 + fi + + # Cannot use Valgrind and Memory Sanitizer together. + if [[ "$USE_MEMORY_SANITIZER" != "\"#\"" ]]; then + echo "Memory Sanitizer is enabled. Skipping test." + exit 77 + fi +} From patchwork Mon Jan 20 03:20:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105081 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 A71C63858C50 for ; Mon, 20 Jan 2025 03:24:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A71C63858C50 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hC0IwaAJ X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 5551B3858D28 for ; Mon, 20 Jan 2025 03:21:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5551B3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5551B3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343261; cv=none; b=bii0Q3LD/lBx6m+07Rh3yb98foLBwFoKXqJ+6qdqq+yAbwehihlrBp5u+ADjX7vZSldDk+PFlCc0PQT1xd2PbSyp6kduxWlGLqJDcre1vQX4joI46C4aIbmYSDHFdyz4q3FPtVW61TT9buANvZvuCYNB3xDbiKkhtQBA0FyV5Yk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343261; c=relaxed/simple; bh=dt0OFljpmz5cSEt1v7ltHJQRUNocDWoh07Sjz2Aq9CI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=h93/IEF8XzKTkoLnknSpknkN/hImNqw2aOA2JfIwLsmHAO2fF56Iun79Ar+sswVDKkl5zcoZVdFcBtzF4J0zPN8l+eFw0rDtUT90WnPWck+U1ynwCkoIDrKZXwhVK6i2tAQqpOhEA1rf/eolZ8KGoQCAPqnGvGWW+QyxBBXDWLI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5551B3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343261; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UGXDTDgBXvu2Qrx+scjtcLUImmawUxiBPm6QWWzO9MU=; b=hC0IwaAJqIYB/E9GcyS8ADRUoPnfMLU1yU8Q3Y/Q19wbkpRcyAVCDcXIqI7A0aptCNXyT5 gKrDwrMLCghmMz1gD9bYwEGgUDk5Y8oPmvp89+S0JTadOIsFGSWjUa/Cxmg+L6Bc1jKl+5 ODwivsUHQMgeBl+ezdLQCVjaUYJGOGs= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-xosHOSl-OZ64ZTgAEhKzRw-1; Sun, 19 Jan 2025 22:20:57 -0500 X-MC-Unique: xosHOSl-OZ64ZTgAEhKzRw-1 X-Mimecast-MFC-AGG-ID: xosHOSl-OZ64ZTgAEhKzRw Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8B5F519560AB; Mon, 20 Jan 2025 03:20:56 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4E5901956094; Mon, 20 Jan 2025 03:20:55 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Heather McIntyre , Aaron Merey , Mark Wielaard Subject: [PATCH 12/15 v4] Add tests/run-eu-search-cfi.sh Date: Sun, 19 Jan 2025 22:20:38 -0500 Message-ID: <20250120032041.280173-12-amerey@redhat.com> In-Reply-To: <20250120032041.280173-1-amerey@redhat.com> References: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: DbUGCRMjLM9mnho9ai2mju-XZslWmN2Z2xrEACqrWcU_1737343256 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 * tests/.gitignore: Add eu_search_cfi. * tests/Makefile.am: Add eu_search_cfi, run-eu-search-cfi.sh. * tests/eu_search_cfi.c: New file. * tests/run-eu-search-cfi.sh: New file. Signed-off-by: Heather S. McIntyre Signed-off-by: Aaron Merey Signed-off-by: Mark Wielaard --- v3: https://patchwork.sourceware.org/project/elfutils/patch/20240802233847.690564-9-amerey@redhat.com/ Changes in v4: run-eu-search-tests.sh dropped and cfi search_tree tests moved to run-eu-search-cfi.sh. Formatting changes and improved lock contention in eu_search_cfi.c. tests/.gitignore | 1 + tests/Makefile.am | 8 +- tests/eu_search_cfi.c | 201 +++++++++++++++++++++++++++++++++++++ tests/run-eu-search-cfi.sh | 31 ++++++ 4 files changed, 239 insertions(+), 2 deletions(-) create mode 100644 tests/eu_search_cfi.c create mode 100755 tests/run-eu-search-cfi.sh diff --git a/tests/.gitignore b/tests/.gitignore index 14620fc3..bf17d646 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -67,6 +67,7 @@ /elfstrtab /elf-print-reloc-syms /emptyfile +/eu_search_cfi /fillfile /find-prologues /funcretval diff --git a/tests/Makefile.am b/tests/Makefile.am index 9ca97b6f..0eb2048d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -65,6 +65,7 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ msg_tst system-elf-libelf-test system-elf-gelf-test \ nvidia_extended_linemap_libdw elf-print-reloc-syms \ cu-dwp-section-info declfiles \ + eu_search_cfi \ $(asm_TESTS) asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ @@ -217,7 +218,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-readelf-dw-form-indirect.sh run-strip-largealign.sh \ run-readelf-Dd.sh run-dwfl-core-noncontig.sh run-cu-dwp-section-info.sh \ run-declfiles.sh \ - run-sysroot.sh + run-sysroot.sh run-eu-search-cfi.sh if !BIARCH export ELFUTILS_DISABLE_BIARCH = 1 @@ -688,7 +689,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ testfile-dwp-4-cu-index-overflow.dwp.bz2 \ testfile-dwp-cu-index-overflow.source \ testfile-define-file.bz2 \ - testfile-sysroot.tar.bz2 run-sysroot.sh run-debuginfod-seekable.sh + testfile-sysroot.tar.bz2 run-sysroot.sh run-debuginfod-seekable.sh \ + run-eu-search-cfi.sh \ thread-safety-subr.sh @@ -874,6 +876,8 @@ nvidia_extended_linemap_libdw_LDADD = $(libelf) $(libdw) elf_print_reloc_syms_LDADD = $(libelf) cu_dwp_section_info_LDADD = $(libdw) declfiles_LDADD = $(libdw) +eu_search_cfi_LDFLAGS = $(if $(filter undefined,$(origin USE_LOCKS)),-pthread) $(AM_LDFLAGS) +eu_search_cfi_LDADD = $(libeu) $(libelf) $(libdw) # We want to test the libelf headers against the system elf.h header. # Don't include any -I CPPFLAGS. Except when we install our own elf.h. diff --git a/tests/eu_search_cfi.c b/tests/eu_search_cfi.c new file mode 100644 index 00000000..4a46ab1c --- /dev/null +++ b/tests/eu_search_cfi.c @@ -0,0 +1,201 @@ +/* Test program for eu_search_cfi + Copyright (C) 2023 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see. */ + +#include +#include +#include +#include ELFUTILS_HEADER(dw) +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "system.h" +#include + +static void handle_section (char *name, const unsigned char e_ident[], + Elf_Scn *scn, const bool is_eh); +static void *thread_work (void *arg); + +typedef struct +{ + char *name; + const unsigned char *e_ident; + Elf_Scn * scn; + bool is_eh; +} +ThreadData; + +static void *thread_work (void *arg) +{ + ThreadData *data = (ThreadData *) arg; + handle_section (data->name, data->e_ident, data->scn, data->is_eh); + return NULL; +} + +static void handle_section (char *name, const unsigned char e_ident[], + Elf_Scn *scn, const bool is_eh) +{ + if (is_eh) + printf (".eh_frame\n"); + else + printf (".debug_frame\n"); + + GElf_Shdr mem; + GElf_Shdr *shdr = gelf_getshdr (scn, &mem); + + if (shdr == NULL) + error (EXIT_FAILURE, 0, "Couldn't get section header: %s", + elf_errmsg (-1)); + + if ((shdr->sh_flags &SHF_COMPRESSED) != 0) + { + if (elf_compress (scn, 0, 0) < 0) + error (EXIT_FAILURE, 0, "Couldn't decompress section: %s", + elf_errmsg (-1)); + } + else if (name[0] == '.' && name[1] == 'z') + { + if (elf_compress_gnu (scn, 0, 0) < 0) + error (EXIT_FAILURE, 0, "Couldn't decompress section: %s", + elf_errmsg (-1)); + } + + Elf_Data *data = elf_getdata (scn, NULL); + if (data == NULL || data->d_buf == NULL) + error (EXIT_FAILURE, 0, "no section data"); + + int res; + Dwarf_Off off; + Dwarf_Off next_off = 0; + Dwarf_CFI_Entry entry; + while ((res = dwarf_next_cfi (e_ident, data, is_eh, off = next_off, + &next_off, &entry)) == 0) + { + printf ("[%" PRId64 "] ", off); + if (dwarf_cfi_cie_p (&entry)) + printf ("CIE augmentation=\"%s\"\n", entry.cie.augmentation); + else + { + printf ("FDE cie=[%" PRId64 "]\n", entry.fde.CIE_pointer); + + Dwarf_Off cie_off = entry.fde.CIE_pointer; + Dwarf_Off cie_off_next; + Dwarf_CFI_Entry cie_entry; + if (dwarf_next_cfi (e_ident, data, is_eh, cie_off, &cie_off_next, + &cie_entry) != 0 + || !dwarf_cfi_cie_p (&cie_entry)) + error (EXIT_FAILURE, 0, "FDE doesn't point to CIE"); + } + } + + if (res < 0) + error (EXIT_FAILURE, 0, "dwarf_next_cfi failed: %s\n", + dwarf_errmsg (-1)); +} + +int main (int argc, char *argv[]) +{ + if (argc != 2) + error (EXIT_FAILURE, 0, "need file name argument"); + + const char *file = argv[1]; + printf ("%s\n", file); + + int fd = open (file, O_RDONLY); + if (fd == -1) + error (EXIT_FAILURE, errno, "cannot open input file `%s'", file); + + elf_version (EV_CURRENT); + + Elf *elf = elf_begin (fd, ELF_C_READ, NULL); + if (elf == NULL) + error (EXIT_FAILURE, 0, "cannot create ELF descriptor: %s", + elf_errmsg (-1)); + + size_t esize; + const unsigned char *ident + = (const unsigned char *) elf_getident (elf, &esize); + + if (ident == NULL || esize < EI_NIDENT) + error (EXIT_FAILURE, 0, "no, or too small, ELF ident"); + + GElf_Ehdr ehdr; + if (gelf_getehdr (elf, &ehdr) == NULL) + error (EXIT_FAILURE, 0, "cannot get the ELF header: %s\n", elf_errmsg (-1)); + + size_t strndx = ehdr.e_shstrndx; + + int num_threads = 4; + pthread_t threads[num_threads]; + ThreadData thread_data; + + Elf_Scn *scn = NULL; + while ((scn = elf_nextscn (elf, scn)) != NULL) + { + GElf_Shdr shdr; + if (gelf_getshdr (scn, &shdr) != NULL) + { + char *name = elf_strptr (elf, strndx, (size_t) shdr.sh_name); + if (name != NULL && shdr.sh_type == SHT_PROGBITS) + { + bool is_eh = false; + if (strcmp (name, ".eh_frame") == 0) + is_eh = true; + else if (strcmp (name, ".debug_frame") == 0 + || strcmp (name, ".zdebug_frame") == 0) + is_eh = false; + else + continue; + + thread_data.name = name; + thread_data.e_ident = ident; + thread_data.scn = scn; + thread_data.is_eh = is_eh; + + for (int i = 0; i < num_threads; i++) + if (pthread_create (&threads[i], NULL, thread_work, + &thread_data) != 0) + { + perror ("pthread_create"); + + for (int j = 0; j < i; j++) + pthread_cancel (threads[j]); + + elf_end (elf); + close (fd); + return 1; + } + + for (int i = 0; i < num_threads; i++) + if (pthread_join (threads[i], NULL) != 0) + perror ("pthread_join"); + } + } + } + + elf_end (elf); + close (fd); + + return 0; +} diff --git a/tests/run-eu-search-cfi.sh b/tests/run-eu-search-cfi.sh new file mode 100755 index 00000000..e86232cc --- /dev/null +++ b/tests/run-eu-search-cfi.sh @@ -0,0 +1,31 @@ +#! /bin/sh +# Data race test for parallelized next_cfi +# Copyright (C) 2015, 2018 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. $srcdir/thread-safety-subr.sh + +check_thread_safety_enabled + +cfi_test_files=("testfile11" "testfile12" + "testfilearm" "testfileaarch64" + "testfileppc32" "testfileppc64") + +testfiles "${cfi_test_files[@]}" + +for file in "${cfi_test_files[@]}"; do + testrun ${abs_builddir}/eu_search_cfi $file +done From patchwork Mon Jan 20 03:20:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105082 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 CB2B63858C2B for ; Mon, 20 Jan 2025 03:25:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB2B63858C2B Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=b7YOjfqa X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 37E9D3858408 for ; Mon, 20 Jan 2025 03:21:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37E9D3858408 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 37E9D3858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343262; cv=none; b=DTzyeWIYPlzJ0lhBXTHtTL/lGyuH8g1M3sZ//1LSkScqaak1sZWH4j8lh33kM340fm35tCduivycEC0nm+k2ch8mMSsG2mgcNhKHUhb/QWCopewvQl92QAg/UtTLZoCn5doqlBmNmqOGDIKlOb29wn/81Y7E7MMXjWSLYlcmSmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343262; c=relaxed/simple; bh=bFLODGakDmXUXB/LX/DPaS4Bx04Q8SbTDOeoI6H3VJ4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gSTPAK0vn8zdGIZVKmIrGSqHQsYrGOqZTGkv8lXmdSW1SDc9zRgO5tOuzuSkE3XtSCqigqtnuDkxt0pEiFehYTST18B6bW4E3Pa7qxfQYaKRlZgV6EBW2FIKrTKhPFn/0OCthL9rdYzHS8yvKkHBSGN7AKMKayTPFPLVlb2ZFWk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37E9D3858408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343262; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XofMrHlp28+yPPjBS4V3mNg4jhq+fVyL/iGnPffOBXE=; b=b7YOjfqabxvhPrsH8rroWr1VCiCsyc9ghXSWLnbiCE64rzN52sjKj5btTQVTuH3NKMH6jG U9Dmuzt1FyXhBomxHrDsISVk83iYJcnoCubypnXtBlFhWqXVydSQX/Z29sGGMmQcfRUctA bjcR0mEJjfI6MmsLXR1zY7bY2HiuAe4= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-253-rXIioG31OA-NdZL66dWD7g-1; Sun, 19 Jan 2025 22:20:59 -0500 X-MC-Unique: rXIioG31OA-NdZL66dWD7g-1 X-Mimecast-MFC-AGG-ID: rXIioG31OA-NdZL66dWD7g Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 162E719560B0; Mon, 20 Jan 2025 03:20:58 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D1DB6195608A; Mon, 20 Jan 2025 03:20:56 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Heather McIntyre , Aaron Merey , Mark Wielaard Subject: [PATCH 13/15 v4] Add tests/run-eu-search-macros.sh Date: Sun, 19 Jan 2025 22:20:39 -0500 Message-ID: <20250120032041.280173-13-amerey@redhat.com> In-Reply-To: <20250120032041.280173-1-amerey@redhat.com> References: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: MRcBbBUiynujaFCVsSbjyAByHPM8JT_sZ9txvoyf7cg_1737343258 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 * tests/.gitignore: Add eu_search_macros.sh * tests/Makefile.am: Add eu_search_macros, run-eu-search-macros.sh. * tests/eu_search_macros.c: New file. * tests/run-eu-search-macros.sh: New file. Signed-off-by: Heather S. McIntyre Signed-off-by: Aaron Merey Signed-off-by: Mark Wielaard --- v3: https://patchwork.sourceware.org/project/elfutils/patch/20240802233847.690564-9-amerey@redhat.com/ Changes in v4: run-eu-search-tests.sh dropped and macros search_tree tests moved to run-eu-search-macros.sh. Formatting changes and improved lock contention in eu_search_macros.sh tests/.gitignore | 1 + tests/Makefile.am | 8 +- tests/eu_search_macros.c | 174 ++++++++++++++++++++++++++++++++++ tests/run-eu-search-macros.sh | 28 ++++++ 4 files changed, 208 insertions(+), 3 deletions(-) create mode 100644 tests/eu_search_macros.c create mode 100755 tests/run-eu-search-macros.sh diff --git a/tests/.gitignore b/tests/.gitignore index bf17d646..9fb56361 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -68,6 +68,7 @@ /elf-print-reloc-syms /emptyfile /eu_search_cfi +/eu_search_macros /fillfile /find-prologues /funcretval diff --git a/tests/Makefile.am b/tests/Makefile.am index 0eb2048d..a1bb6d6a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -65,7 +65,7 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ msg_tst system-elf-libelf-test system-elf-gelf-test \ nvidia_extended_linemap_libdw elf-print-reloc-syms \ cu-dwp-section-info declfiles \ - eu_search_cfi \ + eu_search_cfi eu_search_macros \ $(asm_TESTS) asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ @@ -218,7 +218,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-readelf-dw-form-indirect.sh run-strip-largealign.sh \ run-readelf-Dd.sh run-dwfl-core-noncontig.sh run-cu-dwp-section-info.sh \ run-declfiles.sh \ - run-sysroot.sh run-eu-search-cfi.sh + run-sysroot.sh run-eu-search-cfi.sh run-eu-search-macros.sh if !BIARCH export ELFUTILS_DISABLE_BIARCH = 1 @@ -690,7 +690,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ testfile-dwp-cu-index-overflow.source \ testfile-define-file.bz2 \ testfile-sysroot.tar.bz2 run-sysroot.sh run-debuginfod-seekable.sh \ - run-eu-search-cfi.sh \ + run-eu-search-cfi.sh run-eu-search-macros.sh \ thread-safety-subr.sh @@ -877,7 +877,9 @@ elf_print_reloc_syms_LDADD = $(libelf) cu_dwp_section_info_LDADD = $(libdw) declfiles_LDADD = $(libdw) eu_search_cfi_LDFLAGS = $(if $(filter undefined,$(origin USE_LOCKS)),-pthread) $(AM_LDFLAGS) +eu_search_macros_LDFLAGS = $(if $(filter undefined,$(origin USE_LOCKS)),-pthread) $(AM_LDFLAGS) eu_search_cfi_LDADD = $(libeu) $(libelf) $(libdw) +eu_search_macros_LDADD = $(libdw) # We want to test the libelf headers against the system elf.h header. # Don't include any -I CPPFLAGS. Except when we install our own elf.h. diff --git a/tests/eu_search_macros.c b/tests/eu_search_macros.c new file mode 100644 index 00000000..24c570d4 --- /dev/null +++ b/tests/eu_search_macros.c @@ -0,0 +1,174 @@ +/* Test program for eu_search_macros + Copyright (C) 2023 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see. */ + +#include +#include ELFUTILS_HEADER(dw) +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void *thread_work (void * arg); +static int mac (Dwarf_Macro *macro, void *arg); +static int include (Dwarf_Off macoff, ptrdiff_t token); + +static Dwarf *dbg; +static ptrdiff_t cuoff; + +static void *thread_work (void *arg __attribute__ ((unused))) +{ + Dwarf_Die cudie_mem, *cudie = dwarf_offdie (dbg, cuoff, &cudie_mem); + for (ptrdiff_t off = DWARF_GETMACROS_START; + (off = dwarf_getmacros (cudie, mac, dbg, off));) + { + if (off != 0) + { + puts (dwarf_errmsg (dwarf_errno ())); + break; + } + } + + return NULL; +} + +static int include (Dwarf_Off macoff, ptrdiff_t token) +{ + while ((token = dwarf_getmacros_off (dbg, macoff, mac, dbg, token)) != 0) + { + if (token == -1) + { + puts (dwarf_errmsg (dwarf_errno ())); + return 1; + } + } + return 0; +} + +static int +mac (Dwarf_Macro *macro, void *arg __attribute__ ((unused))) +{ + unsigned int opcode; + dwarf_macro_opcode (macro, &opcode); + switch (opcode) + { + case DW_MACRO_import: + { + Dwarf_Attribute at; + if (dwarf_macro_param (macro, 0, &at) != 0) + return DWARF_CB_ABORT; + + Dwarf_Word w; + if (dwarf_formudata (&at, &w) != 0) + return DWARF_CB_ABORT; + if (include (w, DWARF_GETMACROS_START) != 0) + return DWARF_CB_ABORT; + break; + } + + case DW_MACRO_start_file: + { + Dwarf_Files *files; + size_t nfiles; + if (dwarf_macro_getsrcfiles (dbg, macro, &files, &nfiles) < 0) + { + printf ("dwarf_macro_getsrcfiles: %s\n", + dwarf_errmsg (dwarf_errno ())); + return DWARF_CB_ABORT; + } + + Dwarf_Word w = 0; + if (dwarf_macro_param2 (macro, &w, NULL) != 0) + return DWARF_CB_ABORT; + + if (dwarf_filesrc (files, (size_t) w, NULL, NULL) == NULL) + return DWARF_CB_ABORT; + break; + } + + case DW_MACINFO_define: + case DW_MACRO_define_strp: + { + const char *value; + if (dwarf_macro_param2(macro, NULL, &value) != 0) + return DWARF_CB_ABORT; + break; + } + + case DW_MACINFO_undef: + case DW_MACRO_undef_strp: + break; + + default: + { + size_t paramcnt; + if (dwarf_macro_getparamcnt (macro, ¶mcnt) != 0) + return DWARF_CB_ABORT; + break; + } + } + + return DWARF_CB_OK; +} + +int main (int argc, char *argv[]) +{ + assert (argc == 3); + const char *name = argv[1]; + + int fd = open (name, O_RDONLY); + dbg = dwarf_begin (fd, DWARF_C_READ); + cuoff = strtol (argv[2], NULL, 0); + + int num_threads = 4; + pthread_t threads[num_threads]; + + for (int i = 0; i < num_threads; i++) + { + if (pthread_create (&threads[i], NULL, thread_work, NULL) != 0) + { + perror ("Failed to create thread"); + + for (int j = 0; j < i; j++) + pthread_cancel (threads[j]); + + dwarf_end (dbg); + close (fd); + return 1; + } + } + + for (int i = 0; i < num_threads; i++) + { + if (pthread_join (threads[i], NULL) != 0) + { + perror ("Failed to join thread"); + } + } + + dwarf_end (dbg); + close (fd); + + return 0; +} diff --git a/tests/run-eu-search-macros.sh b/tests/run-eu-search-macros.sh new file mode 100755 index 00000000..3eb5a76f --- /dev/null +++ b/tests/run-eu-search-macros.sh @@ -0,0 +1,28 @@ +#! /bin/sh +# Data race test for parallelizd dwarf-getmacros +# Copyright (C) 2015, 2018 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. $srcdir/thread-safety-subr.sh + +check_thread_safety_enabled + +testfiles testfile51 testfile-macros testfile-macros-0xff + +testrun ${abs_builddir}/eu_search_macros testfile51 0xb +testrun ${abs_builddir}/eu_search_macros testfile51 0x84 +testrun ${abs_builddir}/eu_search_macros testfile-macros 0xb +testrun ${abs_builddir}/eu_search_macros testfile-macros-0xff 0xb From patchwork Mon Jan 20 03:20:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105080 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 AD92B385840C for ; Mon, 20 Jan 2025 03:24:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD92B385840C Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XmgpBvmX X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 3CA913858415 for ; Mon, 20 Jan 2025 03:21:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CA913858415 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3CA913858415 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343264; cv=none; b=BnAST9Gvz1iOApZ18b+oQ2pRDwcxp42k1uqMMzYXAmCYEKBkFWGjeXwwf7OW6jQMWqyRR0GsHtf/B/iHreTQQ1Juxc8egi1bO9toJHhK4luUTnw6J6/WdJatBg+pEvBXtGq6R5C0lPergBrNGjQoNaFkWN0LjcFV5FlkxifhdzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343264; c=relaxed/simple; bh=xNy7eB7Y8B8q9hlLlQ9PXZws3ySStN77H9JoscvCa7k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=r3dS+9YzbjVA53cRt0xDVLMvJfiAzTBLjYLeaXNUhU7jZbUsZpnoD0KDEbh7NmXcS9tZ3oZpdodmmtdIe636ya8xNTIp46RelX5i4Osdfb9/X3doLciH21bTHDWZc7sUAqKwja6tR71VJqKdaDsOcpdrvqYdXz1HOVVPmpo6oF8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CA913858415 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343264; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kvwGRDAFs+/La4/eJCONqBk5CbPsq0tA0gXhW7VpY50=; b=XmgpBvmX+sUVelo6rYaTmPw4CblD7Ny2YQw1arayJgW9jha9Uf+zOYKn8/f2i8AoIgtUBl 6OmcWWjJq+XNgJwlqkR3vKG8u4eq6JNCRSGu3dcVwlcQ4PT0O6C1G78SGsb04romf0KrLt RngFcEL4pWsvZ9jD3cScVsL7Kr232TE= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-388-RjXrkatlN2qSAjRnhY7yqA-1; Sun, 19 Jan 2025 22:21:00 -0500 X-MC-Unique: RjXrkatlN2qSAjRnhY7yqA-1 X-Mimecast-MFC-AGG-ID: RjXrkatlN2qSAjRnhY7yqA Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5E7EC1956048; Mon, 20 Jan 2025 03:20:59 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5EC96195608A; Mon, 20 Jan 2025 03:20:58 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Heather McIntyre , Aaron Merey , Mark Wielaard Subject: [PATCH 14/15 v4] Add tests/run-eu-search-lines.sh Date: Sun, 19 Jan 2025 22:20:40 -0500 Message-ID: <20250120032041.280173-14-amerey@redhat.com> In-Reply-To: <20250120032041.280173-1-amerey@redhat.com> References: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: tUzsTMl1DxyTUL6VbIUG4QUo86Ja_fsNRKqR-ldktR8_1737343259 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 * tests/.gitignore: Add eu_search-lines. * tests/Makefile.am: Add eu_search_lines, run-eu-search-lines.sh. * tests/eu_search_lines.c: New file. * tests/run-eu-search-lines.sh: New file. Signed-off-by: Heather S. McIntyre Signed-off-by: Aaron Merey Signed-off-by: Mark Wielaard --- v3: https://patchwork.sourceware.org/project/elfutils/patch/20240802233847.690564-9-amerey@redhat.com/ Changes in v4: run-eu-search-tests.sh dropped and lines search_tree tests moved to run-eu-search-lines.sh. Formatting changes and improved lock contention in eu_search_lines.c. tests/.gitignore | 1 + tests/Makefile.am | 9 +- tests/eu_search_lines.c | 211 +++++++++++++++++++++++++++++++++++ tests/run-eu-search-lines.sh | 31 +++++ 4 files changed, 249 insertions(+), 3 deletions(-) create mode 100644 tests/eu_search_lines.c create mode 100755 tests/run-eu-search-lines.sh diff --git a/tests/.gitignore b/tests/.gitignore index 9fb56361..26bf6059 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -69,6 +69,7 @@ /emptyfile /eu_search_cfi /eu_search_macros +/eu_search_lines /fillfile /find-prologues /funcretval diff --git a/tests/Makefile.am b/tests/Makefile.am index a1bb6d6a..570d5f72 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -65,7 +65,7 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ msg_tst system-elf-libelf-test system-elf-gelf-test \ nvidia_extended_linemap_libdw elf-print-reloc-syms \ cu-dwp-section-info declfiles \ - eu_search_cfi eu_search_macros \ + eu_search_cfi eu_search_macros eu_search_lines \ $(asm_TESTS) asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ @@ -218,7 +218,8 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-readelf-dw-form-indirect.sh run-strip-largealign.sh \ run-readelf-Dd.sh run-dwfl-core-noncontig.sh run-cu-dwp-section-info.sh \ run-declfiles.sh \ - run-sysroot.sh run-eu-search-cfi.sh run-eu-search-macros.sh + run-sysroot.sh run-eu-search-cfi.sh run-eu-search-macros.sh \ + run-eu-search-lines.sh if !BIARCH export ELFUTILS_DISABLE_BIARCH = 1 @@ -690,7 +691,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ testfile-dwp-cu-index-overflow.source \ testfile-define-file.bz2 \ testfile-sysroot.tar.bz2 run-sysroot.sh run-debuginfod-seekable.sh \ - run-eu-search-cfi.sh run-eu-search-macros.sh \ + run-eu-search-cfi.sh run-eu-search-macros.sh run-eu-search-lines.sh \ thread-safety-subr.sh @@ -877,8 +878,10 @@ elf_print_reloc_syms_LDADD = $(libelf) cu_dwp_section_info_LDADD = $(libdw) declfiles_LDADD = $(libdw) eu_search_cfi_LDFLAGS = $(if $(filter undefined,$(origin USE_LOCKS)),-pthread) $(AM_LDFLAGS) +eu_search_lines_LDFLAGS = $(if $(filter undefined,$(origin USE_LOCKS)),-pthread) $(AM_LDFLAGS) eu_search_macros_LDFLAGS = $(if $(filter undefined,$(origin USE_LOCKS)),-pthread) $(AM_LDFLAGS) eu_search_cfi_LDADD = $(libeu) $(libelf) $(libdw) +eu_search_lines_LDADD = $(libdw) $(libelf) eu_search_macros_LDADD = $(libdw) # We want to test the libelf headers against the system elf.h header. diff --git a/tests/eu_search_lines.c b/tests/eu_search_lines.c new file mode 100644 index 00000000..d5a7de6d --- /dev/null +++ b/tests/eu_search_lines.c @@ -0,0 +1,211 @@ +/* Test program for eu_search_lines. + Copyright (C) 2023 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see. */ + +#include +#include +#include +#include +#include ELFUTILS_HEADER(dw) +#include +#include +#include +#include +#include + +static Dwarf *dbg; + +static void *thread_work (void *arg) +{ + int *res = (int *) arg; + + *res = 0; + Dwarf_Off cuoff = 0; + Dwarf_Off old_cuoff = 0; + size_t hsize; + Dwarf_Off ao; + uint8_t asz; + uint8_t osz; + while (dwarf_nextcu (dbg, cuoff, &cuoff, &hsize, &ao, &asz, &osz) == 0) + { + printf ("cuhl = %zu, o = %llu, asz = %hhu, osz = %hhu, ncu = %llu\n", + hsize, (unsigned long long int) ao, + asz, osz, (unsigned long long int) cuoff); + + // Get the DIE for the CU. + Dwarf_Die die; + if (dwarf_offdie (dbg, old_cuoff + hsize, &die) == NULL) + { + printf ("cannot get CU die\n"); + *res = 1; + break; + } + + old_cuoff = cuoff; + + Dwarf_Lines *lb; + size_t nlb; + if (dwarf_getsrclines (&die, &lb, &nlb) != 0) + { + printf ("cannot get lines\n"); + *res = 1; + break; + } + + printf (" %zu lines\n", nlb); + + for (size_t i = 0; i < nlb; ++i) + { + Dwarf_Line *l = dwarf_onesrcline (lb, i); + if (l == NULL) + { + printf ("cannot get individual line\n"); + *res = 1; + break; + } + + Dwarf_Addr addr; + if (dwarf_lineaddr (l, &addr) != 0) + addr = 0; + + const char *file = dwarf_linesrc (l, NULL, NULL); + int line; + + if (dwarf_lineno (l, &line) != 0) + line = 0; + + printf ("%" PRIx64 ": %s:%d:", (uint64_t) addr, file ? : "???", line); + + // Getting the file path through the Dwarf_Files should + // result in the same path. + Dwarf_Files *files; + size_t idx; + if (dwarf_line_file (l, &files, &idx) != 0) + { + printf ("cannot get file from line (%zd): %s\n", + i, dwarf_errmsg (-1)); + *res = 1; + break; + } + + const char *path = dwarf_filesrc (files, idx, NULL, NULL); + if ((path == NULL && file != NULL) || + (path != NULL && file == NULL) || + (strcmp (file, path) != 0)) + { + printf ("line %zd srcline (%s) != file srcline (%s)\n", + i, file ? : "???", path ? : "???"); + *res = 1; + break; + } + + int column; + + if (dwarf_linecol (l, &column) != 0) + column = 0; + if (column >= 0) + printf ("%d:", column); + + bool is_stmt; + if (dwarf_linebeginstatement (l, &is_stmt) != 0) + is_stmt = false; + bool end_sequence; + if (dwarf_lineendsequence (l, &end_sequence) != 0) + end_sequence = false; + bool basic_block; + if (dwarf_lineblock (l, &basic_block) != 0) + basic_block = false; + bool prologue_end; + if (dwarf_lineprologueend (l, &prologue_end) != 0) + prologue_end = false; + bool epilogue_begin; + if (dwarf_lineepiloguebegin (l, &epilogue_begin) != 0) + epilogue_begin = false; + + printf (" is_stmt:%s, end_seq:%s, bb:%s, prologue:%s, epilogue:%s\n", + is_stmt ? "yes" : "no", end_sequence ? "yes" : "no", + basic_block ? "yes" : "no", prologue_end ? "yes" : "no", + epilogue_begin ? "yes" : "no"); + } + } + + return NULL; +} + +int main (int argc, char *argv[]) +{ + if (argc != 2) + { + printf ("Usage: %s \n", argv[0]); + return 1; + } + + char *name = argv[1]; + int fd = open (name, O_RDONLY); + if (fd < 0) + { + printf ("%s not usable: %s\n", name, dwarf_errmsg (-1)); + return 1; + } + + dbg = dwarf_begin (fd, DWARF_C_READ); + if (dbg == NULL) + { + printf ("%s not usable: %s\n", name, dwarf_errmsg (-1)); + close (fd); + return 1; + } + + printf ("checking %s\n", name); + + int num_threads = 4; + pthread_t threads[num_threads]; + int thread_results[num_threads]; + + for (int i = 0; i < num_threads; ++i) + { + if (pthread_create (&threads[i], NULL, thread_work, + &thread_results[i]) != 0) + { + perror ("Failed to create thread"); + + for (int j = 0; j < i; j++) + pthread_cancel (threads[j]); + + dwarf_end (dbg); + close (fd); + return 1; + } + } + + int res = 0; + for (int i = 0; i < num_threads; ++i) + { + if (pthread_join (threads[i], NULL) != 0) + { + perror ("Failed to join thread"); + res = 1; + break; + } + + res |= thread_results[i]; + } + + dwarf_end (dbg); + close (fd); + + return res; +} diff --git a/tests/run-eu-search-lines.sh b/tests/run-eu-search-lines.sh new file mode 100755 index 00000000..2108ab8f --- /dev/null +++ b/tests/run-eu-search-lines.sh @@ -0,0 +1,31 @@ +#! /bin/sh +# Data race test for parallelized get-lines +# Copyright (C) 2015, 2018 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. $srcdir/thread-safety-subr.sh + +check_thread_safety_enabled + +lines_testfiles=("testfile" "testfile2" "testfilenolines") + +testfiles "${lines_testfiles[@]}" + +for file in "${lines_testfiles[@]}"; do + testrun ${abs_builddir}/eu_search_lines $file +done + +exit 0 From patchwork Mon Jan 20 03:20:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 105076 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 6B5053858C52 for ; Mon, 20 Jan 2025 03:23:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B5053858C52 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DrWRJ9Vh X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 5E5E83858416 for ; Mon, 20 Jan 2025 03:21:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E5E83858416 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5E5E83858416 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343265; cv=none; b=QueV1GwWeP5GqbTigcBbLSTo/JYmLO7e0u0LaL5pY8Ikyk3c3P8FerNV6G+iBY+3lFrqUOSXoUvrNXzhvRKQKbnpRcu+s3wuPpWm0z48k9ceEimHHh7e0jWIAqYytZ+9izh2yYoruxCr+7T4gNazadXlPYJUWxr+XbxNw2gN5C0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737343265; c=relaxed/simple; bh=CILRMDPyw1a9Oz4PE9pN2EYpcNM6UhFleMbX0C1HJKU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=V8mKK78XTrivjkDWGF3wusYrrP/ULlIMCGdpZEwuujpNB1mYxgrSFMEsNN0GAvnTBmUVZGM8OfavQRV8B9A7epngUH9ehDlmyNF01RLSat8TmqSlECcY6xrLy01omV+Go8OUliHYnyAkTnjGxXwsk8bFoetvnP2N9vbN9doEmoU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E5E83858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737343265; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vSRc4IQpHzMVeAObbNfkK7El8uxvp8iClleYluw/LA8=; b=DrWRJ9Vh5zmpN2HTnT89LIuhskT5yEeHthCUKceMZjU2ydsqAOBFaCbEkfFAzkcw1Ll9FF 7r5V9anorOMCQr4TxhHnokDCFyhQaOr1JnaXLTYL9ZsvRr+3QBsX5d/SFQcOmMBW3HJ1X/ xFiIVhEwvhLX+If4hIyA5BHnzEwd714= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-9-sgg9TRPwN6qQw4Ov9cSWbw-1; Sun, 19 Jan 2025 22:21:01 -0500 X-MC-Unique: sgg9TRPwN6qQw4Ov9cSWbw-1 X-Mimecast-MFC-AGG-ID: sgg9TRPwN6qQw4Ov9cSWbw Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B150319560B0; Mon, 20 Jan 2025 03:21:00 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A44AA1956094; Mon, 20 Jan 2025 03:20:59 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: Heather McIntyre , Aaron Merey , Mark Wielaard Subject: [PATCH 15/15 v4] Add tests/run-eu-search-die.sh Date: Sun, 19 Jan 2025 22:20:41 -0500 Message-ID: <20250120032041.280173-15-amerey@redhat.com> In-Reply-To: <20250120032041.280173-1-amerey@redhat.com> References: <20250120032041.280173-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 7gkZGNQt-EGPe46bRtErcJha-RPxiB6pV8zAAdre0Ro_1737343261 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 * tests/.gitignore: Add eu_search_die. * tests/Makefile.am: Add eu_search_die, run-eu-search-die.sh. * tests/eu_search_die.c: New file. * tests/run-eu-search-die.sh: New file. Signed-off-by: Heather S. McIntyre Signed-off-by: Aaron Merey Signed-off-by: Mark Wielaard --- v3: https://patchwork.sourceware.org/project/elfutils/patch/20240802233847.690564-9-amerey@redhat.com/ Changes in v4: run-eu-search-tests.sh dropped and die search_tree tests moved to run-eu-search-die.sh. Formatting changes and improved lock contention in eu_search_die.c. tests/.gitignore | 1 + tests/Makefile.am | 8 +- tests/eu_search_die.c | 226 +++++++++++++++++++++++++++++++++++++ tests/run-eu-search-die.sh | 34 ++++++ 4 files changed, 266 insertions(+), 3 deletions(-) create mode 100644 tests/eu_search_die.c create mode 100755 tests/run-eu-search-die.sh diff --git a/tests/.gitignore b/tests/.gitignore index 26bf6059..f8869b40 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -70,6 +70,7 @@ /eu_search_cfi /eu_search_macros /eu_search_lines +/eu_search_die /fillfile /find-prologues /funcretval diff --git a/tests/Makefile.am b/tests/Makefile.am index 570d5f72..8f8972cb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -65,7 +65,7 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ msg_tst system-elf-libelf-test system-elf-gelf-test \ nvidia_extended_linemap_libdw elf-print-reloc-syms \ cu-dwp-section-info declfiles \ - eu_search_cfi eu_search_macros eu_search_lines \ + eu_search_cfi eu_search_macros eu_search_lines eu_search_die \ $(asm_TESTS) asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ @@ -219,7 +219,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-readelf-Dd.sh run-dwfl-core-noncontig.sh run-cu-dwp-section-info.sh \ run-declfiles.sh \ run-sysroot.sh run-eu-search-cfi.sh run-eu-search-macros.sh \ - run-eu-search-lines.sh + run-eu-search-lines.sh run-eu-search-die.sh if !BIARCH export ELFUTILS_DISABLE_BIARCH = 1 @@ -692,7 +692,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ testfile-define-file.bz2 \ testfile-sysroot.tar.bz2 run-sysroot.sh run-debuginfod-seekable.sh \ run-eu-search-cfi.sh run-eu-search-macros.sh run-eu-search-lines.sh \ - thread-safety-subr.sh + run-eu-search-die.sh thread-safety-subr.sh if USE_HELGRIND @@ -880,9 +880,11 @@ declfiles_LDADD = $(libdw) eu_search_cfi_LDFLAGS = $(if $(filter undefined,$(origin USE_LOCKS)),-pthread) $(AM_LDFLAGS) eu_search_lines_LDFLAGS = $(if $(filter undefined,$(origin USE_LOCKS)),-pthread) $(AM_LDFLAGS) eu_search_macros_LDFLAGS = $(if $(filter undefined,$(origin USE_LOCKS)),-pthread) $(AM_LDFLAGS) +eu_search_die_LDFLAGS = $(if $(filter undefined,$(origin USE_LOCKS)),-pthread) $(AM_LDFLAGS) eu_search_cfi_LDADD = $(libeu) $(libelf) $(libdw) eu_search_lines_LDADD = $(libdw) $(libelf) eu_search_macros_LDADD = $(libdw) +eu_search_die_LDADD = $(libdw) # We want to test the libelf headers against the system elf.h header. # Don't include any -I CPPFLAGS. Except when we install our own elf.h. diff --git a/tests/eu_search_die.c b/tests/eu_search_die.c new file mode 100644 index 00000000..a4510d3b --- /dev/null +++ b/tests/eu_search_die.c @@ -0,0 +1,226 @@ +/* Test program for eu_search_die. + Copyright (C) 2023 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see. */ + +#include +#include ELFUTILS_HEADER(dw) +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int check_die (Dwarf_Die *die, Dwarf *dbg); +static int check_dbg (Dwarf *dbg); + +static Dwarf *dwarf; + +static void *thread_work (void *arg) +{ + int *res = (int *) arg; + *res = check_dbg (dwarf); + return NULL; +} + +static int check_die (Dwarf_Die *die, Dwarf *dbg) +{ + if (dwarf_tag (die) == DW_TAG_invalid) + { + printf ("Invalid die\n"); + return -1; + } + + int res = 0; + void *addr = die->addr; + Dwarf_Die die2; + if (dwarf_die_addr_die (dbg, addr, &die2) == NULL) + { + printf ("Bad die addr die at offset %" PRIx64 "\n", + dwarf_dieoffset (die)); + res = -1; + } + + if (dwarf_tag (die) != dwarf_tag (&die2)) + { + printf ("Tags differ for die at offset %" PRIx64 "\n", + dwarf_dieoffset (die)); + res = -1; + } + + if (dwarf_cuoffset (die) != dwarf_cuoffset (&die2)) + { + printf ("CU offsets differ for die at offset %" PRIx64 "\n", + dwarf_dieoffset (die)); + res = -1; + } + + Dwarf_Die child; + if (dwarf_child (die, &child) == 0) + res |= check_die (&child, dbg); + + Dwarf_Die sibling; + if (dwarf_siblingof (die, &sibling) == 0) + res |= check_die (&sibling, dbg); + + return res; +} + +static int check_dbg (Dwarf *dbg) +{ + int res = 0; + Dwarf_Off off = 0; + Dwarf_Off old_off = 0; + size_t hsize; + Dwarf_Off abbrev; + uint8_t addresssize; + uint8_t offsetsize; + + while (dwarf_nextcu (dbg, off, &off, &hsize, &abbrev, + &addresssize, &offsetsize) == 0) + { + Dwarf_Die die; + if (dwarf_offdie (dbg, old_off + hsize, &die) != NULL) + { + printf ("checking CU at %" PRIx64 "\n", old_off); + res |= check_die (&die, dbg); + } + + old_off = off; + } + + // Same for type... + Dwarf_Half version; + uint64_t typesig; + Dwarf_Off typeoff; + off = 0; + old_off = 0; + + while (dwarf_next_unit (dbg, off, &off, &hsize, &version, + &abbrev, &addresssize, &offsetsize, &typesig, &typeoff) == 0) + { + Dwarf_Die die; + if (dwarf_offdie_types (dbg, old_off + hsize, &die) != NULL) + { + printf ("checking TU at %" PRIx64 "\n", old_off); + res |= check_die (&die, dbg); + } + + // We should have seen this already, but double check... + if (dwarf_offdie_types (dbg, old_off + typeoff, &die) != NULL) + { + printf ("checking Type DIE at %" PRIx64 "\n", + old_off + hsize + typeoff); + res |= check_die (&die, dbg); + } + + old_off = off; + } + + Dwarf *alt = dwarf_getalt (dbg); + + if (alt != NULL) + { + printf ("checking alt debug\n"); + res |= check_dbg (alt); + } + + // Split or Type Dwarf_Dies gotten through dwarf_get_units. + Dwarf_CU *cu = NULL; + Dwarf_Die subdie; + uint8_t unit_type; + while (dwarf_get_units (dbg, cu, &cu, NULL, &unit_type, NULL, &subdie) == 0) + { + if (dwarf_tag (&subdie) != DW_TAG_invalid) + { + printf ("checking %" PRIx8 " subdie\n", unit_type); + res |= check_die (&subdie, dbg); + } + } + + return res; +} + +int main (int argc, char *argv[]) +{ + if (argc < 2) + { + printf ("No file given.\n"); + return -1; + } + + const char *name = argv[1]; + int fd = open (name, O_RDONLY); + if (fd < 0) + { + printf ("Cannot open '%s': %s\n", name, strerror (errno)); + return -1; + } + + dwarf = dwarf_begin (fd, DWARF_C_READ); + if (dwarf == NULL) + { + printf ("Not a Dwarf file '%s': %s\n", name, dwarf_errmsg (-1)); + close (fd); + return -1; + } + + printf ("checking %s\n", name); + + int num_threads = 4; + pthread_t threads[num_threads]; + int thread_results[num_threads]; + + for (int i = 0; i < num_threads; i++) + { + if (pthread_create (&threads[i], NULL, thread_work, + &thread_results[i]) != 0) + { + perror ("Failed to create thread"); + for (int j = 0; j < i; j++) + pthread_cancel (threads[j]); + + dwarf_end (dwarf); + close (fd); + return 1; + } + } + + int res = 0; + for (int i = 0; i < num_threads; i++) + { + if (pthread_join (threads[i], NULL) != 0) + { + perror ("Failed to join thread"); + res = 1; + break; + } + + res |= thread_results[i]; + } + + dwarf_end (dwarf); + close (fd); + + return res; +} diff --git a/tests/run-eu-search-die.sh b/tests/run-eu-search-die.sh new file mode 100755 index 00000000..bc8a5959 --- /dev/null +++ b/tests/run-eu-search-die.sh @@ -0,0 +1,34 @@ +#! /bin/sh +# Data race test for parallelized dwarf-die-addr-die +# Copyright (C) 2015, 2018 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. $srcdir/thread-safety-subr.sh + +check_thread_safety_enabled + +die_test_files=("testfile-debug-types" + "testfile_multi_main" "testfile_multi.dwz" + "testfilebazdbgppc64.debug" + "testfile-dwarf-4" "testfile-dwarf-5" + "testfile-splitdwarf-4" "testfile-hello4.dwo" "testfile-world4.dwo" + "testfile-splitdwarf-5" "testfile-hello5.dwo" "testfile-world5.dwo") + +testfiles "${die_test_files[@]}" + +for file in "${die_test_files[@]}"; do + testrun ${abs_builddir}/eu_search_die $file +done