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