From patchwork Fri Jul 7 11:41:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 72289 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 EDB5738ED3B6 for ; Fri, 7 Jul 2023 12:00:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EDB5738ED3B6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688731230; bh=hl+8UK3MYycoXl0Sfdv6QQFZurwP8u4GZIEzKlQP1D4=; h=To:Subject:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:From; b=FTWgr+VICmnu0VMu3qiCr504vutIi8V+sep/8z7kRK5a8jQ1igV+fd9YTXGGcuiUl cukqRyrzpBDks5mY/5UyS6PQHwFHCABh8+juH3Vh795fK/etZ8JCCTZ0TVc9LzLcC2 KfNrwjgnVLuF9RhDjo7y4ZCZ+g9T245/C98PwnJ0= 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 ESMTPS id 50BC139F87C8 for ; Fri, 7 Jul 2023 11:41:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 50BC139F87C8 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-100-0NxYaFbjNT6aHBtTp2q9Iw-1; Fri, 07 Jul 2023 07:41:13 -0400 X-MC-Unique: 0NxYaFbjNT6aHBtTp2q9Iw-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7656cf70228so220445585a.2 for ; Fri, 07 Jul 2023 04:41:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688730073; x=1691322073; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:to:from:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=hl+8UK3MYycoXl0Sfdv6QQFZurwP8u4GZIEzKlQP1D4=; b=Trcq0sW36Gr4bSzPaVeIBZty81/Q7cAAPL5i0jbkVbjUdja4EwdKp5WML20XubXJDv 0vUEymcuDRM+uVIPIJmmLOgxvMR+KDCbA46C+5dW9IO6MDNEtoXMRgfbkLJ3CSVZA9T1 UGIs5u5DvUKEzbVSIwET4qMtyJZ6EhVNW1NJHgvQipfFgn0KNVFOiDUy7wLWy0Cpla9M n//O5ajjZ9dUE3cQ/3aKan/4Fz8cCYjFyc9VZKV//BQsrRq5dJ9YLcBM42DQ+IVTk0wm xbyA/0YZlSDvadfQmk/sq96pp9NfKEt+9cI7ZsHnvDJ+RL6pFoXNN9wkg5Y9XVw8Muso w45Q== X-Gm-Message-State: ABy/qLZJitVRIsbFPIsJ6E0Mtg4ZXlX7d8Kp6+x16ws+bhww4OMxse5N o91T5IMsQHcGFFf1VKHhsRd+kOz+NCttPS2hBYVEiZG310iNHcLV5to1NRlkC8JE2hbV2Uk5rGJ JWgYFyclRfMJL15PMF6x3YOalRohB X-Received: by 2002:a0c:e150:0:b0:62d:e3d7:5b89 with SMTP id c16-20020a0ce150000000b0062de3d75b89mr4188961qvl.38.1688730073046; Fri, 07 Jul 2023 04:41:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlEhKlL58dD/xR7glJjlK1zrB03YP5vSI7VbFetHtpEK4schAh7juQgfvuT8tVrrGLAxtxsNvg== X-Received: by 2002:a0c:e150:0:b0:62d:e3d7:5b89 with SMTP id c16-20020a0ce150000000b0062de3d75b89mr4188948qvl.38.1688730072662; Fri, 07 Jul 2023 04:41:12 -0700 (PDT) Received: from localhost ([88.120.130.27]) by smtp.gmail.com with ESMTPSA id o17-20020a0ccb11000000b00630c0ed6339sm1976162qvk.64.2023.07.07.04.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 04:41:12 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id A1BE6B4FFD; Fri, 7 Jul 2023 13:41:10 +0200 (CEST) To: libabigail@sourceware.org Subject: [PATCH 1/4, applied] Make fe_iface::initialize independent from the kind of interface Organization: Red Hat / France References: <87edlk0x3p.fsf@redhat.com> X-Operating-System: CentOS Stream release 9 X-URL: http://www.redhat.com Date: Fri, 07 Jul 2023 13:41:10 +0200 In-Reply-To: <87edlk0x3p.fsf@redhat.com> (Dodji Seketeli's message of "Fri, 07 Jul 2023 13:39:22 +0200") Message-ID: <87a5w80x0p.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=-11.9 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, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Dodji Seketeli via Libabigail From: Dodji Seketeli Reply-To: Dodji Seketeli Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" Hello, In the use case laid out by the "Library Splitting support" at https://sourceware.org/bugzilla/show_bug.cgi?id=30034, tools might want to be able to re-initialize a given front-end to load several corpora in a row, independently from the kind of front-end (elf-based, ABIXML, etc). So we need a fe_iface::initialize() interface that is similar to the elf_based_reader::initialize() interface but, unlike that one, it should not depend on parameters that only make sense in a elf-based context. For instance, the fe_iface::initialize() interface should not contain paths to debug-info as that information does not make sense in an ABIXML context. This patch thus renames fe_iface::reset() into fe_iface::initialize() and makes it virtual. It adjusts the plumbing accordingly, basically making the other ::initialize() methods of classes that inherit fe_iface use fe_iface::initialize() when appropriate. The patch also provides an elf_based_reader::initialize() implementation of the fe_iface::initialize() interface, so that invoking ::initialize on elf_based_reader through the fe_iface interface does the right thing so that the initial use case presented at the beginning of this comment is supported. * include/abg-elf-based-reader.h (elf_based_reader::initialize): Rename elf_based_reader::reset into this. Add a new virtual overload that implements fe_iface::initialize. * include/abg-elf-reader.h (reader::initialize): Rename elf_reader::reset into this. Add a new virtual overload that implements fe_iface::initialize. * include/abg-fe-iface.h (fe_iface::initialize): Rename fe_iface::reset into this and make it virtual. * src/abg-btf-reader.cc (btf::reader::initialize): Adjust call to elf_based_reader::reset to elf_based_reader::initialize. * src/abg-ctf-reader.cc (ctf::reader::initialize): Likewise. * src/abg-dwarf-reader.cc (dwarf::reader::initialize): Likewise. * src/abg-elf-based-reader.cc (elf_based_reader::initialize): Rename elf_based_reader::reset into this. Adjust call to elf::reader::reset into elf::reader::initialize. Add a new virtual overload that implements fe_iface::initialize. * src/abg-elf-reader.cc (reader::initialize): Rename elf::reader::reset into this. Adjust call to fe_iface::reset into fe_iface::initialize. Add a new virtual overload that implements fe_iface::initialize. * src/abg-fe-iface.cc (fe_iface::priv::initialize): Reset the corpus too. (fe_iface::initialize): Rename fe_iface::reset into this. Invoke priv::initialize and set the new corpus_path. Signed-off-by: Dodji Seketeli Applied to master. --- include/abg-elf-based-reader.h | 8 ++++++-- include/abg-elf-reader.h | 9 ++++++--- include/abg-fe-iface.h | 4 ++-- src/abg-btf-reader.cc | 2 +- src/abg-ctf-reader.cc | 2 +- src/abg-dwarf-reader.cc | 2 +- src/abg-elf-based-reader.cc | 23 +++++++++++++++++++---- src/abg-elf-reader.cc | 25 +++++++++++++++++++------ src/abg-fe-iface.cc | 11 ++++------- 9 files changed, 59 insertions(+), 27 deletions(-) diff --git a/include/abg-elf-based-reader.h b/include/abg-elf-based-reader.h index 597eec90..f51cb2cb 100644 --- a/include/abg-elf-based-reader.h +++ b/include/abg-elf-based-reader.h @@ -50,17 +50,21 @@ public: ~elf_based_reader(); virtual void - reset(const std::string& elf_path, - const vector& debug_info_root_paths); + initialize(const std::string& elf_path, + const vector& debug_info_root_paths); virtual ir::corpus_sptr read_and_add_corpus_to_group(ir::corpus_group& group, fe_iface::status& status); + virtual void initialize(const string& elf_path, const vector& debug_info_root_paths, bool load_all_types, bool linux_kernel_mode) = 0; + + virtual void + initialize(const std::string& corpus_path); };//end class elf_based_reader typedef std::shared_ptr elf_based_reader_sptr; diff --git a/include/abg-elf-reader.h b/include/abg-elf-reader.h index 9e370c0b..ab350607 100644 --- a/include/abg-elf-reader.h +++ b/include/abg-elf-reader.h @@ -72,9 +72,12 @@ class reader : public fe_iface ~reader(); - void - reset(const std::string& elf_path, - const vector& debug_info_roots); + virtual void + initialize(const std::string& elf_path, + const vector& debug_info_roots); + + virtual void + initialize(const std::string& elf_path); const vector& debug_info_root_paths() const; diff --git a/include/abg-fe-iface.h b/include/abg-fe-iface.h index 12b8b2bd..64feafb2 100644 --- a/include/abg-fe-iface.h +++ b/include/abg-fe-iface.h @@ -74,8 +74,8 @@ protected: virtual ~fe_iface(); - void - reset(const std::string& corpus_path, environment& e); + virtual void + initialize(const std::string& corpus_path); const options_type& options() const; diff --git a/src/abg-btf-reader.cc b/src/abg-btf-reader.cc index 1ab2b4c8..995ff5b4 100644 --- a/src/abg-btf-reader.cc +++ b/src/abg-btf-reader.cc @@ -237,7 +237,7 @@ protected: bool load_all_types, bool linux_kernel_mode) { - reset(elf_path, debug_info_root_paths); + elf_based_reader::initialize(elf_path, debug_info_root_paths); btf__free(btf_handle_); options().load_all_types = load_all_types; options().load_in_linux_kernel_mode = linux_kernel_mode; diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc index 8e9c204f..2de11c0f 100644 --- a/src/abg-ctf-reader.cc +++ b/src/abg-ctf-reader.cc @@ -288,7 +288,7 @@ public: { load_all_types = load_all_types; linux_kernel_mode = linux_kernel_mode; - reset(elf_path, debug_info_root_paths); + elf_based_reader::initialize(elf_path, debug_info_root_paths); } /// Setter of the current translation unit. diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 80b9d752..c20cf16b 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -2018,7 +2018,7 @@ public: bool load_all_types, bool linux_kernel_mode) { - reset(elf_path, debug_info_root_paths); + elf_based_reader::initialize(elf_path, debug_info_root_paths); initialize(load_all_types, linux_kernel_mode); } diff --git a/src/abg-elf-based-reader.cc b/src/abg-elf-based-reader.cc index d1d9a2df..f565c26a 100644 --- a/src/abg-elf-based-reader.cc +++ b/src/abg-elf-based-reader.cc @@ -61,7 +61,7 @@ elf_based_reader::elf_based_reader(const std::string& elf_path, elf_based_reader::~elf_based_reader() {delete priv_;} -/// Reset (re-initialize) the resources used by the current reader. +/// (re)Initialize) the resources used by the current reader. /// /// This frees the resources of the current reader and gets it ready /// to read data from another ELF file. @@ -71,13 +71,28 @@ elf_based_reader::~elf_based_reader() /// @param debug_info_root_paths a vector of paths to look into for /// split debug info files. void -elf_based_reader::reset(const std::string& elf_path, - const vector& debug_info_root_paths) +elf_based_reader::initialize(const std::string& elf_path, + const vector& debug_info_root_paths) { - elf::reader::reset(elf_path, debug_info_root_paths); + elf::reader::initialize(elf_path, debug_info_root_paths); priv_->initialize(); } +/// (re)Initialize the resources used by the current reader. +/// +/// This invokes fe_iface::initialize as wel as the virtual pure +/// elf_based_reader::initialize() interface. +/// +/// @param corpus_path path to the corpus to be built. +void +elf_based_reader::initialize(const std::string& corpus_path) +{ + fe_iface::initialize(corpus_path); + vector v; + initialize(corpus_path, v, /*load_all_type=*/false, + /*linux_kernel_mode=*/false); +} + /// Read an ABI corpus and add it to a given corpus group. /// /// @param group the corpus group to consider. The new corpus is diff --git a/src/abg-elf-reader.cc b/src/abg-elf-reader.cc index af65cecf..7884c672 100644 --- a/src/abg-elf-reader.cc +++ b/src/abg-elf-reader.cc @@ -527,8 +527,8 @@ reader::reader(const string& elf_path, reader::~reader() {delete priv_;} -/// Resets (erase) the resources used by the current @ref -/// elf::reader type. +/// Re-initialize the resources used by the current @ref elf::reader +/// type. /// /// This lets the reader in a state where it's ready to read from /// another ELF file. @@ -538,11 +538,10 @@ reader::~reader() /// @param debug_info_roots a vector of directory paths to look into /// for split debug information files. void -reader::reset(const std::string& elf_path, - const vector& debug_info_roots) +reader::initialize(const std::string& elf_path, + const vector& debug_info_roots) { - fe_iface::options_type opts = options(); - fe_iface::reset(elf_path, opts.env); + fe_iface::initialize(elf_path); corpus_path(elf_path); priv_->initialize(debug_info_roots); priv_->crack_open_elf_file(); @@ -550,6 +549,20 @@ reader::reset(const std::string& elf_path, priv_->locate_ctf_debug_info(); } +/// Re-initialize the resources used by the current @ref elf::reader +/// type. +/// +/// This lets the reader in a state where it's ready to read from +/// another ELF file. +/// +/// @param elf_path the new ELF path to read from. +void +reader::initialize(const std::string& elf_path) +{ + vector v; + initialize(elf_path, v); +} + /// Getter of the vector of directory paths to look into for split /// debug information files. /// diff --git a/src/abg-fe-iface.cc b/src/abg-fe-iface.cc index 6ec50bfd..7c62fe7c 100644 --- a/src/abg-fe-iface.cc +++ b/src/abg-fe-iface.cc @@ -43,11 +43,11 @@ struct fe_iface::priv void initialize() { - //TODO: initialize the options. corpus_path.clear(); dt_soname.clear(); suppressions.clear(); corpus_group.reset(); + corpus.reset(); } }; //end struct fe_iface::priv @@ -78,14 +78,11 @@ fe_iface::~fe_iface() /// /// @param corpus_path the path to the file for which a new corpus is /// to be created. -/// -/// @param e the environment in which the Front End operates. void -fe_iface::reset(const std::string& corpus_path, - environment& e) +fe_iface::initialize(const std::string& corpus_path) { - delete priv_; - priv_ = new fe_iface::priv(corpus_path, e); + priv_->initialize(); + priv_->corpus_path = corpus_path; } /// Getter of the the options of the current Front End Interface.