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