From patchwork Thu Aug 8 09:47:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 95503 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 BC5BE3858429 for ; Thu, 8 Aug 2024 09:47:20 +0000 (GMT) X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@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 210A73858D34 for ; Thu, 8 Aug 2024 09:47:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 210A73858D34 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 210A73858D34 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=1723110434; cv=none; b=VKDVT29GljsJwBv23HOqK9HiATewUbS8z8Mf97Blw4UvhooRgz+xhE+WxMVno6QNyaQ1R6yNZx2p6wYUrxIAdzWeUPU43ieFOgHJDaS/YcAYIorPwGBZJf7uo09BCWRJIYJFJFee5wVLsFXlVvWR8htslNCGHHGL3dFE61lOMZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723110434; c=relaxed/simple; bh=PX6EIOkvq4o6VjQ7lsTUNr5G0nDRdhwuvemHEiAt/uw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=CZS2jBJKEpg7t83Iyjb5Y34NAWtaxRnpiwoHdp2qGTMAbPZEqL4DKjd8XesZamv7L8XIW/130QsIJ/QHQDM6ysiVObs/T8vEYZTU58v00k0vB6GYyr3ya4dUiR59suAwiUgSmrAi86/oM2pgPOM+5Tef4cayhXKTU/+j+pwrcVM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723110431; 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; bh=e0obpgAOtjr9tyzYHluTb0Ja+N5F7X9qQe7igkAxQ6A=; b=OiqxrUzoOASvTUprI3AXQ0Rq5xD0NbejV4HtXqsMSegCBE97M19GJ89i4diOfvWtMWxhoy ilaPo9fW29oE/CYYzRSiohSn4iHnWLcBSU37Thej+TVXr/eUA0MTARSAhmwUJ6/KtT+lO8 7NGjmHaVgIj3sTvgFcGNTr1a9dC/Rq8= Received: from mail-vs1-f71.google.com (mail-vs1-f71.google.com [209.85.217.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-692-ACBOXg2lPiyMBvutOTJrtQ-1; Thu, 08 Aug 2024 05:47:10 -0400 X-MC-Unique: ACBOXg2lPiyMBvutOTJrtQ-1 Received: by mail-vs1-f71.google.com with SMTP id ada2fe7eead31-49292256be3so144137137.0 for ; Thu, 08 Aug 2024 02:47:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723110430; x=1723715230; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=e0obpgAOtjr9tyzYHluTb0Ja+N5F7X9qQe7igkAxQ6A=; b=JJYy/dlGX4Oh332pvT5nKric+G/0B8go58HTae3GWu+lH6IR/FdJHrZgQEks5UbXvy vtV2lBgYBC2SFOncPWpupPaCQgFZpq3Me6+X/+RG+s7vJf+URC+Jonqmo+nA3kvA0dgq G6VLaIlCT9s+IwEb2uCVgKy0HmPP5291e4aWtuyoKsiwAXLe3MTXbxHeCPje0UFqbuZ0 hJD+Zpa0/QRn5miaADQJcdUyozjHSqeRSZoQFqW9ZkS4t82KVzrDxlOr1qilZjE9nOxj Pk6NCBA9imxEfOFUu469nbm8nzfuI07U+u00GplGSGdNLgJAOm2/wwkxPeXZEpDiHtnJ itqQ== X-Gm-Message-State: AOJu0YwS1FsYQMEv3kipJpN6cLiT+MRYYDg5eVWK9Z7d3jIr988ON+4a EUDFn83oSuWIVq37JrSc6slQ2w3LUqGEUWNm60b0PKlKMlxkcHjO1Md0Qon77A2Hqq1WuuLtKVs 86aGL2cW3OAyMZ8Adht/J6X+w0J/LaTjFgUuEB3SIKo1/myqSlWh6ZbnVfw== X-Received: by 2002:a05:6102:5488:b0:48f:e729:f45e with SMTP id ada2fe7eead31-495c5c36f15mr1397654137.26.1723110429671; Thu, 08 Aug 2024 02:47:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGq52jGSoxpdVW/ouOzG43N9ROBpRZ9OhE8biUffTzoUTWhH89FnVMOOIcBquHkra2n7BMYTA== X-Received: by 2002:a05:6102:5488:b0:48f:e729:f45e with SMTP id ada2fe7eead31-495c5c36f15mr1397640137.26.1723110429250; Thu, 08 Aug 2024 02:47:09 -0700 (PDT) Received: from localhost (88-120-130-27.subs.proxad.net. [88.120.130.27]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6bb9c86ac72sm65145256d6.113.2024.08.08.02.47.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 02:47:08 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id CBE9E507A61B; Thu, 8 Aug 2024 11:47:06 +0200 (CEST) From: Dodji Seketeli To: Nick Alcock , claudiu.zissulescu-ianculescu@oracle.com Cc: libabigail@sourceware.org Subject: [PATCH, for review] ctf-reader: Enumerate dicts in the archive rather than using their name Organization: Red Hat / France X-Operating-System: AlmaLinux 9.4 X-URL: http://www.redhat.com Date: Thu, 08 Aug 2024 11:47:06 +0200 Message-ID: <87h6bvs5wl.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.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_H4, 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: libabigail@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libabigail-bounces~patchwork=sourceware.org@sourceware.org Hello, Following up my message https://inbox.sourceware.org/libabigail/87le17s6b9.fsf@seketeli.org/, Here is a patch I am proposing to avoid having to pass a new --ctf-parent option to the libabigail tools. If you agree with the spirit of this patch and if it works for you, I'd prefer this one (or some other patch that avoids having to pass a --ctf-parent option to the tools) to be applied instead. So I am looking forward to hearing your comments. ctf::reader::process_ctf_archive calls ctf_dict_open with the name of the (parent) dictionary to open. If that parent dictionary is set to an unexpected name, then the call to ctf_dict_open fails. This can happen for instance when at link time, the name of the parent dictionary is set to an arbitrary name using the "ctf_link_set_memb_name_changer" function. This patch enumerates the dictionaries of the archive to avoid having to know the name of the parent dictionary. The enumeration is done using the ctf_archive_next function of libctf. There is currently no binary with an unexpected dictionary name in the test suite so this patch cannot be tested for that particular case. I'd be glad to have such binaries added to the test suite. In the mean time this patch has been tested successfully using "make fullcheck" on the existing test suite. * src/abg-ctf-reader.cc (reader::process_ctf_archive): Do not use ctf_dict_open to open the dictionary by name. Rather, enumerate the dictionaries of the current archive by using ctf_archive_next just like what lookup_symbol_in_ctf_archive does. Set the argument of the skip_parent parameter to "false" to ensure we get the parent dictionary. (lookup_symbol_in_ctf_archive): Clean this up to properly initialize the parameters and to document the arguments to the parameters of ctf_archive_next. Use nullptr instead of NULL. * tests/data/test-diff-pkg-ctf/test-rpm-report-1.txt: Adjust. * tests/data/test-diff-pkg-ctf/test-rpm-report-2.txt: Adjust. Signed-off-by: Dodji Seketeli --- src/abg-ctf-reader.cc | 52 +++++++++---------- .../test-diff-pkg-ctf/test-rpm-report-1.txt | 2 +- .../test-diff-pkg-ctf/test-rpm-report-2.txt | 2 +- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc index 6879c6e0..40b89af9 100644 --- a/src/abg-ctf-reader.cc +++ b/src/abg-ctf-reader.cc @@ -445,35 +445,26 @@ public: corp->add(ir_translation_unit); cur_transl_unit(ir_translation_unit); - int ctf_err; - ctf_dict_t *ctf_dict, *dict_tmp; + ctf_dict_t *ctf_dict = nullptr, *initial_ctf_dict = nullptr; const auto symt = symtab(); symtab_reader::symtab_filter filter = symt->make_filter(); filter.set_public_symbols(); - std::string dict_name; - if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN) - && corpus_group()) + ctf_next_t *it = nullptr; + // Iterate through the dictionnaries of the archive and get the + // first one, which should be the parent dictionnary. + initial_ctf_dict = ctf_archive_next(ctfa, /*iterator=*/&it, + /*dict_name=*/nullptr, + /*skip_parent=*/false, + /*ctf_error=*/nullptr); + if (!initial_ctf_dict) { - tools_utils::base_name(corpus_path(), dict_name); - // remove .* suffix - std::size_t pos = dict_name.find("."); - if (pos != string::npos) - dict_name.erase(pos); - - std::replace(dict_name.begin(), dict_name.end(), '-', '_'); - } - - if ((ctf_dict = ctf_dict_open(ctfa, - dict_name.empty() ? NULL : dict_name.c_str(), - &ctf_err)) == NULL) - { - fprintf(stderr, "ERROR dictionary not found\n"); - abort(); + std::cerr << "Could not find any dictionnary in the CTF archive\n"; + ctf_next_destroy(it); + return; } - dict_tmp = ctf_dict; - + ctf_dict = initial_ctf_dict; for (const auto& symbol : symtab_reader::filtered_symtab(*symt, filter)) { std::string sym_name = symbol->get_name(); @@ -524,11 +515,14 @@ public: func_declaration->set_is_in_public_symbol_table(true); add_fn_to_exported_or_undefined_decls(func_declaration.get()); } - - ctf_dict = dict_tmp; + if (ctf_dict != initial_ctf_dict) + { + ctf_dict_close(initial_ctf_dict); + initial_ctf_dict = ctf_dict; + } } - ctf_dict_close(ctf_dict); + ctf_next_destroy(it); } /// Add a new type declaration to the given libabigail IR corpus CORP. @@ -1667,10 +1661,12 @@ lookup_symbol_in_ctf_archive(ctf_archive_t *ctfa, ctf_dict_t **ctf_dict, if (ctf_type == CTF_ERR) { ctf_dict_t *fp; - ctf_next_t *i = NULL; - const char *arcname; + ctf_next_t *i = nullptr; + const char *arcname = nullptr; - while ((fp = ctf_archive_next(ctfa, &i, &arcname, 1, &ctf_err)) != NULL) + while ((fp = ctf_archive_next(ctfa, &i, &arcname, + /*skip_parent=*/true, + &ctf_err)) != nullptr) { if ((ctf_type = ctf_lookup_by_symbol_name (fp, sym_name)) == CTF_ERR) ctf_type = ctf_lookup_variable(fp, sym_name); diff --git a/tests/data/test-diff-pkg-ctf/test-rpm-report-1.txt b/tests/data/test-diff-pkg-ctf/test-rpm-report-1.txt index 84d22968..af0afa73 100644 --- a/tests/data/test-diff-pkg-ctf/test-rpm-report-1.txt +++ b/tests/data/test-diff-pkg-ctf/test-rpm-report-1.txt @@ -1,5 +1,5 @@ ================ changes of 'libdwarf.so.1.20180129.0'=============== - Functions changes summary: 0 Removed, 0 Changed, 0 Added function + Functions changes summary: 0 Removed, 0 Changed (1 filtered out), 0 Added function Variables changes summary: 0 Removed, 0 Changed, 0 Added variable Function symbols changes summary: 0 Removed, 1 Added function symbol not referenced by debug info Variable symbols changes summary: 0 Removed, 0 Added variable symbol not referenced by debug info diff --git a/tests/data/test-diff-pkg-ctf/test-rpm-report-2.txt b/tests/data/test-diff-pkg-ctf/test-rpm-report-2.txt index e22399de..1347b012 100644 --- a/tests/data/test-diff-pkg-ctf/test-rpm-report-2.txt +++ b/tests/data/test-diff-pkg-ctf/test-rpm-report-2.txt @@ -1,5 +1,5 @@ ================ changes of 'libdwarf.so.1.20180129.0'=============== - Functions changes summary: 0 Removed, 0 Changed, 0 Added function + Functions changes summary: 0 Removed, 0 Changed (1 filtered out), 0 Added function Variables changes summary: 0 Removed, 0 Changed, 0 Added variable Function symbols changes summary: 1 Removed, 0 Added function symbol not referenced by debug info Variable symbols changes summary: 0 Removed, 0 Added variable symbol not referenced by debug info