From patchwork Fri Jul 3 16:46:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39890 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 7745E384403B; Fri, 3 Jul 2020 16:47:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7745E384403B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1593794875; bh=U8ZzVKAzuHA6MRPOLfahUBWYf8Xo5g3urcVksFrxGas=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=mnswW7cA662jgWXUfBwmjEb3PsyoRzrMEOHGiMBEfR8N+gV918TKZNDKZQIESn6FF VsshuNbFwMlSTApkGCpDiENP+tY5J55bf1lxqweVQaLm1TdUwz+86I9VLyBduQ/Mr4 lNkSHK/FOkFty7dLQxHGXGbCzt2xgJBts20HsEE8= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by sourceware.org (Postfix) with ESMTPS id B5FC1384402F for ; Fri, 3 Jul 2020 16:47:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B5FC1384402F Received: by mail-wr1-x449.google.com with SMTP id b8so18190256wro.19 for ; Fri, 03 Jul 2020 09:47:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=U8ZzVKAzuHA6MRPOLfahUBWYf8Xo5g3urcVksFrxGas=; b=qBPJ+jrtm8mhuLBj6KqxOW7jkLi0GJzW+pf0NKu/ZxWzK1f4G6uiqCy2itnYd0FarQ Kl8cLaj5vXzikIFNXqHvyOKPkp+88u3ZqTIjiMuHnM97zh5CaJeiMT+97Dv2XbnTXv2Y yGeJDapG1hKMnif3N5qcUxYXzqHTiRIkusZaTY7sdX+7mT+tS/YPffDEjWzxMOjaz5bC NxxJFSrMicoqZ3DAwKifM+2/7ZYjpw5CpERyZwSnIhIBL7r8WHl6Wsq7RSJQWCICDgAp NmYc4Bh3/MzuYCirkE/OOwWu5MesP2+0RftO4bABYJidwZHxKmcVqQEW5Zh1ykq1zkzy /KVw== X-Gm-Message-State: AOAM531vp20l/qX4peT6BJ76C5VSEfQtz/UTRlObA3wiWHLOV8dByB0R XqOWJjlRLGTqQA9BJ1xi6WB/gzauXM2Rf2L1Upb1KRSS8rJ4vwwPtx2T6SDlV6/cVZV8DTCU2Ws NIee5JjYnPlNcLj4Rqv7slVV/QvW8pYj4ax1dF4Dqlrg6BiydWUNCxWWu843NaUxv1VWQUr4= X-Google-Smtp-Source: ABdhPJzYSHUs3DAopv2hZvKkw3gNMQe+y5YmnKdBnaZCLnZDJVsy89mS10hriJiPx04iGDN0RC9pE6kIPY70Fg== X-Received: by 2002:a7b:c1d8:: with SMTP id a24mr2314101wmj.0.1593794870008; Fri, 03 Jul 2020 09:47:50 -0700 (PDT) Date: Fri, 3 Jul 2020 18:46:37 +0200 In-Reply-To: <20200703164651.1510825-1-maennich@google.com> Message-Id: <20200703164651.1510825-8-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20200703164651.1510825-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.212.ge8ba1cc988-goog Subject: [PATCH v2 07/21] Integrate new symtab reader into corpus and read_context To: libabigail@sourceware.org X-Spam-Status: No, score=-23.5 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Matthias Maennich via Libabigail From: =?utf-8?q?Matthias_M=C3=A4nnich?= Reply-To: Matthias Maennich Cc: maennich@google.com, kernel-team@android.com Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" While reading the corpus in the read_context, also load the new type symtab object side-by-side and set it accordingly in the resulting corpus. This is still side by side and passive code that gets active in the following changes. This is applicable for the dwarf reader as well as for the reader that consumes XML. * include/abg-corpus.h (corpus::set_symtab): New method declaration. (corpus::get_symtab): New method declaration. * include/abg-fwd.h (symtab_reader::symtab_sptr): New forward declaration. * src/abg-corpus-priv.h (corpus::priv::symtab_): New data member. * src/abg-corpus.cc (corpus::set_symtab): Likewise. (corpus::get_symtab): Likewise. * src/abg-dwarf-reader.cc (read_context::symtab_): New data member. (read_context::initialize): reset symtab_ as well (read_context::symtab): new method that loads a symtab on first access and returns it. (read_debug_info_into_corpus): also set the new symtab object on the current corpus. (read_corpus_from_elf): Also determine (i.e. load) the new symtab object and contribute to the load status. * src/abg-reader.cc (read_corpus_from_input): also set the new type symtab when reading from xml. * tests/test-symtab.cc: Add test assertions. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- include/abg-corpus.h | 6 ++++ include/abg-fwd.h | 8 ++++++ src/abg-corpus-priv.h | 2 ++ src/abg-corpus.cc | 9 ++++++ src/abg-dwarf-reader.cc | 27 ++++++++++++++++++ src/abg-reader.cc | 3 ++ tests/data/test-symtab/basic/no_debug_info.c | 2 +- tests/data/test-symtab/basic/no_debug_info.so | Bin 15360 -> 15544 bytes tests/test-symtab.cc | 15 ++++------ 9 files changed, 61 insertions(+), 11 deletions(-) diff --git a/include/abg-corpus.h b/include/abg-corpus.h index 410a9c2459e6..b94926996cde 100644 --- a/include/abg-corpus.h +++ b/include/abg-corpus.h @@ -169,6 +169,12 @@ public: bool operator==(const corpus&) const; + void + set_symtab(symtab_reader::symtab_sptr); + + const symtab_reader::symtab_sptr& + get_symtab() const; + void set_fun_symbol_map(string_elf_symbols_map_sptr); diff --git a/include/abg-fwd.h b/include/abg-fwd.h index 999b071b5664..07ab0b9f163e 100644 --- a/include/abg-fwd.h +++ b/include/abg-fwd.h @@ -1331,6 +1331,14 @@ typedef vector suppressions_type; } // end namespace suppr +namespace symtab_reader +{ + +class symtab; +typedef abg_compat::shared_ptr symtab_sptr; + +} // end namespace symtab_reader + void dump(const decl_base_sptr, std::ostream&); diff --git a/src/abg-corpus-priv.h b/src/abg-corpus-priv.h index ee8c823964e7..5c1e915ad2f3 100644 --- a/src/abg-corpus-priv.h +++ b/src/abg-corpus-priv.h @@ -32,6 +32,7 @@ #include "abg-internal.h" #include "abg-regex.h" #include "abg-sptr-utils.h" +#include "abg-symtab-reader.h" namespace abigail { @@ -700,6 +701,7 @@ struct corpus::priv string_elf_symbols_map_sptr undefined_var_symbol_map; elf_symbols sorted_var_symbols; elf_symbols sorted_undefined_var_symbols; + symtab_reader::symtab_sptr symtab_; string_elf_symbols_map_sptr fun_symbol_map; string_elf_symbols_map_sptr undefined_fun_symbol_map; elf_symbols sorted_fun_symbols; diff --git a/src/abg-corpus.cc b/src/abg-corpus.cc index 9e90b99473d3..94702047dd82 100644 --- a/src/abg-corpus.cc +++ b/src/abg-corpus.cc @@ -38,6 +38,7 @@ ABG_BEGIN_EXPORT_DECLARATIONS #include "abg-ir.h" #include "abg-reader.h" #include "abg-sptr-utils.h" +#include "abg-symtab-reader.h" #include "abg-tools-utils.h" #include "abg-writer.h" @@ -905,6 +906,14 @@ corpus::operator==(const corpus& other) const && j == other.get_translation_units().end()); } +void +corpus::set_symtab(symtab_reader::symtab_sptr symtab) +{priv_->symtab_ = symtab;} + +const symtab_reader::symtab_sptr& +corpus::get_symtab() const +{ return priv_->symtab_; } + /// Setter of the function symbols map. /// /// @param map a shared pointer to the new function symbols map. diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index cf789d09a8be..d9c1c03d273f 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -50,6 +50,7 @@ #include "abg-suppression-priv.h" #include "abg-corpus-priv.h" #include "abg-elf-helpers.h" + #include "abg-internal.h" // @@ -57,6 +58,7 @@ ABG_BEGIN_EXPORT_DECLARATIONS #include "abg-dwarf-reader.h" #include "abg-sptr-utils.h" +#include "abg-symtab-reader.h" #include "abg-tools-utils.h" ABG_END_EXPORT_DECLARATIONS @@ -2277,6 +2279,9 @@ public: bool drop_undefined_syms_; read_context(); +private: + mutable symtab_reader::symtab_sptr symtab_; + public: /// Constructor of read_context. @@ -2426,6 +2431,8 @@ public: dt_soname_.clear(); elf_architecture_.clear(); + symtab_.reset(); + clear_per_translation_unit_data(); memset(&offline_callbacks_, 0, sizeof(offline_callbacks_)); @@ -5577,6 +5584,22 @@ public: return symbol; } + const symtab_reader::symtab_sptr& + symtab() const + { + using namespace abg_compat::placeholders; + if (!symtab_) + symtab_ = symtab_reader::symtab::load( + elf_handle(), options_.env, + abg_compat::bind(&read_context::is_elf_symbol_suppressed, this, _1)); + if (!symtab_) + { + std::cerr << "Symbol table of '" << elf_path_ + << "' could not be loaded\n"; + } + return symtab_; + } + /// Getter for a pointer to the map that associates the address of /// an entry point of a function with the symbol of that function. /// @@ -15481,6 +15504,7 @@ read_debug_info_into_corpus(read_context& ctxt) group->add_corpus(ctxt.current_corpus()); // Set symbols information to the corpus. + ctxt.current_corpus()->set_symtab(ctxt.symtab()); if (!get_ignore_symbol_table(ctxt)) { if (ctxt.load_in_linux_kernel_mode() @@ -16737,6 +16761,9 @@ read_corpus_from_elf(read_context& ctxt, status& status) status |= STATUS_NO_SYMBOLS_FOUND; } + if (!ctxt.symtab() || !ctxt.symtab()->has_symbols()) + status |= STATUS_NO_SYMBOLS_FOUND; + if (// If no elf symbol was found ... status & STATUS_NO_SYMBOLS_FOUND // ... or if debug info was found but not the required alternate diff --git a/src/abg-reader.cc b/src/abg-reader.cc index eb74659f1d46..188c23d2e5cd 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -47,6 +47,7 @@ ABG_BEGIN_EXPORT_DECLARATIONS #include "abg-libxml-utils.h" #include "abg-reader.h" #include "abg-corpus.h" +#include "abg-symtab-reader.h" #ifdef WITH_ZIP_ARCHIVE #include "abg-libzip-utils.h" @@ -1973,6 +1974,8 @@ read_corpus_from_input(read_context& ctxt) // Note that it's possible that both fn_sym_db and var_sym_db // are nil, due to potential suppression specifications. That's // fine. + corp.set_symtab(symtab_reader::symtab::load(fn_sym_db, var_sym_db)); + if (fn_sym_db) { corp.set_fun_symbol_map(fn_sym_db); diff --git a/tests/data/test-symtab/basic/no_debug_info.c b/tests/data/test-symtab/basic/no_debug_info.c index 5bb380ba0db8..8ac09016eb4d 100644 --- a/tests/data/test-symtab/basic/no_debug_info.c +++ b/tests/data/test-symtab/basic/no_debug_info.c @@ -1 +1 @@ -// empty! +void exported_function(){} diff --git a/tests/data/test-symtab/basic/no_debug_info.so b/tests/data/test-symtab/basic/no_debug_info.so index 827c1eee3e4e8f326af7e360ea444627ee59bee6..0b2310196a2a3a67369f80eb29e9ecefc22dc704 100755 GIT binary patch delta 1147 zcmZWoOH31C5T3tV9tB!<%cHzPw**bm(Cq`-Vl{1*M`I!w5)LMqVl09tfFOpVCM?DW zhJ&qhFdTd|AsW4SASPgpk#I5|(39dxV>oy)f(G?Kg0tN&N}SF7-_HE=`e*)Mj?a%L z?3Q^iY*PsQV1N*mfh8HV<=OS>j$NNT<1l0~Rmw`HB*SdRXEwQVUGVEvX&Z5vSu2jN zj>ggf#Ek7W;t0FD|IOD}WzFr0h4_JvUAv{Vajf89D27U`EMg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