From patchwork Wed Jan 27 12:58:34 2021 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: 41835 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 CF2073971C3C; Wed, 27 Jan 2021 12:59:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CF2073971C3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752351; bh=IMAJmyAnvqlExA+Te96eT75k6mPliMHDurcni5mQK7M=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=LPRR5dk99a2/mxRBHSIZZIpa5ayvc8jSvvCvOCFyvA2G0CkAOjE9PRrC7Na/7XZkD 1R+ZqzM7ZixtcJ/zvydPtcejJsPredDVXhhBFqljjDQ6Si6vzdiIOlZsLp2TQkNbiK PNQWx6CtqdE8f1H9CAuZl+m+q/JBg7x+0GcJrvCs= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by sourceware.org (Postfix) with ESMTPS id 7C67B382D830 for ; Wed, 27 Jan 2021 12:59:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7C67B382D830 Received: by mail-wr1-x44a.google.com with SMTP id o17so912327wrv.4 for ; Wed, 27 Jan 2021 04:59:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=IMAJmyAnvqlExA+Te96eT75k6mPliMHDurcni5mQK7M=; b=CO8Ba2cdWr3zGyHYOob+VCJUxXV6WMWsTxt9s8R7niG8CvRNEFeMRAAE7imICGvQ5L wJ5nOkPSRIeaTbOwcl6dtXbj/UkMwfThzr3butEE1XAGS1uXmohoglK42h2qWHOJTr38 FJLs0j7CKB/Czg6ryDhMkRIfy315+V0Go8tKsNcM+1Z1RTWTdGK57p6qVpGRHeI67KKA l2meo46hTdktP5Rcx6RaLWltvwo7TTncl7PVMLG5EgHpNLTsmHRYbAQfyDRX7PMnK8QE c/rF7rj8zVQWZLe8sWbdGcHglFSFa6ycqg4Li2JmIhaEWzrvBismqdeJfmRSQvkaGRJa 7uNQ== X-Gm-Message-State: AOAM531drfqoX9UoUSS7WacSdAq+QmC4BaUnKAdCyVNw5+3mgvk5hSEo 5QUXV/KVdEEmeA7Sl2Ivc4P6Noox1uhLnYKWHmiQO1yR/anfKr91fw2Rps/trcuUdos3wUfAa5+ fFFTTMUAOweL1s/bPDussGoWXCQU4jYdaUMRwb2ed9rmWN75w3hHkXszJnZr2ReToqk0MzmY= X-Google-Smtp-Source: ABdhPJwqR4vxv9uU5aWG5Ejg5IGsCLYyoGM1BxgB7otlKP2iJbJ8jFj6e3gzpaf9jVxmfqutLgUKJQw7AB0CTg== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:a7b:cb54:: with SMTP id v20mr4251488wmj.148.1611752348145; Wed, 27 Jan 2021 04:59:08 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:34 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-2-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 01/20] abg-cxx-compat: add simplified version of std::optional To: libabigail@sourceware.org X-Spam-Status: No, score=-22.6 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" In the absence (but desire) of std::optional, add a simplified version of it to abg_compat:: in case we are compiling with a pre-C++17 standard. Otherwise use std::optional from directly. This is being used by a later patch and serves as a prerequisite. It only serves the purpose of being a compatibility implementation and does not claim to be complete at all. Just enough for the project's needs. * include/abg-cxx-compat.h (abg_compat::optional): Add new class. * tests/tests-cxx-compat.cc: Add new test cases. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- include/abg-cxx-compat.h | 84 ++++++++++++++++++++++++++++++++++++++++ tests/test-cxx-compat.cc | 52 +++++++++++++++++++++++++ 2 files changed, 136 insertions(+) diff --git a/include/abg-cxx-compat.h b/include/abg-cxx-compat.h index 838fa53707d1..443905c75138 100644 --- a/include/abg-cxx-compat.h +++ b/include/abg-cxx-compat.h @@ -8,8 +8,92 @@ #ifndef __ABG_CXX_COMPAT_H #define __ABG_CXX_COMPAT_H +// C++17 support (via custom implementations if compiled with earlier standard) + +#if __cplusplus >= 201703L + +#include + +#else + +#include // for throwing std::runtime_error("bad_optional_access") + +#endif + namespace abg_compat { +#if __cplusplus >= 201703L + +using std::optional; + +#else + +// + +/// Simplified implementation of std::optional just enough to be used as a +/// replacement for our purposes and when compiling with pre C++17. +/// +/// The implementation intentionally does not support a whole lot of features +/// to minimize the maintenance effort with this. +template class optional +{ + bool has_value_; + T value_; + +public: + optional() : has_value_(false), value_() {} + optional(const T& value) : has_value_(true), value_(value) {} + + bool + has_value() const + { + return has_value_; + } + + const T& + value() const + { + if (!has_value_) + throw std::runtime_error("bad_optional_access"); + return value_; + } + + const T + value_or(const T& default_value) const + { + if (!has_value_) + return default_value; + return value_; + } + + const T& + operator*() const + { return value_; } + + T& + operator*() + { return value_; } + + const T* + operator->() const + { return &value_; } + + T* + operator->() + { return &value_; } + + optional& + operator=(const T& value) + { + has_value_ = true; + value_ = value; + return *this; + } + + explicit operator bool() const { return has_value_; } +}; + +#endif } #endif // __ABG_CXX_COMPAT_H diff --git a/tests/test-cxx-compat.cc b/tests/test-cxx-compat.cc index 35dc4f6104c2..2b0caaae1ab4 100644 --- a/tests/test-cxx-compat.cc +++ b/tests/test-cxx-compat.cc @@ -12,3 +12,55 @@ #include "lib/catch.hpp" #include "abg-cxx-compat.h" + +using abg_compat::optional; + +TEST_CASE("OptionalConstruction", "[abg_compat::optional]") +{ + optional opt1; + REQUIRE_FALSE(opt1.has_value()); + + optional opt2(true); + REQUIRE(opt2.has_value()); + CHECK(opt2.value() == true); + + optional opt3(false); + REQUIRE(opt3.has_value()); + CHECK(opt3.value() == false); +} + +TEST_CASE("OptionalValue", "[abg_compat::optional]") +{ + optional opt; + REQUIRE_FALSE(opt.has_value()); + REQUIRE_THROWS(opt.value()); + + opt = true; + REQUIRE_NOTHROW(opt.value()); + CHECK(opt.value() == true); +} + +TEST_CASE("OptionalValueOr", "[abg_compat::optional]") +{ + optional opt; + REQUIRE_FALSE(opt.has_value()); + + const std::string& mine = "mine"; + // Ensure we get a copy of our own value. + CHECK(opt.value_or(mine) == mine); + + // Now set the value + const std::string& other = "other"; + opt = other; + CHECK(opt.value_or(mine) != mine); + CHECK(opt.value_or(mine) == other); +} + +TEST_CASE("OptionalDeref", "[abg_compat::optional]") +{ + optional opt("asdf"); + REQUIRE(opt.has_value()); + + CHECK(*opt == "asdf"); + CHECK(opt->size() == 4); +} From patchwork Wed Jan 27 12:58:35 2021 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: 41836 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 24BE2396EC6E; Wed, 27 Jan 2021 12:59:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24BE2396EC6E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752353; bh=zgjd9IU5V06y2MD77ruwpvAOtYwhySW9CVAbHbe/+/U=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Yhp2lFdZz204ONJZiqdaEdlY7IylEDl+mD6zKIiYNTcqwt4X3UKxud0sO7ArZG42K L5xfGCPiHXTOIg+fvpcDho999mrwxfB/8fTuPDM4evMirqzCl40ajtqLpeHHoZJ/54 hzicm4O4jraMv0Zuhyds4Ng2L9TwmQeJNyMjeNb4= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by sourceware.org (Postfix) with ESMTPS id 418AE382D830 for ; Wed, 27 Jan 2021 12:59:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 418AE382D830 Received: by mail-qt1-x84a.google.com with SMTP id z19so1002779qtv.20 for ; Wed, 27 Jan 2021 04:59:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=zgjd9IU5V06y2MD77ruwpvAOtYwhySW9CVAbHbe/+/U=; b=fvb0ZgcJcvuZfNCh9Pw+hwCdOfChvWphTnjUPCphz80u9HQLLAWQATdBQNHM5mSGo2 2/YBccgBAtxuyTCK7bK1GImnAX3/Fh2n3Hw51Tgi5lffr3x1tEWOXBYvMxMT8/Dhog/2 VRMiwmL6CmJgEW4MIBdM5xXNOuNJv5m0Au+cT57gVez/yeYIzerT18s38sl5IEg43eHC xwOuwLTSmZnZAHKI6UuaU7jL2z9Rh3noChZV3JHA79CmKD/8pWNN17+4q40frxgpOq7d o5IdIvIXX3EFDQ0BG+PzVLdVzYtJlfHEAOK99ilHZfx/sNLLPe8nUQIZwTW+f7K6WSo3 0EZQ== X-Gm-Message-State: AOAM532qfHdUtYxyW8qwP/jySC1l7kjGobW3idNvtLTgss5XK80ALNXF 0tZzfkq4ocMlHK4Im9VquHOm7mJ3QjG7RqUhPcbimLKgdDLtnKlxzH5JWrhDoK0teITc8fFG+99 tH44aqrqbFU95pGsok/USrdRyr/wdcW84/A51aKPn8TUWWDHoYPqhTpYWzLfuWH5fZWmyhu8= X-Google-Smtp-Source: ABdhPJyWaXeC3FUoJvPQfQWEOG0YVe5cGBg999FrwBMEeh3Z7YGUPiIjQLGXZj5f8ZxoMmmZk2uUO0p+svTv/Q== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:a0c:eda6:: with SMTP id h6mr10021252qvr.19.1611752350663; Wed, 27 Jan 2021 04:59:10 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:35 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-3-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 02/20] abg-ir: elf_symbol: add is_in_ksymtab field To: libabigail@sourceware.org X-Spam-Status: No, score=-22.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" Being exported through a ksymtab (in case of Linux Kernel binaries) is actually a property of the Elf symbol itself and we can therefore track it along with the symbol that we collect from symtab. While tracking is currently done by keeping separate symbol lists and maps for symtab and ksymtab symbols, they can be consolidated having a property to indicate whether this symbol also appeared as a ksymtab entry. Hence, and for future changes in this area, add this property and update all references. The flag is false initially unless otherwise specified. * include/abg-ir.h (elf_symbol::elf_symbol): Add is_in_ksymtab parameter. (elf_symbol::create): Likewise. (elf_symbol::is_in_ksymtab): New getter declaration. (elf_symbol::set_is_in_ksymtab): New setter declaration. * src/abg-ir.cc (elf_symbol::priv::priv): Add is_in_ksymtab parameter. (elf_symbol::priv::is_in_ksymtab_): New field. (elf_symbol::elf_symbol): Add is_in_ksymtab parameter. (elf_symbol::create): Likewise. (elf_symbol::is_in_ksymtab): New getter implementation. (elf_symbol::set_is_in_ksymtab): New setter implementation. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- include/abg-ir.h | 34 +++++++++------ src/abg-ir.cc | 105 +++++++++++++++++++++++++++++------------------ 2 files changed, 86 insertions(+), 53 deletions(-) diff --git a/include/abg-ir.h b/include/abg-ir.h index c32b2f7fe989..d82c83592f82 100644 --- a/include/abg-ir.h +++ b/include/abg-ir.h @@ -837,8 +837,9 @@ private: bool d, bool c, const version& ve, - visibility vi, - bool is_linux_string_cst = false); + visibility vi, + bool is_linux_string_cst = false, + bool is_in_ksymtab = false); elf_symbol(const elf_symbol&); @@ -851,17 +852,18 @@ public: create(); static elf_symbol_sptr - create(const environment* e, - size_t i, - size_t s, - const string& n, - type t, - binding b, - bool d, - bool c, - const version& ve, - visibility vi, - bool is_linux_string_cst = false); + create(const environment* e, + size_t i, + size_t s, + const string& n, + type t, + binding b, + bool d, + bool c, + const version& ve, + visibility vi, + bool is_linux_string_cst = false, + bool is_in_ksymtab = false); const environment* get_environment() const; @@ -929,6 +931,12 @@ public: bool is_variable() const; + bool + is_in_ksymtab() const; + + void + set_is_in_ksymtab(bool is_in_ksymtab); + const elf_symbol_sptr get_main_symbol() const; diff --git a/src/abg-ir.cc b/src/abg-ir.cc index d1d02f3aad5d..22532cc87dfd 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -1310,6 +1310,7 @@ struct elf_symbol::priv // STT_COMMON definition of that name that has the largest size. bool is_common_; bool is_linux_string_cst_; + bool is_in_ksymtab_; elf_symbol_wptr main_symbol_; elf_symbol_wptr next_alias_; elf_symbol_wptr next_common_instance_; @@ -1324,20 +1325,22 @@ struct elf_symbol::priv visibility_(elf_symbol::DEFAULT_VISIBILITY), is_defined_(false), is_common_(false), - is_linux_string_cst_(false) + is_linux_string_cst_(false), + is_in_ksymtab_(false) {} - priv(const environment* e, - size_t i, - size_t s, - const string& n, - elf_symbol::type t, - elf_symbol::binding b, - bool d, - bool c, - const elf_symbol::version& ve, - elf_symbol::visibility vi, - bool is_linux_string_cst) + priv(const environment* e, + size_t i, + size_t s, + const string& n, + elf_symbol::type t, + elf_symbol::binding b, + bool d, + bool c, + const elf_symbol::version& ve, + elf_symbol::visibility vi, + bool is_linux_string_cst, + bool is_in_ksymtab) : env_(e), index_(i), size_(s), @@ -1348,7 +1351,8 @@ struct elf_symbol::priv visibility_(vi), is_defined_(d), is_common_(c), - is_linux_string_cst_(is_linux_string_cst) + is_linux_string_cst_(is_linux_string_cst), + is_in_ksymtab_(is_in_ksymtab) { if (!is_common_) is_common_ = type_ == COMMON_TYPE; @@ -1394,19 +1398,30 @@ elf_symbol::elf_symbol() /// /// @param is_linux_string_cst true if the symbol is a Linux Kernel /// string constant defined in the __ksymtab_strings section. -elf_symbol::elf_symbol(const environment* e, - size_t i, - size_t s, - const string& n, - type t, - binding b, - bool d, - bool c, - const version& ve, - visibility vi, - bool is_linux_string_cst) - : priv_(new priv(e, i, s, n, t, b, d, - c, ve, vi, is_linux_string_cst)) +elf_symbol::elf_symbol(const environment* e, + size_t i, + size_t s, + const string& n, + type t, + binding b, + bool d, + bool c, + const version& ve, + visibility vi, + bool is_linux_string_cst, + bool is_in_ksymtab) + : priv_(new priv(e, + i, + s, + n, + t, + b, + d, + c, + ve, + vi, + is_linux_string_cst, + is_in_ksymtab)) {} /// Factory of instances of @ref elf_symbol. @@ -1453,20 +1468,22 @@ elf_symbol::create() /// @return a (smart) pointer to a newly created instance of @ref /// elf_symbol. elf_symbol_sptr -elf_symbol::create(const environment* e, - size_t i, - size_t s, - const string& n, - type t, - binding b, - bool d, - bool c, - const version& ve, - visibility vi, - bool is_linux_string_cst) -{ - elf_symbol_sptr sym(new elf_symbol(e, i, s, n, t, b, d, c, ve, - vi, is_linux_string_cst)); +elf_symbol::create(const environment* e, + size_t i, + size_t s, + const string& n, + type t, + binding b, + bool d, + bool c, + const version& ve, + visibility vi, + bool is_linux_string_cst, + bool is_in_ksymtab) +{ + elf_symbol_sptr sym(new elf_symbol(e, i, s, n, t, b, d, c, ve, vi, + is_linux_string_cst, + is_in_ksymtab)); sym->priv_->main_symbol_ = sym; return sym; } @@ -1686,6 +1703,14 @@ bool elf_symbol::is_variable() const {return get_type() == OBJECT_TYPE || get_type() == TLS_TYPE;} +bool +elf_symbol::is_in_ksymtab() const +{return priv_->is_in_ksymtab_;} + +void +elf_symbol::set_is_in_ksymtab(bool is_in_ksymtab) +{priv_->is_in_ksymtab_ = is_in_ksymtab;} + /// @name Elf symbol aliases /// /// An alias A for an elf symbol S is a symbol that is defined at the From patchwork Wed Jan 27 12:58:36 2021 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: 41837 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 8C9CC3971830; Wed, 27 Jan 2021 12:59:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C9CC3971830 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752355; bh=284iQNR8hS3qvWB1uODjpQ+ZEyfRumfCSXRi94FHAzM=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=jvoYZ5rgIjHe5osNlBEqEu9BL5GMqtd4EqXSr9xM13XHorlC7eU//wVhcyllC8Vxi I41oUh1IwpH3QmFU3gvUrEJ01U1+uwYW/UkXMC3eCIrqvE3i2jX5Vz3Y+HN3PFiHGc NRj+6wlpfWmpC68GVd67uzkJmtju4NpSG+pZKtoE= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by sourceware.org (Postfix) with ESMTPS id 651443972827 for ; Wed, 27 Jan 2021 12:59:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 651443972827 Received: by mail-qk1-x749.google.com with SMTP id l124so1378841qke.7 for ; Wed, 27 Jan 2021 04:59:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=284iQNR8hS3qvWB1uODjpQ+ZEyfRumfCSXRi94FHAzM=; b=NsIm6tgq1lwynTtoTsXkQ/XRZYc7KfZ3QDRdOkL53UGLrYjfNPewFdfUXb9pA/Zgwj IKmjPYtyUxthc0bD90oRphOArFN4zbcq94yJdkmr7QF9r0KFEEcHmI52jn4WVtIa9DB5 QUaSTqkRfAuBiwe7XAK2dlkl5xOpnX9SYjoamYvD4k9g8tDczcR9H/iD8NQIMzjDdeBT ndccarLZOsMtj1RKVk1LUSojeZ+outd2gmw5QkZAEnwG3/UWT4n2ZVdnTxrQs6qeVlX9 IXToq1Mn01/Y5Fyw0cFuNTli+NNVpv6WTwdohY6hJ6knWJRRFldwUveaPC9CVzoSVjBS 1XaA== X-Gm-Message-State: AOAM531EBaC/FScl+wUTnXNmp9asjtAtKUE/gb/SNtRsE6n5Z3x0Eloe 7rRQICWmCyOEIOJ1tO1DcsV6ugaem8pngRNnQyrGVM5gwFu9YJKw07ZUWomgxOgu/4oFAyV1eEK T5zU5Rl6I//jqn5Otqe5PlGSXW/q+KXxC2Q9Y7mcUvcuNjyrm/zQJqvHkX9uYepxlnPlvGiU= X-Google-Smtp-Source: ABdhPJwEJoNYFLkkRTS8se/4uDf65sj4bZL6vTsFHZRZmAmZWsxg9bB/awhWPaAZEW+JhhMuT2xSLhj9hXwUqw== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:a0c:8365:: with SMTP id j92mr10365042qva.19.1611752352954; Wed, 27 Jan 2021 04:59:12 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:36 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-4-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 03/20] abg-ir: elf_symbol: add is_suppressed field To: libabigail@sourceware.org X-Spam-Status: No, score=-22.7 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" In the context of libabigail and a single library run (when reading from dwarf or from xml), a symbol is either suppressed or it is not. While one could argue that this is a property of the read_context, the read_context might not be around anymore when the symbol still is. Hence, persist the 'is_suppressed' state along with the symbol itself. * include/abg-ir.h (elf_symbol::elf_symbol): Add is_suppressed parameter. (elf_symbol::create): Likewise. (elf_symbol::is_suppressed): New getter declaration. (elf_symbol::set_is_suppressed): New setter declaration. * src/abg-ir.cc (elf_symbol::priv::priv): Add is_suppressed parameter. (elf_symbol::priv::is_suppressed_): New field. (elf_symbol::elf_symbol): Add is_suppressed parameter. (elf_symbol::create): Likewise. (elf_symbol::is_suppressed): New getter implementation. (elf_symbol::set_is_suppressed): New setter implementation. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- include/abg-ir.h | 12 ++++++++++-- src/abg-ir.cc | 29 ++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/include/abg-ir.h b/include/abg-ir.h index d82c83592f82..23ba16bd327b 100644 --- a/include/abg-ir.h +++ b/include/abg-ir.h @@ -839,7 +839,8 @@ private: const version& ve, visibility vi, bool is_linux_string_cst = false, - bool is_in_ksymtab = false); + bool is_in_ksymtab = false, + bool is_suppressed = false); elf_symbol(const elf_symbol&); @@ -863,7 +864,8 @@ public: const version& ve, visibility vi, bool is_linux_string_cst = false, - bool is_in_ksymtab = false); + bool is_in_ksymtab = false, + bool is_suppressed = false); const environment* get_environment() const; @@ -937,6 +939,12 @@ public: void set_is_in_ksymtab(bool is_in_ksymtab); + bool + is_suppressed() const; + + void + set_is_suppressed(bool is_suppressed); + const elf_symbol_sptr get_main_symbol() const; diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 22532cc87dfd..1ba95dd6c14f 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -1311,6 +1311,7 @@ struct elf_symbol::priv bool is_common_; bool is_linux_string_cst_; bool is_in_ksymtab_; + bool is_suppressed_; elf_symbol_wptr main_symbol_; elf_symbol_wptr next_alias_; elf_symbol_wptr next_common_instance_; @@ -1326,7 +1327,8 @@ struct elf_symbol::priv is_defined_(false), is_common_(false), is_linux_string_cst_(false), - is_in_ksymtab_(false) + is_in_ksymtab_(false), + is_suppressed_(false) {} priv(const environment* e, @@ -1340,7 +1342,8 @@ struct elf_symbol::priv const elf_symbol::version& ve, elf_symbol::visibility vi, bool is_linux_string_cst, - bool is_in_ksymtab) + bool is_in_ksymtab, + bool is_suppressed) : env_(e), index_(i), size_(s), @@ -1352,7 +1355,8 @@ struct elf_symbol::priv is_defined_(d), is_common_(c), is_linux_string_cst_(is_linux_string_cst), - is_in_ksymtab_(is_in_ksymtab) + is_in_ksymtab_(is_in_ksymtab), + is_suppressed_(is_suppressed) { if (!is_common_) is_common_ = type_ == COMMON_TYPE; @@ -1409,7 +1413,8 @@ elf_symbol::elf_symbol(const environment* e, const version& ve, visibility vi, bool is_linux_string_cst, - bool is_in_ksymtab) + bool is_in_ksymtab, + bool is_suppressed) : priv_(new priv(e, i, s, @@ -1421,7 +1426,8 @@ elf_symbol::elf_symbol(const environment* e, ve, vi, is_linux_string_cst, - is_in_ksymtab)) + is_in_ksymtab, + is_suppressed)) {} /// Factory of instances of @ref elf_symbol. @@ -1479,11 +1485,12 @@ elf_symbol::create(const environment* e, const version& ve, visibility vi, bool is_linux_string_cst, - bool is_in_ksymtab) + bool is_in_ksymtab, + bool is_suppressed) { elf_symbol_sptr sym(new elf_symbol(e, i, s, n, t, b, d, c, ve, vi, is_linux_string_cst, - is_in_ksymtab)); + is_in_ksymtab, is_suppressed)); sym->priv_->main_symbol_ = sym; return sym; } @@ -1711,6 +1718,14 @@ void elf_symbol::set_is_in_ksymtab(bool is_in_ksymtab) {priv_->is_in_ksymtab_ = is_in_ksymtab;} +bool +elf_symbol::is_suppressed() const +{return priv_->is_suppressed_;} + +void +elf_symbol::set_is_suppressed(bool is_suppressed) +{priv_->is_suppressed_ = is_suppressed;} + /// @name Elf symbol aliases /// /// An alias A for an elf symbol S is a symbol that is defined at the From patchwork Wed Jan 27 12:58:37 2021 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: 41838 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 D17963971C3C; Wed, 27 Jan 2021 12:59:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D17963971C3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752358; bh=IEj+VDlJ6TcTEtpciyhJQZfM3Vt/s/2x1yOHuFtKw/o=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=tkbjx7a53FD4HiAzCTGR+Dn5UFAjK8ARP4piqIWeCJ/8M7B+ZDEVn54FRlNFGGzRe Blf8pmIBr4OR/Pfl3ZOqYCmRIXu6rCJOyoJw056yswJ9Kw/URrAEUp8NLegP6ZJU1S hDXRbkrQ5c9+6p5qSImeqTIvYAtIp8MEAHQwNj3M= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by sourceware.org (Postfix) with ESMTPS id 8CEB43971C3C for ; Wed, 27 Jan 2021 12:59:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8CEB43971C3C Received: by mail-qt1-x849.google.com with SMTP id f5so1011413qtf.15 for ; Wed, 27 Jan 2021 04:59:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=IEj+VDlJ6TcTEtpciyhJQZfM3Vt/s/2x1yOHuFtKw/o=; b=GG1D3YPiWBKU6W3nfJvXU4meiGcli11ogPL4QnAkYj2DPxag6TO7R58UgsiPnMCi78 vu8/8sk6qBq0JPlq5GTc6iFHtBPCLEGH2k5h3Ug+HomOj4pWwuaZNRPNLcYED1OQh3Y1 9E9+Fc8IYetn668akVlbof/UP7Ky9RP9awMvDbr2me3Dd1Ve+Z/tiVNjkxt9iDwjKlAV QQQw4JU0q/tSL4nJGMM3ahf6QLGozEYXSGZtkt5MxY05AdGJA9G/u9Og9qQMBzkH0pF2 gjX2B/0ltWqJLKAz5CGbCN/6z36M3ya/dIdZcNPxCzIMRXOALYwbptCmhOEws9ESS3rk +NnQ== X-Gm-Message-State: AOAM532iGa7G+LZyeJW7FifT5dEEEjYUM72TDHnJ/SfJhySpTk0iQoBy tRxOwlPXbFdTzTPi3fsNt7xeUFJUadGS/H3urXTCxzYAOw8Xu5UPT8kdXWb1+o3t6pV3vhnUr+X TMWGnK6OAz+G4eAAwyteT7IHUZzB9lhsI8bMI5KTGCGL9y0m1VjX6Hid/h9JN/6XwSba4U48= X-Google-Smtp-Source: ABdhPJy5MmP8lUHwTxg4xTULSfjKSurWpBxw0vlGdsg8g1I+KmQ0GunaBGEdPaQreFtn3ESo7fCSOLEyn01Qzg== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:a0c:c30e:: with SMTP id f14mr10184150qvi.48.1611752355002; Wed, 27 Jan 2021 04:59:15 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:37 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-5-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 04/20] dwarf-reader split: create abg-symtab-reader.{h, cc} and test case To: libabigail@sourceware.org X-Spam-Status: No, score=-22.2 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" abg-symtab-reader.{h,cc} shall contain the refactored symtab reader. Create the stub files, an empty unit test and hook everything up in the make system. * src/abg-symtab-reader.h: New header file. * src/abg-symtab-reader.cc: New source file. * src/Makefile.am: Add new source files. * tests/Makefile.am: Add new test case runtestsymtabreader. * tests/test-symtab-reader.cc: New test source file. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- src/Makefile.am | 2 ++ src/abg-symtab-reader.cc | 21 +++++++++++++++++++++ src/abg-symtab-reader.h | 24 ++++++++++++++++++++++++ tests/Makefile.am | 4 ++++ tests/test-symtab-reader.cc | 15 +++++++++++++++ 5 files changed, 66 insertions(+) create mode 100644 src/abg-symtab-reader.cc create mode 100644 src/abg-symtab-reader.h create mode 100644 tests/test-symtab-reader.cc diff --git a/src/Makefile.am b/src/Makefile.am index 26fc4d1566ca..86877635be03 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,6 +38,8 @@ abg-tools-utils.cc \ abg-elf-helpers.h \ abg-elf-helpers.cc \ abg-regex.cc \ +abg-symtab-reader.h \ +abg-symtab-reader.cc \ $(VIZ_SOURCES) libabigail_la_LIBADD = $(DEPS_LIBS) diff --git a/src/abg-symtab-reader.cc b/src/abg-symtab-reader.cc new file mode 100644 index 000000000000..a6c8ca0ef548 --- /dev/null +++ b/src/abg-symtab-reader.cc @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// -*- Mode: C++ -*- +// +// Copyright (C) 2020 Google, Inc. +// +// Author: Matthias Maennich + +/// @file +/// +/// This contains the definition of the symtab reader + +#include "abg-symtab-reader.h" + +namespace abigail +{ + +namespace symtab_reader +{ + +} // end namespace symtab_reader +} // end namespace abigail diff --git a/src/abg-symtab-reader.h b/src/abg-symtab-reader.h new file mode 100644 index 000000000000..a929166b83ef --- /dev/null +++ b/src/abg-symtab-reader.h @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// -*- Mode: C++ -*- +// +// Copyright (C) 2020 Google, Inc. +// +// Author: Matthias Maennich + +/// @file +/// +/// This contains the declarations for the symtab reader. + +#ifndef __ABG_SYMTAB_READER_H__ +#define __ABG_SYMTAB_READER_H__ + +namespace abigail +{ + +namespace symtab_reader +{ + +} // end namespace symtab_reader +} // end namespace abigail + +#endif // __ABG_SYMTAB_READER_H__ diff --git a/tests/Makefile.am b/tests/Makefile.am index 655facb19ec1..533cc23680ce 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -46,6 +46,7 @@ runtestkmiwhitelist \ runtestlookupsyms \ runtestreadwrite \ runtestsymtab \ +runtestsymtabreader \ runtesttoolsutils \ runtestsvg \ $(FEDABIPKGDIFF_TEST) \ @@ -156,6 +157,9 @@ runtestcxxcompat_LDADD = libcatch.la $(top_builddir)/src/libabigail.la runtestsymtab_SOURCES = test-symtab.cc runtestsymtab_LDADD = libtestutils.la libcatch.la $(top_builddir)/src/libabigail.la +runtestsymtabreader_SOURCES = test-symtab-reader.cc +runtestsymtabreader_LDADD = libcatch.la $(top_builddir)/src/libabigail.la + runtestsvg_SOURCES=test-svg.cc runtestsvg_LDADD=$(top_builddir)/src/libabigail.la diff --git a/tests/test-symtab-reader.cc b/tests/test-symtab-reader.cc new file mode 100644 index 000000000000..1bd37572f4d7 --- /dev/null +++ b/tests/test-symtab-reader.cc @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// -*- Mode: C++ -*- +// +// Copyright (C) 2020 Google, Inc. +// +// Author: Matthias Maennich + +/// @file +/// +/// This program tests libabigail's symtab reader. + +#include "lib/catch.hpp" + +#include "abg-symtab-reader.h" + From patchwork Wed Jan 27 12:58:38 2021 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: 41839 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 26EF53972827; Wed, 27 Jan 2021 12:59:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26EF53972827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752362; bh=NL5VusAhaxB7NQAPdqJZJyyOGstyDNFXX/J5YX7cqFI=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=OazQDl+KRE1J+ASoipJse54jQQkAuha+U11m2ijnjq7vK5CEI77SlDWgeTYTtSdui /1zE/M5gUbmVMqMFTYcXrCw2BqgDqUv+jCUA9gqTuL+qV6sR+BVy67q+PP2dwZMek+ k3Gyn16t4UPMj19Yn9KufPxfni3dMiqaOcsD/uCM= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by sourceware.org (Postfix) with ESMTPS id E9CD33971830 for ; Wed, 27 Jan 2021 12:59:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E9CD33971830 Received: by mail-qk1-x749.google.com with SMTP id m64so1368613qke.12 for ; Wed, 27 Jan 2021 04:59:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=NL5VusAhaxB7NQAPdqJZJyyOGstyDNFXX/J5YX7cqFI=; b=XWI/5UDtkhOUNXr54QF1Tuh0UIYcVvd4IeKHSxMUjDjzbzR+YN1aHoITHaYMfHP9g/ QQriIasVzKr2QcuEXB8vnnoRoH3fqOqOc+7PEd7LiJRyFW5mZjsHm1CK//BP/vKtnXzG 8ObcdXDaAxqZt4zxsbA27jhi2/X3wVK8HkFkPPWXxJv4xWzpMYKzv9p8i9BmvHNRoHjK DxkHeBXup9t4cnZTqgTHncS6rxGHxiuxHdptN2H330qghx2iff2VDATE+rHbqEUZObuz 88NJrZrcMAJIDycjB/zrRNTkW7aWLFZvgnM3/Fw8uD9DgkN6d5EF0drR+NtNrGcc2GhF mSHQ== X-Gm-Message-State: AOAM5317S+vKG8CbzlsR9JSeQrg/f9zf3LxJp2Hf4TpzAAYuSvrel2SY bTSLrVMswggDE3YwpB5XsBaUv2AkoCaA4tb/77pY5rBogMNriTFSpOTl2a2CDx/VIgWr11JLGS4 UENc1q8SbKO/WQfXq92U/LYtbUYqJG3PvrfZJOAf4JzxLe/69IvIcQSfeOYVJ+VBea2nSPCA= X-Google-Smtp-Source: ABdhPJwxLvxi4g+Jya9oAOfhBLkzarnXioUDwX0uHFAvilBTZLosqqKskmWCbSxHqfJPp4nHppa+taL93tK/wQ== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:a0c:fd64:: with SMTP id k4mr10118522qvs.3.1611752357494; Wed, 27 Jan 2021 04:59:17 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:38 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-6-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 05/20] Refactor ELF symbol table reading by adding a new symtab reader To: libabigail@sourceware.org X-Spam-Status: No, score=-22.6 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" Based on existing functionality, implement the reading of ELF symbol tables as a separate component. This reduces the complexity of abg-dwarf-reader's read_context by separating and delegating the functionality. This also allows dedicated testing. The new namespace symtab_reader contains a couple of new components that work loosely coupled together. Together they allow for a consistent view on a symbol table. With filter criteria those views can be restricted, iterated and consistent lookup maps can be built on top of them. While this implementation tries to address some shortcomings of the previous model, it still provides the high level interfaces to the symbol table contents through sorted iterating and name/address mapped access. symtab_reader::symtab While the other classes in the same namespace are merely helpers, this is the main implementation of symtab reading and storage. Symtab objects are factory created to ensure a consistent construction and valid invariants. Thus a symtab will be loaded by either passing an ELF handle (when reading from binary) or by passing a set of function/variable symbol maps (when reading from XML). When constructed they are considered const and are not writable anymore. As such, all public methods are const. The load reuses the existing implementation for loading symtab sections, but since the new implementation does not distinguish between functions and variables, the code could be simplified. The support for ppc64 function entry addresses has been deferred to a later commit. Linux Kernel symbol tables are now directly loaded by name when encountering symbols prefixed with the __ksymtab_ as per convention. This has been tricky in the past due to various different binary layouts (relocations, position relative relocations, symbol namespaces, CFI indirections, differences between vmlinux and kernel modules). Thus the new implementation is much simpler and is less vulnerable to future ksymtab changes. As we are also not looking up the Kernel symbols by addresses, we could resolve shortcomings with symbol aliasing: Previously a symbol and its alias were indistinguishable as they are having the same symbol address. We could not identify the one that is actually exported via ksymtab. One major architectural difference of this implementation is that we do not early discard suppressed symbols. While we keep them out of the vector of exported symbols, we still make them available for lookup. That helps addressing issues when looking up a symbol by address (e.g. from the ksymtab read implementation) that is suppressed. That would fail in the existing implementation. Still, we intend to only instantiate each symbol once and pass around shared_ptr instances to refer to it from the vector as well as from the lookup maps. For reading, there are two access paths that serve the existing patterns: 1) lookup_symbol: either via a name or an address 2) filtered iteration with begin(), end() The former is used for direct access with a clue in hand (like a name or an address), the latter is used for iteration (e.g. when emitting the XML). symtab_reader::symtab_iterator The symtab_iterator is an STL compatible iterator that is returned from begin() and end() of the symtab. It allows usual forward iterator operations and can optionally take a filter predicate to skip non matching elements. symtab_reader::symtab_filter The symtab_filter serves as a predicate for the symtab_iterator by providing a matches(const elf_symbol_sptr&) function. The predicate is built by ANDing together several conditions on attributes a symbol can have. The filter conditions are implemented in terms of std::optional members to allow a tristate: "needs to have the condition set", "must not have it set" and "don't care". symtab_reader::filtered_symtab The filtered_symtab is a convenience zero cost abstraction that allows prepopulating the symtab_filter (call it a capture) such that begin() and end() are now accessible without the need to pass the filter again. Argumentless begin() and end() are a requirement for range-for loops and other STL based algorithms. * src/abg-symtab-reader.h (symtab_filter): New class. (symtab_iterator): Likewise. (symtab): Likewise. (filtered_symtab): Likewise. * src/abg-symtab-reader.cc (symtab_filter::matches): New. (symtab::make_filter): Likewise. (symtab::lookup_symbol): Likewise. (symbol_sort): Likewise. (symtab::load): Likewise. (symtab::load_): Likewise. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- src/abg-symtab-reader.cc | 347 +++++++++++++++++++++++++++++++++++++++ src/abg-symtab-reader.h | 277 ++++++++++++++++++++++++++++++- 2 files changed, 623 insertions(+), 1 deletion(-) diff --git a/src/abg-symtab-reader.cc b/src/abg-symtab-reader.cc index a6c8ca0ef548..4576be2a0b42 100644 --- a/src/abg-symtab-reader.cc +++ b/src/abg-symtab-reader.cc @@ -1,6 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -*- Mode: C++ -*- // +// Copyright (C) 2013-2020 Red Hat, Inc. // Copyright (C) 2020 Google, Inc. // // Author: Matthias Maennich @@ -9,7 +10,20 @@ /// /// This contains the definition of the symtab reader +#include +#include +#include + +#include "abg-elf-helpers.h" +#include "abg-fwd.h" +#include "abg-internal.h" +#include "abg-tools-utils.h" + +// Though this is an internal header, we need to export the symbols to be able +// to test this code. TODO: find a way to export symbols just for unit tests. +ABG_BEGIN_EXPORT_DECLARATIONS #include "abg-symtab-reader.h" +ABG_END_EXPORT_DECLARATIONS namespace abigail { @@ -17,5 +31,338 @@ namespace abigail namespace symtab_reader { +/// symtab_filter implementations + +/// Determine whether a symbol is matching the filter criteria of this filter +/// object. In terms of a filter functionality, you would _not_ filter out +/// this symbol if it passes this (i.e. returns true). +/// +/// @param symbol The Elf symbol under test. +/// +/// @return whether the symbol matches all relevant / required criteria +bool +symtab_filter::matches(const elf_symbol& symbol) const +{ + if (functions_ && *functions_ != symbol.is_function()) + return false; + if (variables_ && *variables_ != symbol.is_variable()) + return false; + if (public_symbols_ && *public_symbols_ != symbol.is_public()) + return false; + if (undefined_symbols_ && *undefined_symbols_ == symbol.is_defined()) + return false; + if (kernel_symbols_ && *kernel_symbols_ != symbol.is_in_ksymtab()) + return false; + + return true; +} + +/// symtab implementations + +/// Obtain a suitable default filter for iterating this symtab object. +/// +/// The symtab_filter obtained is populated with some sensible default +/// settings, such as public_symbols(true) and kernel_symbols(true) if the +/// binary has been identified as Linux Kernel binary. +/// +/// @return a symtab_filter with sensible populated defaults +symtab_filter +symtab::make_filter() const +{ + symtab_filter filter; + filter.set_public_symbols(); + if (is_kernel_binary_) + filter.set_kernel_symbols(); + return filter; +} + +/// Get a vector of symbols that are associated with a certain name +/// +/// @param name the name the symbols need to match +/// +/// @return a vector of symbols, empty if no matching symbols have been found +const elf_symbols& +symtab::lookup_symbol(const std::string& name) const +{ + static const elf_symbols empty_result; + const auto it = name_symbol_map_.find(name); + if (it != name_symbol_map_.end()) + return it->second; + return empty_result; +} + +/// Lookup a symbol by its address +/// +/// @param symbol_addr the starting address of the symbol +/// +/// @return a symbol if found, else an empty sptr +const elf_symbol_sptr& +symtab::lookup_symbol(GElf_Addr symbol_addr) const +{ + static const elf_symbol_sptr empty_result; + const auto it = addr_symbol_map_.find(symbol_addr); + if (it != addr_symbol_map_.end()) + return it->second; + return empty_result; +} + +/// A symbol sorting functor. +static struct +{ + bool + operator()(const elf_symbol_sptr& left, const elf_symbol_sptr& right) + { return left->get_id_string() < right->get_id_string(); } +} symbol_sort; + +/// Construct a symtab object and instantiate from an ELF handle. Also pass +/// in an ir::environment handle to interact with the context we are living +/// in. If specified, the symbol_predicate will be respected when creating +/// the full vector of symbols. +symtab_ptr +symtab::load(Elf* elf_handle, + ir::environment* env, + symbol_predicate is_suppressed) +{ + ABG_ASSERT(elf_handle); + ABG_ASSERT(env); + + symtab_ptr result(new symtab); + if (!result->load_(elf_handle, env, is_suppressed)) + return {}; + + return result; +} + +/// Construct a symtab object from existing name->symbol lookup maps. +/// They were possibly read from a different representation (XML maybe). +symtab_ptr +symtab::load(string_elf_symbols_map_sptr function_symbol_map, + string_elf_symbols_map_sptr variables_symbol_map) +{ + symtab_ptr result(new symtab); + if (!result->load_(function_symbol_map, variables_symbol_map)) + return {}; + + return result; +} + +symtab::symtab() : is_kernel_binary_(false), has_ksymtab_entries_(false) {} + +/// Load the symtab representation from an Elf binary presented to us by an +/// Elf* handle. +/// +/// This method iterates over the entries of .symtab and collects all +/// interesting symbols (functions and variables). +/// +/// In case of a Linux Kernel binary, it also collects information about the +/// symbols exported via EXPORT_SYMBOL in the Kernel that would then end up +/// having a corresponding __ksymtab entry. +/// +/// Symbols that are suppressed will be omitted from the symbols_ vector, but +/// still be discoverable through the name->symbol and addr->symbol lookup +/// maps. +bool +symtab::load_(Elf* elf_handle, + ir::environment* env, + symbol_predicate is_suppressed) +{ + + Elf_Scn* symtab_section = elf_helpers::find_symbol_table_section(elf_handle); + if (!symtab_section) + { + std::cerr << "No symbol table found: Skipping symtab load.\n"; + return false; + } + + GElf_Shdr symtab_sheader; + gelf_getshdr(symtab_section, &symtab_sheader); + + // check for bogus section header + if (symtab_sheader.sh_entsize == 0) + { + std::cerr << "Invalid symtab header found: Skipping symtab load.\n"; + return false; + } + + const size_t number_syms = + symtab_sheader.sh_size / symtab_sheader.sh_entsize; + + Elf_Data* symtab = elf_getdata(symtab_section, 0); + if (!symtab) + { + std::cerr << "Could not load elf symtab: Skipping symtab load.\n"; + return false; + } + + const bool is_kernel = elf_helpers::is_linux_kernel(elf_handle); + std::unordered_set exported_kernel_symbols; + + for (size_t i = 0; i < number_syms; ++i) + { + GElf_Sym *sym, sym_mem; + sym = gelf_getsym(symtab, i, &sym_mem); + if (!sym) + { + std::cerr << "Could not load symbol with index " << i + << ": Skipping symtab load.\n"; + return false; + } + + const char* const name_str = + elf_strptr(elf_handle, symtab_sheader.sh_link, sym->st_name); + + // no name, no game + if (!name_str) + continue; + + const std::string name = name_str; + if (name.empty()) + continue; + + // Handle ksymtab entries. Every symbol entry that starts with __ksymtab_ + // indicates that the symbol in question is exported through ksymtab. We + // do not know whether this is ksymtab_gpl or ksymtab, but that is good + // enough for now. + // + // We could follow up with this entry: + // + // symbol_value -> ksymtab_entry in either ksymtab_gpl or ksymtab + // -> addr/name/namespace (in case of PREL32: offset) + // + // That way we could also detect ksymtab<>ksymtab_gpl changes or changes + // of the symbol namespace. + // + // As of now this lookup is fragile, as occasionally ksymtabs are empty + // (seen so far for kernel modules and LTO builds). Hence we stick to the + // fairly safe assumption that ksymtab exported entries are having an + // appearence as __ksymtab_ in the symtab. + if (is_kernel && name.rfind("__ksymtab_", 0) == 0) + { + ABG_ASSERT(exported_kernel_symbols.insert(name.substr(10)).second); + continue; + } + + // filter out uninteresting entries and only keep functions/variables for + // now. The rest might be interesting in the future though. + const int sym_type = GELF_ST_TYPE(sym->st_info); + if (!(sym_type == STT_FUNC + || sym_type == STT_GNU_IFUNC + // If the symbol is for an OBJECT, the index of the + // section it refers to cannot be absolute. + // Otherwise that OBJECT is not a variable. + || (sym_type == STT_OBJECT && sym->st_shndx != SHN_ABS) + || sym_type == STT_TLS)) + continue; + + const bool sym_is_defined = sym->st_shndx != SHN_UNDEF; + // this occurs in relocatable files. + const bool sym_is_common = sym->st_shndx == SHN_COMMON; + + elf_symbol::version ver; + elf_helpers::get_version_for_symbol(elf_handle, i, sym_is_defined, ver); + + const elf_symbol_sptr& symbol_sptr = elf_symbol::create( + env, i, sym->st_size, name, + elf_helpers::stt_to_elf_symbol_type(GELF_ST_TYPE(sym->st_info)), + elf_helpers::stb_to_elf_symbol_binding(GELF_ST_BIND(sym->st_info)), + sym_is_defined, sym_is_common, ver, + elf_helpers::stv_to_elf_symbol_visibility( + GELF_ST_VISIBILITY(sym->st_other)), + false); // TODO: is_linux_strings_cstr + + // We do not take suppressed symbols into our symbol vector to avoid + // accidental leakage. But we ensure supressed symbols are otherwise set + // up for lookup. + if (!(is_suppressed && is_suppressed(symbol_sptr))) + // add to the symbol vector + symbols_.push_back(symbol_sptr); + else + symbol_sptr->set_is_suppressed(true); + + // add to the name->symbol lookup + name_symbol_map_[name].push_back(symbol_sptr); + + // add to the addr->symbol lookup + if (symbol_sptr->is_common_symbol()) + { + const auto it = name_symbol_map_.find(name); + ABG_ASSERT(it != name_symbol_map_.end()); + const elf_symbols& common_sym_instances = it->second; + ABG_ASSERT(!common_sym_instances.empty()); + if (common_sym_instances.size() > 1) + { + elf_symbol_sptr main_common_sym = common_sym_instances[0]; + ABG_ASSERT(main_common_sym->get_name() == name); + ABG_ASSERT(main_common_sym->is_common_symbol()); + ABG_ASSERT(symbol_sptr.get() != main_common_sym.get()); + main_common_sym->add_common_instance(symbol_sptr); + } + } + else if (symbol_sptr->is_defined()) + { + const GElf_Addr symbol_value = + elf_helpers::maybe_adjust_et_rel_sym_addr_to_abs_addr(elf_handle, + sym); + + const auto result = + addr_symbol_map_.emplace(symbol_value, symbol_sptr); + if (!result.second) + result.first->second->get_main_symbol()->add_alias(symbol_sptr); + } + } + + is_kernel_binary_ = elf_helpers::is_linux_kernel(elf_handle); + + // Now apply the ksymtab_exported attribute to the symbols we collected. + for (const auto& symbol : exported_kernel_symbols) + { + const auto r = name_symbol_map_.find(symbol); + if (r == name_symbol_map_.end()) + continue; + + for (const auto& elf_symbol : r->second) + if (elf_symbol->is_public()) + elf_symbol->set_is_in_ksymtab(true); + has_ksymtab_entries_ = true; + } + + // sort the symbols for deterministic output + std::sort(symbols_.begin(), symbols_.end(), symbol_sort); + + return true; +} + +/// Load the symtab representation from a function/variable lookup map pair. +/// +/// This method assumes the lookup maps are correct and sets up the data +/// vector as well as the name->symbol lookup map. The addr->symbol lookup +/// map cannot be set up in this case. +bool +symtab::load_(string_elf_symbols_map_sptr function_symbol_map, + string_elf_symbols_map_sptr variables_symbol_map) + +{ + if (function_symbol_map) + for (const auto& symbol_map_entry : *function_symbol_map) + { + symbols_.insert(symbols_.end(), symbol_map_entry.second.begin(), + symbol_map_entry.second.end()); + ABG_ASSERT(name_symbol_map_.insert(symbol_map_entry).second); + } + + if (variables_symbol_map) + for (const auto& symbol_map_entry : *variables_symbol_map) + { + symbols_.insert(symbols_.end(), symbol_map_entry.second.begin(), + symbol_map_entry.second.end()); + ABG_ASSERT(name_symbol_map_.insert(symbol_map_entry).second); + } + + // sort the symbols for deterministic output + std::sort(symbols_.begin(), symbols_.end(), symbol_sort); + + return true; +} + } // end namespace symtab_reader } // end namespace abigail diff --git a/src/abg-symtab-reader.h b/src/abg-symtab-reader.h index a929166b83ef..4c5e3b85c22d 100644 --- a/src/abg-symtab-reader.h +++ b/src/abg-symtab-reader.h @@ -12,12 +12,287 @@ #ifndef __ABG_SYMTAB_READER_H__ #define __ABG_SYMTAB_READER_H__ +#include + +#include +#include +#include +#include +#include + +#include "abg-cxx-compat.h" // for abg_compat::optional +#include "abg-ir.h" + namespace abigail { - namespace symtab_reader { +/// The symtab filter is the object passed to the symtab object in order to +/// iterate over the symbols in the symtab while applying filters. +/// +/// The general idea is that it consists of a set of optionally enforced flags, +/// such as 'functions' or 'variables'. If not set, those are not filtered for, +/// neither inclusive nor exclusive. If set they are all ANDed together. +class symtab_filter +{ +public: + // Default constructor disabling all features. + symtab_filter() {} + + bool + matches(const elf_symbol& symbol) const; + + void + set_functions(bool new_value = true) + { functions_ = new_value; }; + + void + set_variables(bool new_value = true) + { variables_ = new_value; }; + + void + set_public_symbols(bool new_value = true) + { public_symbols_ = new_value; }; + + void + set_undefined_symbols(bool new_value = true) + { undefined_symbols_ = new_value; }; + + void + set_kernel_symbols(bool new_value = true) + { kernel_symbols_ = new_value; }; + +private: + // The symbol is a function (FUNC) + abg_compat::optional functions_; + + // The symbol is a variables (OBJECT) + abg_compat::optional variables_; + + // The symbol is publicly accessible (global/weak with default/protected + // visibility) + abg_compat::optional public_symbols_; + + // The symbols is not defined (declared) + abg_compat::optional undefined_symbols_; + + // The symbol is listed in the ksymtab (for Linux Kernel binaries). + abg_compat::optional kernel_symbols_; +}; + +/// Base iterator for our custom iterator based on whatever the const_iterator +/// is for a vector of symbols. +/// As of writing this, std::vector::const_iterator. +typedef elf_symbols::const_iterator base_iterator; + +/// An iterator to walk a vector of elf_symbols filtered by symtab_filter. +/// +/// The implementation inherits all properties from the vector's +/// const_iterator, but intercepts where necessary to allow effective +/// filtering. This makes it a STL compatible iterator for general purpose +/// usage. +class symtab_iterator : public base_iterator +{ +public: + typedef base_iterator::value_type value_type; + typedef base_iterator::reference reference; + typedef base_iterator::pointer pointer; + typedef base_iterator::difference_type difference_type; + typedef std::forward_iterator_tag iterator_category; + + /// Construct the iterator based on a pair of underlying iterators and a + /// symtab_filter object. Immediately fast forward to the next element that + /// matches the criteria (if any). + symtab_iterator(base_iterator begin, + base_iterator end, + const symtab_filter& filter = symtab_filter()) + : base_iterator(begin), end_(end), filter_(filter) + { skip_to_next(); } + + /// Pre-increment operator to advance to the next matching element. + symtab_iterator& + operator++() + { + base_iterator::operator++(); + skip_to_next(); + return *this; + } + + /// Post-increment operator to advance to the next matching element. + symtab_iterator + operator++(int) + { + symtab_iterator result(*this); + ++(*this); + return result; + } + +private: + /// The end of the underlying iterator. + const base_iterator end_; + + /// The symtab_filter used to determine when to advance. + const symtab_filter& filter_; + + /// Skip to the next element that matches the filter criteria (if any). Hold + /// off when reaching the end of the underlying iterator. + void + skip_to_next() + { + while (*this != end_ && !filter_.matches(***this)) + ++(*this); + } +}; + +/// Convenience declaration of a unique_ptr +class symtab; +typedef std::unique_ptr symtab_ptr; + +/// symtab is the actual data container of the symtab_reader implementation. +/// +/// The symtab is instantiated either via an Elf handle (from binary) or from a +/// set of existing symbol maps (usually when instantiated from XML). It will +/// then discover the symtab, possibly the ksymtab (for Linux Kernel binaries) +/// and setup the data containers and lookup maps for later perusal. +/// +/// The symtab is supposed to be used in a const context as all information is +/// already computed at construction time. Symbols are stored sorted to allow +/// deterministic reading of the entries. +/// +/// An example use of the symtab class is +/// +/// const auto symtab = symtab::load(elf_handle, env); +/// symtab_filter filter = symtab->make_filter(); +/// filter.set_public_symbols(); +/// filter.set_functions(); +/// +/// for (const auto& symbol : filtered_symtab(*symtab, filter)) +/// { +/// std::cout << symbol->get_name() << "\n"; +/// } +/// +/// This uses the filtered_symtab proxy object to capture the filter. +class symtab +{ +public: + typedef std::function symbol_predicate; + + /// Indicate whether any (kernel) symbols have been seen at construction. + /// + /// @return true if there are symbols detected earlier. + bool + has_symbols() const + { return is_kernel_binary_ ? has_ksymtab_entries_ : !symbols_.empty(); } + + symtab_filter + make_filter() const; + + /// The (only) iterator type we offer is a const_iterator implemented by the + /// symtab_iterator. + typedef symtab_iterator const_iterator; + + /// Obtain an iterator to the beginning of the symtab according to the filter + /// criteria. Whenever this iterator advances, it skips elements that do not + /// match the filter criteria. + /// + /// @param filter the symtab_filter to match symbols against + /// + /// @return a filtering const_iterator of the underlying type + const_iterator + begin(const symtab_filter& filter) const + { return symtab_iterator(symbols_.begin(), symbols_.end(), filter); } + + /// Obtain an iterator to the end of the symtab. + /// + /// @return an end iterator + const_iterator + end() const + { return symtab_iterator(symbols_.end(), symbols_.end()); } + + const elf_symbols& + lookup_symbol(const std::string& name) const; + + const elf_symbol_sptr& + lookup_symbol(GElf_Addr symbol_addr) const; + + static symtab_ptr + load(Elf* elf_handle, + ir::environment* env, + symbol_predicate is_suppressed = NULL); + + static symtab_ptr + load(string_elf_symbols_map_sptr function_symbol_map, + string_elf_symbols_map_sptr variables_symbol_map); + +private: + /// Default constructor. Private to enforce creation by factory methods. + symtab(); + + /// The vector of symbols we discovered. + elf_symbols symbols_; + + /// Whether this is a Linux Kernel binary + bool is_kernel_binary_; + + /// Whether this kernel_binary has ksymtab entries + /// + /// A kernel module might not have a ksymtab if it does not export any + /// symbols. In order to quickly decide whether the symbol table is empty, we + /// remember whether we ever saw ksymtab entries. + bool has_ksymtab_entries_; + + /// Lookup map name->symbol(s) + typedef std::unordered_map> + name_symbol_map_type; + name_symbol_map_type name_symbol_map_; + + /// Lookup map addr->symbol + typedef std::unordered_map addr_symbol_map_type; + addr_symbol_map_type addr_symbol_map_; + + bool + load_(Elf* elf_handle, ir::environment* env, symbol_predicate is_suppressed); + + bool + load_(string_elf_symbols_map_sptr function_symbol_map, + string_elf_symbols_map_sptr variables_symbol_map); +}; + +/// Helper class to allow range-for loops on symtabs for C++11 and later code. +/// It serves as a proxy for the symtab iterator and provides a begin() method +/// without arguments, as required for range-for loops (and possibly other +/// iterator based transformations). +/// +/// Example usage: +/// +/// for (const auto& symbol : filtered_symtab(tab, filter)) +/// { +/// std::cout << symbol->get_name() << "\n"; +/// } +/// +class filtered_symtab +{ + const symtab& tab_; + const symtab_filter filter_; + +public: + /// Construct the proxy object keeping references to the underlying symtab + /// and the filter object. + filtered_symtab(const symtab& tab, const symtab_filter& filter) + : tab_(tab), filter_(filter) { } + + /// Pass through symtab.begin(), but also pass on the filter. + symtab::const_iterator + begin() const + { return tab_.begin(filter_); } + + /// Pass through symtab.end(). + symtab::const_iterator + end() const + { return tab_.end(); } +}; + } // end namespace symtab_reader } // end namespace abigail From patchwork Wed Jan 27 12:58:39 2021 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: 41840 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 9574B3971C3C; Wed, 27 Jan 2021 12:59:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9574B3971C3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752363; bh=B2FhkSnMPJ+1kl3QChFfkbmSY9GBeOA9IlGL5skJ+kU=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=WYSlps0WNU54Rm+RefQJY8ybf6GLMbxMAu9kWe8ggJ4M4t8hp44lDmtZySoHuNdju 866nEc6fope0PbH+BAUVGtvXriEc/wKZOh9fBUzv1htPDPXUlWLWr36/P71o0zOHoi GcLuP/q7srBWZ7slD+B38UxBIG6gvkA5rpvdLgUA= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by sourceware.org (Postfix) with ESMTPS id 4F3FD3971C3C for ; Wed, 27 Jan 2021 12:59:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4F3FD3971C3C Received: by mail-qv1-xf4a.google.com with SMTP id l3so1229144qvz.12 for ; Wed, 27 Jan 2021 04:59:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=B2FhkSnMPJ+1kl3QChFfkbmSY9GBeOA9IlGL5skJ+kU=; b=LC3FV5GChbjfq6H26mZfy4hZDAo3fWIxJG8rd1PkTylNNB94LQRramicK2s98LT80G +eFJD0vHti7RVLU3Rn+fBZq3MhVNvFwLwSY+Tk0ATP97rWScR+pCAqA47T/cCecBnGZX l7jG9jjWLdGP1REaHK7JoOsPn40fEgjSHbzXmTfXutfIgwtKmnFZpX9tOAsDPV5qDbEw pWx3OzRloUpU4OKY9v8DjsF5vhjN+LdNTHv+DbpJ0cya2n0Yc5tZYMH5HBpl67tGy3wC M3ZHA+rJgqZcZ7UPGIggFCBMlodyKNwje/GbgDZvO4oQFY6NSL7eb1QgNEsudh4rJBmq d+cg== X-Gm-Message-State: AOAM532NwW2iHM408/VsLx9oKk14NKH5FNSa/94Qpn+H+dv9zhNe13K9 m6GMkwtuUxEQ6TwjnhWX9NAdvlS1/O2VIomKfEncpqxCpoqNymc1r/OCGaF2eNComae+AIUd1It OTfMQevHNrGa4SiP+ttiLvJKT5RVYAFOoEsCK+ZL3I+WXKhb9EHpL16jVoISiXve4kXtccLg= X-Google-Smtp-Source: ABdhPJw7RGdH3l23IHOvUjmYAQ1w7oMBAFPBdWT8D3k9nyUS1tenisv4wJm7Hgiggr/Urgd3VjjUCN6d5V5EJw== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:a05:6214:48f:: with SMTP id ay15mr10114427qvb.58.1611752359787; Wed, 27 Jan 2021 04:59:19 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:39 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-7-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 06/20] Integrate new symtab reader into corpus and read_context To: libabigail@sourceware.org X-Spam-Status: No, score=-22.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 | 25 ++++++++++++++++++ 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, 59 insertions(+), 11 deletions(-) diff --git a/include/abg-corpus.h b/include/abg-corpus.h index e60b5013473b..425702182056 100644 --- a/include/abg-corpus.h +++ b/include/abg-corpus.h @@ -152,6 +152,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 bb839fe76315..76df1b51dae7 100644 --- a/include/abg-fwd.h +++ b/include/abg-fwd.h @@ -1375,6 +1375,14 @@ typedef vector suppressions_type; } // end namespace suppr +namespace symtab_reader +{ + +class symtab; +typedef std::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 a4a97adfd00a..290e19c60e67 100644 --- a/src/abg-corpus-priv.h +++ b/src/abg-corpus-priv.h @@ -17,6 +17,7 @@ #include "abg-internal.h" #include "abg-regex.h" #include "abg-sptr-utils.h" +#include "abg-symtab-reader.h" namespace abigail { @@ -684,6 +685,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 2c37e253cf88..0d5849ddac5d 100644 --- a/src/abg-corpus.cc +++ b/src/abg-corpus.cc @@ -23,6 +23,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" @@ -850,6 +851,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 4b39e966e385..9f533e64959c 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -44,6 +44,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 @@ -2259,6 +2260,9 @@ public: bool drop_undefined_syms_; read_context(); +private: + mutable symtab_reader::symtab_sptr symtab_; + public: /// Constructor of read_context. @@ -2408,6 +2412,8 @@ public: dt_soname_.clear(); elf_architecture_.clear(); + symtab_.reset(); + clear_per_translation_unit_data(); memset(&offline_callbacks_, 0, sizeof(offline_callbacks_)); @@ -5870,6 +5876,21 @@ public: return symbol; } + const symtab_reader::symtab_sptr& + symtab() const + { + if (!symtab_) + symtab_ = symtab_reader::symtab::load( + elf_handle(), options_.env, [&](const elf_symbol_sptr& symbol) { + return is_elf_symbol_suppressed(symbol); + }); + + 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. /// @@ -16012,6 +16033,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() @@ -17345,6 +17367,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 1fb0cf7d1074..68b19cf4b65b 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -33,6 +33,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" @@ -1907,6 +1908,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^FHZg!mpGu0p>x*?7 zQ>+SmbUi{BDa=&z2Co|A;DWAO=#8Hp8X4`4MNgd{JUM!LXmGBSyIgRK-^l5T+*nN< zUz+>P>kB7XB^RhAKaN;j+u8~dItlv;Hwa}yg^E=GcA*nkoM)8t`c1_;F{ZxA$L0~!keTv z;X}8?jQGyo#udPQN>k4YvBP62H-i}38TK`a49qy;sc!+ur$O%AUnfxqd9azeAlmLP z`e7gdgfxwcMqKw;=yK6o?xh*;xLg_2NZKZbwuYZVw5`1>+7gMjc7~6%L?g|eSkl<~ z{{_TlT{XrVujr%wu@U^{PjQjfXUGCkqd)!B0ZJ*19R~t?4RV7T@f@ZCKEsbjRa&A- Gt$zTQCEAJr delta 769 zcmYjPO=uHA6rPt&tQ(Uy+mLRmfhLHOs?Gl7XR~cF5sGcW9~6V+lp+dMywrnjJTz(j zJKFexS`cbZA_yKrK~Igh9PLT;pqCy6Jy>W((An&6>0{=7^SycV-kUe`zFJ>cNy^0> z+mj;8vxBV2WH!(!B>Zi`-f0VsTPcyqX4GgZqSra&ZG3qwF^|Js#2gKwL-oYf&gaYe z@1AET?rp9f>8ssbT)rK#e63L3iG)|dE6)s~LWx*wQCJQ@_0B#GZCklpe?#8BR$O|} zi+U{5rZ6W#aPL=UZy~ay8qbXEJQ;Sd#Ynm+dvK7u`e9{Jl5RXE7 zge3gqJN+!qnG99GJIL2XyB?>D>@26mg4oa%3gD+cDIDUb=d>`+r4JACsHdI!9oXpl zOQ@w~9{+iIWW>Y#Y=@`ZFI!zNZY=J%GWG{ek4z#G8JUiDb-~i8XTIZ3cA}>;edT=R z`VBO*5o~22Vm`No?Oa&gds;|_A-S!0F^00CNN&SjT)--~y3gWb37Q_p4 X-Patchwork-Id: 41841 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 DD1A73973009; Wed, 27 Jan 2021 12:59:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD1A73973009 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752365; bh=2oMhQD0te+7uH1CsgcygqjHyzCdfmH05pkiKfvpM408=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ZOtH1viueCXW/dS3vSN8lZOqbKGmRDsbMV9p2kK03mE/YVjS7xM+gybNKB+kyIhDw 1NXFWY3aYRvtdgova266vQbX/qb9WWKUs5BWJ0K64VkyX2ErmFdEpuJfYslCo+F6UK 4ndeshY7ToRgAPIwMurxdjKGFpZGr3HfOuSs02VU= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by sourceware.org (Postfix) with ESMTPS id 7A67F3973009 for ; Wed, 27 Jan 2021 12:59:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7A67F3973009 Received: by mail-qt1-x849.google.com with SMTP id d26so1026675qtr.0 for ; Wed, 27 Jan 2021 04:59:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=2oMhQD0te+7uH1CsgcygqjHyzCdfmH05pkiKfvpM408=; b=APQUJ4fyUBe99putKKT1q1bu5BfAIRfHMHRuJXKen/csUVnbFFXxVBTMVLOUM9+d39 i+GU3oJugQMosbQXZZeP4NchQxwBG9a5zuNyufEjGTa0kLwxW8OG1UDEaNYs0w1gp2Cy PN49TzYoSf7FMsvhaXX71iNcLl5ILe1COsphSOTUUY6oHC6+hE4p5cf766xT/zL2jQ7r zzydgkEdLb+uAMLp5ISYGL57iijkMV1H109v61Mf/R8aMrID6keFmWszAjtqUnS1Gbp3 mWzEl6hsvCl4dK6UxEWll4lxUF3UGGozn57CeImT6UXTVUUQyOqMmqcNSbt2Fw1n3X5B gZMA== X-Gm-Message-State: AOAM5314uy+v3D3/TCbD8Kiqw321dWe9yMx2E7SAGASE1tx/TdJ1HGkK hzp/Z7dsKp/Xy1HvoX3KiExaw5GqyY8q64A3eF0c0V6Lh68jzzHsKxPQdBvzMYnPiBrIvgvKU5e 2qc13mPmOOx4uYYzdVcO0gKR/C05bYNffJCCmBwmpaE6xkEpQIYVdnllK0J60FqlLXE19tb8= X-Google-Smtp-Source: ABdhPJwOH07mJoJteeUQ0suIQkCRCiOyji8G3JViv+gFO6tvHxNdBn921v5S+O9/sSPCJoic80vLhn6xe/cBnQ== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:ad4:4f83:: with SMTP id em3mr8736152qvb.28.1611752361986; Wed, 27 Jan 2021 04:59:21 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:40 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-8-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 07/20] corpus: make get_(undefined_)?_(var|fun)_symbols use the new symtab To: libabigail@sourceware.org X-Spam-Status: No, score=-22.1 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" Make the corresponding members an implementation detail of corpus::priv. They get computed based on the new symtab whenever they are accessed first with an atomic instantiation. That simplifies the implementation and homogenizes the access to functions and variables. Sorting does not need to be done as the symtab already gives a guarantee for that. Due to improved alias detection in the new symtab reader, ensure we only write symbol aliases to ksymtab symbols if having a ksymtab main symbol. Test data needed to be adjusted as the new symtab reader is stricter in regards to symbols listed in ksymtab. I.e. init_module is not an exported symbol in the ksymtab of a kernel module. * src/abg-corpus-priv.h (corpus::priv::sorted_var_symbols): make private, mutable and optional. (corpus::sorted_undefined_var_symbols): Likewise. (corpus::sorted_fun_symbols): Likewise. (corpus::sorted_undefined_fun_symbols): Likewise. (corpus::priv::get_sorted_fun_symbols): New method declaration. (corpus::priv::get_sorted_undefined_fun_symbols): Likewise. (corpus::priv::get_sorted_var_symbols): Likewise. (corpus::priv::get_sorted_undefined_var_symbols): Likewise. * src/abg-corpus.cc (corpus::elf_symbol_comp_functor): Delete struct. (corpus::priv::get_sorted_fun_symbols): New method implementation. (corpus::priv::get_sorted_undefined_fun_symbols): Likewise. (corpus::priv::get_sorted_var_symbols): Likewise. (corpus::priv::get_sorted_undefined_var_symbols): Likewise. (corpus::get_sorted_fun_symbols): Proxy call to corpus::priv. (corpus::get_sorted_undefined_fun_symbols): Likewise. (corpus::get_sorted_var_symbols): Likewise. (corpus::get_sorted_undefined_var_symbols): Likewise. * src/abg-writer.cc (write_elf_symbol_aliases): When emitting aliases for a kernel symbol, ensure to only emit exported, public aliases. * tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: update test data. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- src/abg-corpus-priv.h | 21 +- src/abg-corpus.cc | 241 +++++++----------- src/abg-writer.cc | 39 ++- .../data/test-read-dwarf/PR25007-sdhci.ko.abi | 3 - 4 files changed, 135 insertions(+), 169 deletions(-) diff --git a/src/abg-corpus-priv.h b/src/abg-corpus-priv.h index 290e19c60e67..282796e1b685 100644 --- a/src/abg-corpus-priv.h +++ b/src/abg-corpus-priv.h @@ -683,13 +683,9 @@ struct corpus::priv vector vars; string_elf_symbols_map_sptr var_symbol_map; 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; - elf_symbols sorted_undefined_fun_symbols; elf_symbols unrefed_fun_symbols; elf_symbols unrefed_var_symbols; // The type maps contained in this data member are populated if the @@ -711,6 +707,11 @@ struct corpus::priv private: priv(); + mutable abg_compat::optional sorted_var_symbols; + mutable abg_compat::optional sorted_undefined_var_symbols; + mutable abg_compat::optional sorted_fun_symbols; + mutable abg_compat::optional sorted_undefined_fun_symbols; + public: priv(const string & p, environment* e) @@ -730,6 +731,18 @@ public: const type_maps& get_types() const; + const elf_symbols& + get_sorted_fun_symbols() const; + + const elf_symbols& + get_sorted_undefined_fun_symbols() const; + + const elf_symbols& + get_sorted_var_symbols() const; + + const elf_symbols& + get_sorted_undefined_var_symbols() const; + unordered_set* get_public_types_pretty_representations(); diff --git a/src/abg-corpus.cc b/src/abg-corpus.cc index 0d5849ddac5d..75f897eb72a8 100644 --- a/src/abg-corpus.cc +++ b/src/abg-corpus.cc @@ -438,6 +438,87 @@ const type_maps& corpus::priv::get_types() const {return types_;} +/// Return a sorted vector of function symbols for this corpus. +/// +/// Note that the first time this function is called, the symbols are +/// sorted and cached. Subsequent invocations of this function return +/// the cached vector that was built previously. +/// +/// @return the sorted list of function symbols. +const elf_symbols& +corpus::priv::get_sorted_fun_symbols() const +{ + if (!sorted_fun_symbols) + { + auto filter = symtab_->make_filter(); + filter.set_functions(); + sorted_fun_symbols = elf_symbols(symtab_->begin(filter), symtab_->end()); + } + return *sorted_fun_symbols; +} + +/// Getter for a sorted vector of the function symbols undefined in +/// this corpus. +/// +/// @return a vector of the function symbols undefined in this corpus, +/// sorted by name and then version. +const elf_symbols& +corpus::priv::get_sorted_undefined_fun_symbols() const +{ + if (!sorted_undefined_fun_symbols) + { + auto filter = symtab_->make_filter(); + filter.set_functions(); + filter.set_undefined_symbols(); + filter.set_public_symbols(false); + + sorted_undefined_fun_symbols = + elf_symbols(symtab_->begin(filter), symtab_->end()); + } + return *sorted_undefined_fun_symbols; +} + +/// Getter for the sorted vector of variable symbols for this corpus. +/// +/// Note that the first time this function is called, it computes the +/// sorted vector, caches the result and returns it. Subsequent +/// invocations of this function just return the cached vector. +/// +/// @return the sorted vector of variable symbols for this corpus. +const elf_symbols& +corpus::priv::get_sorted_var_symbols() const +{ + if (!sorted_var_symbols) + { + auto filter = symtab_->make_filter(); + filter.set_variables(); + + sorted_var_symbols = elf_symbols(symtab_->begin(filter), symtab_->end()); + } + return *sorted_var_symbols; +} + +/// Getter for a sorted vector of the variable symbols undefined in +/// this corpus. +/// +/// @return a vector of the variable symbols undefined in this corpus, +/// sorted by name and then version. +const elf_symbols& +corpus::priv::get_sorted_undefined_var_symbols() const +{ + if (!sorted_undefined_var_symbols) + { + auto filter = symtab_->make_filter(); + filter.set_variables(); + filter.set_undefined_symbols(); + filter.set_public_symbols(false); + + sorted_undefined_var_symbols = + elf_symbols(symtab_->begin(filter), symtab_->end()); + } + return *sorted_undefined_var_symbols; +} + /// Getter of the set of pretty representation of types that are /// reachable from public interfaces (global functions and variables). /// @@ -933,104 +1014,21 @@ const string_elf_symbols_map_type& corpus::get_undefined_fun_symbol_map() const {return *get_undefined_fun_symbol_map_sptr();} -/// Functor to sort instances of @ref elf_symbol. -struct elf_symbol_comp_functor -{ - - /// Return true if the first argument is less than the second one. - /// - /// @param l the first parameter to consider. - /// - /// @param r the second parameter to consider. - /// - /// @return true if @p l is less than @p r - bool - operator()(elf_symbol& l, elf_symbol& r) - {return (l.get_id_string() < r.get_id_string());} - - /// Return true if the first argument is less than the second one. - /// - /// @param l the first parameter to consider. - /// - /// @param r the second parameter to consider. - /// - /// @return true if @p l is less than @p r - bool - operator()(elf_symbol* l, elf_symbol* r) - {return operator()(*l, *r);} - - /// Return true if the first argument is less than the second one. - /// - /// @param l the first parameter to consider. - /// - /// @param r the second parameter to consider. - /// - /// @return true if @p l is less than @p r - bool - operator()(elf_symbol_sptr l, elf_symbol_sptr r) - {return operator()(*l, *r);} -}; // end struct elf_symbol_comp_functor - -/// Return a sorted vector of function symbols for this corpus. -/// -/// Note that the first time this function is called, the symbols are -/// sorted and cached. Subsequent invocations of this function return -/// the cached vector that was built previously. -/// -/// @return the sorted list of function symbols. const elf_symbols& corpus::get_sorted_fun_symbols() const -{ - if (priv_->sorted_fun_symbols.empty() - && !get_fun_symbol_map().empty()) - { - priv_->sorted_fun_symbols.reserve(get_fun_symbol_map().size()); - for (string_elf_symbols_map_type::const_iterator i = - get_fun_symbol_map().begin(); - i != get_fun_symbol_map().end(); - ++i) - for (elf_symbols::const_iterator s = i->second.begin(); - s != i->second.end(); - ++s) - priv_->sorted_fun_symbols.push_back(*s); +{ return priv_->get_sorted_fun_symbols(); } - elf_symbol_comp_functor comp; - std::sort(priv_->sorted_fun_symbols.begin(), - priv_->sorted_fun_symbols.end(), - comp); - } - return priv_->sorted_fun_symbols; -} - -/// Getter for a sorted vector of the function symbols undefined in -/// this corpus. -/// -/// @return a vector of the function symbols undefined in this corpus, -/// sorted by name and then version. const elf_symbols& corpus::get_sorted_undefined_fun_symbols() const -{ - if (priv_->sorted_undefined_fun_symbols.empty() - && !get_undefined_fun_symbol_map().empty()) - { - priv_->sorted_undefined_fun_symbols.reserve - (get_undefined_fun_symbol_map().size()); - for (string_elf_symbols_map_type::const_iterator i = - get_undefined_fun_symbol_map().begin(); - i != get_undefined_fun_symbol_map().end(); - ++i) - for (elf_symbols::const_iterator s = i->second.begin(); - s != i->second.end(); - ++s) - priv_->sorted_undefined_fun_symbols.push_back(*s); +{ return priv_->get_sorted_undefined_fun_symbols(); } - elf_symbol_comp_functor comp; - std::sort(priv_->sorted_undefined_fun_symbols.begin(), - priv_->sorted_undefined_fun_symbols.end(), - comp); - } - return priv_->sorted_undefined_fun_symbols; -} +const elf_symbols& +corpus::get_sorted_var_symbols() const +{ return priv_->get_sorted_var_symbols(); } + +const elf_symbols& +corpus::get_sorted_undefined_var_symbols() const +{ return priv_->get_sorted_undefined_var_symbols(); } /// Getter for the variable symbols map. /// @@ -1070,65 +1068,6 @@ const string_elf_symbols_map_type& corpus::get_undefined_var_symbol_map() const {return *get_undefined_var_symbol_map_sptr();} -/// Getter for the sorted vector of variable symbols for this corpus. -/// -/// Note that the first time this function is called, it computes the -/// sorted vector, caches the result and returns it. Subsequent -/// invocations of this function just return the cached vector. -/// -/// @return the sorted vector of variable symbols for this corpus. -const elf_symbols& -corpus::get_sorted_var_symbols() const -{ - if (priv_->sorted_var_symbols.empty() - && !get_var_symbol_map().empty()) - { - priv_->sorted_var_symbols.reserve(get_var_symbol_map().size()); - for (string_elf_symbols_map_type::const_iterator i = - get_var_symbol_map().begin(); - i != get_var_symbol_map().end(); - ++i) - for (elf_symbols::const_iterator s = i->second.begin(); - s != i->second.end(); ++s) - priv_->sorted_var_symbols.push_back(*s); - - elf_symbol_comp_functor comp; - std::sort(priv_->sorted_var_symbols.begin(), - priv_->sorted_var_symbols.end(), - comp); - } - return priv_->sorted_var_symbols; -} - -/// Getter for a sorted vector of the variable symbols undefined in -/// this corpus. -/// -/// @return a vector of the variable symbols undefined in this corpus, -/// sorted by name and then version. -const elf_symbols& -corpus::get_sorted_undefined_var_symbols() const -{ - if (priv_->sorted_undefined_var_symbols.empty() - && !get_undefined_var_symbol_map().empty()) - { - priv_->sorted_undefined_var_symbols.reserve - (get_undefined_var_symbol_map().size()); - for (string_elf_symbols_map_type::const_iterator i = - get_undefined_var_symbol_map().begin(); - i != get_undefined_var_symbol_map().end(); - ++i) - for (elf_symbols::const_iterator s = i->second.begin(); - s != i->second.end(); ++s) - priv_->sorted_undefined_var_symbols.push_back(*s); - - elf_symbol_comp_functor comp; - std::sort(priv_->sorted_undefined_var_symbols.begin(), - priv_->sorted_undefined_var_symbols.end(), - comp); - } - return priv_->sorted_undefined_var_symbols; -} - /// Look in the function symbols map for a symbol with a given name. /// /// @param n the name of the symbol to look for. diff --git a/src/abg-writer.cc b/src/abg-writer.cc index d55bbbc166d5..d4d5e5531894 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -1678,26 +1678,43 @@ write_elf_symbol_visibility(elf_symbol::visibility v, ostream& o) /// /// @return true upon successful completion. static bool -write_elf_symbol_aliases(const elf_symbol& sym, ostream& o) +write_elf_symbol_aliases(const elf_symbol& sym, ostream& out) { if (!sym.is_main_symbol() || !sym.has_aliases()) return false; - bool emitted = false; - o << " alias='"; - for (elf_symbol_sptr s = sym.get_next_alias(); - !s->is_main_symbol(); + + std::vector aliases; + for (elf_symbol_sptr s = sym.get_next_alias(); s && !s->is_main_symbol(); s = s->get_next_alias()) { - if (s->get_next_alias()->is_main_symbol()) - o << s->get_id_string() << "'"; - else - o << s->get_id_string() << ","; + if (!s->is_public()) + continue; + + if (s->is_suppressed()) + continue; + + if (sym.is_in_ksymtab() != s->is_in_ksymtab()) + continue; - emitted = true; + aliases.push_back(s->get_id_string()); } - return emitted; + if (!aliases.empty()) + { + out << " alias='"; + std::string separator; + for (const auto& alias : aliases) + { + out << separator << alias; + separator = ","; + } + + out << "'"; + return true; + } + + return false; } /// Write an XML attribute for the reference to a symbol for the diff --git a/tests/data/test-read-dwarf/PR25007-sdhci.ko.abi b/tests/data/test-read-dwarf/PR25007-sdhci.ko.abi index 44e2e608260b..1167e5aa478a 100644 --- a/tests/data/test-read-dwarf/PR25007-sdhci.ko.abi +++ b/tests/data/test-read-dwarf/PR25007-sdhci.ko.abi @@ -2,8 +2,6 @@ - - @@ -40,7 +38,6 @@ - From patchwork Wed Jan 27 12:58:41 2021 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: 41842 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 657A93972827; Wed, 27 Jan 2021 12:59:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 657A93972827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752368; bh=+ZIL8dWUEp5kHmdoNk0aU93X4+lYLVS0zLjYZyqKjNM=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=K2njGbElmmahQapZZS/UKH0jKceFD8ZQTqhNajC3PnF3bCE2Y4LzzABzoh/Y0IlhL XjjLkM2Wt33X5yTWe7WG2yqH2Z4PwfXwYuWxCgnjqpbSU1h9F8J8JEAkUjk/JYOWxq rvgcj4s7r9+HAB/LO2keZMjgxECYQwruhcog3zps= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by sourceware.org (Postfix) with ESMTPS id 24ABA3971830 for ; Wed, 27 Jan 2021 12:59:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 24ABA3971830 Received: by mail-wr1-x44a.google.com with SMTP id s18so918665wrf.0 for ; Wed, 27 Jan 2021 04:59:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+ZIL8dWUEp5kHmdoNk0aU93X4+lYLVS0zLjYZyqKjNM=; b=Tcr9G2d3n9r0rMgPdup7ZC2+Y+G/s+nrfjTKSAwjK2+3WawCltTcrSiTqRSodLsgzJ DFrbmmc/UlwNlUHtqryiL+urG2EEcmV3Tf5SgMrRwCxzTn4T6JRGbh3diRxNB+zZzW63 0bZa+gGgDTNyXMMxEqy+VeaExeT3sGw1HgJEuWq5N6287elUrAerBBpRHGd2kLn2bHnD NZk8qsXeqIB/f7eCRJXHZYlI9SD+BQiKrHtOlY8YHTwOFYHTwKLZ/YK95RGIu/mEHjCq O3AyRdI73pvaDVEnL4rQwKwERNh3ld8tvDojFazwtJfCCrODn62/MwVjgRtpRdLWvyym yhlQ== X-Gm-Message-State: AOAM533+nzsJBWLkUuzTnagWZ5AURKveMLJW9CpgcpHOewQCudy7Stdk NBQr2rHLHcU04w+Gxh0ghZ9HLe2swtSq1h2YrwD3uRT7u/DSLfEv/NVmz/Adkz3e1/qbf8cvAGp OulJfrxAGFYDZzwWzGfw+Ah3Cm7QUHDAJ+8U9BxJ1hOqdn2H2XMfrW18X4b4EYpJrcYRYD3Y= X-Google-Smtp-Source: ABdhPJxpxIPCJkvICdrkYCQER2yTpidNlB2zIDRJTpgdFjuzgKhUjB730GlePDETb5FjNBDO5c1Ml0tlN9Q2/A== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:a1c:bcd4:: with SMTP id m203mr4107455wmf.120.1611752364199; Wed, 27 Jan 2021 04:59:24 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:41 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-9-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 08/20] corpus: make get_unreferenced_(function|variable)_symbols use the new symtab To: libabigail@sourceware.org X-Spam-Status: No, score=-22.6 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" Make the corresponding members an implementation detail of corpus::priv. They get computed based on the new symtab whenever they are accessed first with an atomic instantiation. That simplifies the implementation and homogenizes the access to functions and variables. Sorting does not need to be done as the symtab already gives a guarantee for that. * src/abg-corpus-priv.h (corpus::priv::unrefed_var_symbols): make private, mutable and optional. (corpus::unrefed_fun_symbols): Likewise. (corpus::priv::get_unreferenced_function_symbols): New method declaration. (corpus::priv::get_unreferenced_variable_symbols): Likewise. * src/abg-corpus.cc (corpus::priv::build_unreferenced_symbols_tables): Delete method. (corpus::priv::get_unreferenced_function_symbols): New method implementation. (corpus::priv::get_unreferenced_variable_symbols): Likewise. (corpus::get_unreferenced_function_symbols): Proxy call to corpus::priv. (corpus::get_unreferenced_variable_symbols): Likewise. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- src/abg-corpus-priv.h | 13 ++- src/abg-corpus.cc | 246 +++++++++++++++++++----------------------- 2 files changed, 116 insertions(+), 143 deletions(-) diff --git a/src/abg-corpus-priv.h b/src/abg-corpus-priv.h index 282796e1b685..c8bf7f9d4cf6 100644 --- a/src/abg-corpus-priv.h +++ b/src/abg-corpus-priv.h @@ -686,8 +686,6 @@ struct corpus::priv symtab_reader::symtab_sptr symtab_; string_elf_symbols_map_sptr fun_symbol_map; string_elf_symbols_map_sptr undefined_fun_symbol_map; - elf_symbols unrefed_fun_symbols; - elf_symbols unrefed_var_symbols; // The type maps contained in this data member are populated if the // corpus follows the One Definition Rule and thus if there is only // one copy of a type with a given name, per corpus. Otherwise, if @@ -709,8 +707,10 @@ private: mutable abg_compat::optional sorted_var_symbols; mutable abg_compat::optional sorted_undefined_var_symbols; + mutable abg_compat::optional unrefed_var_symbols; mutable abg_compat::optional sorted_fun_symbols; mutable abg_compat::optional sorted_undefined_fun_symbols; + mutable abg_compat::optional unrefed_fun_symbols; public: priv(const string & p, @@ -722,9 +722,6 @@ public: pub_type_pretty_reprs_() {} - void - build_unreferenced_symbols_tables(); - type_maps& get_types(); @@ -737,12 +734,18 @@ public: const elf_symbols& get_sorted_undefined_fun_symbols() const; + const elf_symbols& + get_unreferenced_function_symbols() const; + const elf_symbols& get_sorted_var_symbols() const; const elf_symbols& get_sorted_undefined_var_symbols() const; + const elf_symbols& + get_unreferenced_variable_symbols() const; + unordered_set* get_public_types_pretty_representations(); diff --git a/src/abg-corpus.cc b/src/abg-corpus.cc index 75f897eb72a8..f9f51a360707 100644 --- a/src/abg-corpus.cc +++ b/src/abg-corpus.cc @@ -302,132 +302,6 @@ struct comp_elf_symbols_functor // - -/// Build the tables of symbols that are not referenced by any -/// function or variables of corpus::get_functions() or -/// corpus::get_variables(). -/// -/// Note that this function considers the list of function and -/// variable symbols to keep, that is provided by -/// corpus::get_sym_ids_of_fns_to_keep() and -/// corpus::get_sym_ids_of_vars_to_keep(). If a given unreferenced -/// function or variable symbol is not in the list of variable and -/// function symbols to keep, then that symbol is dropped and will not -/// be part of the resulting table of unreferenced symbol that is -/// built. -/// -/// The built tables are accessible from -/// corpus::get_unreferenced_function_symbols() and -/// corpus::get_unreferenced_variable_symbols(). -void -corpus::priv::build_unreferenced_symbols_tables() -{ - unordered_map refed_funs, refed_vars; - elf_symbol_sptr sym; - - for (vector::const_iterator f = fns.begin(); - f != fns.end(); - ++f) - if ((sym = (*f)->get_symbol())) - { - refed_funs[sym->get_id_string()] = true; - for (elf_symbol_sptr a = sym->get_next_alias(); - a && !a->is_main_symbol(); - a = a->get_next_alias()) - refed_funs[a->get_id_string()] = true; - } - - for (vector::const_iterator v = vars.begin(); - v != vars.end(); - ++v) - if ((sym = (*v)->get_symbol())) - { - refed_vars[sym->get_id_string()] = true; - for (elf_symbol_sptr a = sym->get_next_alias(); - a && !a->is_main_symbol(); - a = a->get_next_alias()) - refed_vars[a->get_id_string()] = true; - } - - if (fun_symbol_map) - { - // Let's assume that the size of the unreferenced symbols vector - // is roughly smaller than the size of the symbol table. - unrefed_fun_symbols.reserve(fun_symbol_map->size()); - for (string_elf_symbols_map_type::const_iterator i - = fun_symbol_map->begin(); - i != fun_symbol_map->end(); - ++i) - for (elf_symbols::const_iterator s = i->second.begin(); - s != i->second.end(); - ++s) - { - string sym_id = (*s)->get_id_string(); - if (refed_funs.find(sym_id) == refed_funs.end()) - { - bool keep = sym_id_fns_to_keep.empty(); - for (vector::const_iterator i = - sym_id_fns_to_keep.begin(); - i != sym_id_fns_to_keep.end(); - ++i) - { - if (*i == sym_id) - { - keep = true; - break; - } - } - if (keep) - unrefed_fun_symbols.push_back(*s); - } - } - - comp_elf_symbols_functor comp; - std::sort(unrefed_fun_symbols.begin(), - unrefed_fun_symbols.end(), - comp); - } - - if (var_symbol_map) - { - // Let's assume that the size of the unreferenced symbols vector - // is roughly smaller than the size of the symbol table. - unrefed_var_symbols.reserve(var_symbol_map->size()); - for (string_elf_symbols_map_type::const_iterator i - = var_symbol_map->begin(); - i != var_symbol_map->end(); - ++i) - for (elf_symbols::const_iterator s = i->second.begin(); - s != i->second.end(); - ++s) - { - string sym_id = (*s)->get_id_string(); - if (refed_vars.find(sym_id) == refed_vars.end()) - { - bool keep = sym_id_vars_to_keep.empty(); - for (vector::const_iterator i = - sym_id_vars_to_keep.begin(); - i != sym_id_vars_to_keep.end(); - ++i) - { - if (*i == sym_id) - { - keep = true; - break; - } - } - if (keep) - unrefed_var_symbols.push_back(*s); - } - } - - comp_elf_symbols_functor comp; - std::sort(unrefed_var_symbols.begin(), - unrefed_var_symbols.end(), - comp); - } -} - /// Get the maps that associate a name to a certain kind of type. type_maps& corpus::priv::get_types() @@ -478,6 +352,59 @@ corpus::priv::get_sorted_undefined_fun_symbols() const return *sorted_undefined_fun_symbols; } +/// Return a list of symbols that are not referenced by any function of +/// corpus::get_functions(). +/// +/// Note that this function considers the list of function symbols to keep, +/// that is provided by corpus::get_sym_ids_of_fns_to_keep(). If a given +/// unreferenced function symbol is not in the list of functions to keep, then +/// that symbol is dropped and will not be part of the resulting table of +/// unreferenced symbol that is built. +const elf_symbols& +corpus::priv::get_unreferenced_function_symbols() const +{ + if (!unrefed_fun_symbols) + { + unrefed_fun_symbols = elf_symbols(); + if (symtab_) + { + unordered_map refed_funs; + + for (const auto& function : fns) + if (elf_symbol_sptr sym = function->get_symbol()) + { + refed_funs[sym->get_id_string()] = true; + for (elf_symbol_sptr a = sym->get_next_alias(); + a && !a->is_main_symbol(); a = a->get_next_alias()) + refed_funs[a->get_id_string()] = true; + } + + auto filter = symtab_->make_filter(); + filter.set_functions(); + for (const auto& symbol : + symtab_reader::filtered_symtab(*symtab_, filter)) + { + const std::string sym_id = symbol->get_id_string(); + if (refed_funs.find(sym_id) == refed_funs.end()) + { + bool keep = sym_id_fns_to_keep.empty(); + for (const auto& id : sym_id_fns_to_keep) + { + if (id == sym_id) + { + keep = true; + break; + } + } + if (keep) + unrefed_fun_symbols->push_back(symbol); + } + } + } + } + return *unrefed_fun_symbols; +} + /// Getter for the sorted vector of variable symbols for this corpus. /// /// Note that the first time this function is called, it computes the @@ -519,6 +446,59 @@ corpus::priv::get_sorted_undefined_var_symbols() const return *sorted_undefined_var_symbols; } +/// Return a list of symbols that are not referenced by any variable of +/// corpus::get_variables(). +/// +/// Note that this function considers the list of variable symbols to keep, +/// that is provided by corpus::get_sym_ids_of_vars_to_keep(). If a given +/// unreferenced variable symbol is not in the list of variable to keep, then +/// that symbol is dropped and will not be part of the resulting table of +/// unreferenced symbol that is built. +const elf_symbols& +corpus::priv::get_unreferenced_variable_symbols() const +{ + if (!unrefed_var_symbols) + { + unrefed_var_symbols = elf_symbols(); + if (symtab_) + { + unordered_map refed_vars; + for (const auto& variable : vars) + if (elf_symbol_sptr sym = variable->get_symbol()) + { + refed_vars[sym->get_id_string()] = true; + for (elf_symbol_sptr a = sym->get_next_alias(); + a && !a->is_main_symbol(); a = a->get_next_alias()) + refed_vars[a->get_id_string()] = true; + } + + auto filter = symtab_->make_filter(); + filter.set_variables(); + for (const auto& symbol : + symtab_reader::filtered_symtab(*symtab_, filter)) + { + const std::string sym_id = symbol->get_id_string(); + if (refed_vars.find(sym_id) == refed_vars.end()) + { + bool keep = sym_id_vars_to_keep.empty(); + for (const auto& id : sym_id_vars_to_keep) + { + if (id == sym_id) + { + keep = true; + break; + } + } + if (keep) + unrefed_var_symbols->push_back(symbol); + } + } + } + } + return *unrefed_var_symbols; +} + + /// Getter of the set of pretty representation of types that are /// reachable from public interfaces (global functions and variables). /// @@ -1310,12 +1290,7 @@ corpus::sort_variables() /// function exported by the current corpus. const elf_symbols& corpus::get_unreferenced_function_symbols() const -{ - if (priv_->unrefed_fun_symbols.empty() - && priv_->unrefed_var_symbols.empty()) - priv_->build_unreferenced_symbols_tables(); - return priv_->unrefed_fun_symbols; -} +{ return priv_->get_unreferenced_function_symbols(); } /// Getter of the set of variable symbols that are not referenced by /// any variable exported by the current corpus. @@ -1328,12 +1303,7 @@ corpus::get_unreferenced_function_symbols() const /// variable exported by the current corpus. const elf_symbols& corpus::get_unreferenced_variable_symbols() const -{ - if (priv_->unrefed_fun_symbols.empty() - && priv_->unrefed_var_symbols.empty()) - priv_->build_unreferenced_symbols_tables(); - return priv_->unrefed_var_symbols; -} +{ return priv_->get_unreferenced_variable_symbols(); } /// Accessor for the regex patterns describing the functions to drop /// from the public decl table. From patchwork Wed Jan 27 12:58:42 2021 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: 41843 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 AD190397282F; Wed, 27 Jan 2021 12:59:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD190397282F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752369; bh=QqwzaSsGg5Abvk8XxC0XCm1qTnuYw619eIX6QL8dsLU=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=BTBs/Rje0pDW4JXdDFZZi2nT0YGkSteV50NeGB2jbj5dL7MtJCB5J+rO4Pge5+F/C exy9W+8/bCN5MGjnLFh678U11YttqliJPbS9KBSj+owQIEw+iFiLfOMsZUe0Y/F1wM 4aJBR3GfOs1tb/DkSDhncqQiArh99cqwozt4tPdQ= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-ej1-x649.google.com (mail-ej1-x649.google.com [IPv6:2a00:1450:4864:20::649]) by sourceware.org (Postfix) with ESMTPS id 8AA773971C3C for ; Wed, 27 Jan 2021 12:59:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8AA773971C3C Received: by mail-ej1-x649.google.com with SMTP id j14so607499eja.15 for ; Wed, 27 Jan 2021 04:59:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=QqwzaSsGg5Abvk8XxC0XCm1qTnuYw619eIX6QL8dsLU=; b=mHai7/innNgIBGfIeaus25LCk2Zg5VFzmHopR0N6taoFEHnknzwdi+TI77demgb9uV ojQO+zx9Rxt6z55tClxlphJCb0A5/q30/GBwlDiTBQYBb3s8X56dU7QpZptuVqDrQWo7 AttkyddLgmJFbVYhjq+ZrzL9y4bFiMuKUL8vNlAaDRIsBi8d7qddhkh2rfOaki8rRixG V8bjRemrbyW/z2DYEYQVYeahKXh+zTg/unLHaBdFwFWTQqOCQK0/R0tcY+CziMDaE+6z F3xu+ataUp8pKlJ9HJa3Rv7rGEBeFIV/qU/O+1u9/rRvt9LCI57bWlAZA3ziKg731mMp H3Yw== X-Gm-Message-State: AOAM532d14A5IyOZcLVkbLQ7mUlh5yvcY430f6FkxUGxEDXqw0UmV/T2 MgOo0TUz76cK5/dd6KpNUValPiIAfslEhiKWZmvk1SNPgcwADBdfTX/kC/HlS61THHBms1yydmJ HrLRSk1Omx0liLLOic4Xgc3Dr3CXyDB41ZeVuIu0qXpjYJknEYS86eNViJxKzR8t7usvS5dk= X-Google-Smtp-Source: ABdhPJyNGVPUbB2ZExjGcjSfttk/rmUfCIr477MZPNCDP5sNLXcEldVBmsfleHpe702gN99ynhyYchC/O5t7Yw== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:aa7:c94a:: with SMTP id h10mr6824937edt.41.1611752366458; Wed, 27 Jan 2021 04:59:26 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:42 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-10-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 09/20] abg-reader: avoid using the (var|function)_symbol_map To: libabigail@sourceware.org X-Spam-Status: No, score=-21.7 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" Instead of using the corpus var|function_symbol_maps for symbol lookups, let build_elf_symbol_from_reference use the symtab::lookup_symbol method. That leads to a shorter implementation and we can drop the indicative parameter. * src/abg-reader.cc (build_elf_symbol_from_reference): drop last parameter indicating the lookup type and use corpus symtab for the lookup (build_function_decl): Adjust accordingly. (build_var_decl): Likewise. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- src/abg-reader.cc | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/abg-reader.cc b/src/abg-reader.cc index 68b19cf4b65b..c26689ae17ca 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -1084,8 +1084,7 @@ static elf_symbol_sptr build_elf_symbol(read_context&, const xmlNodePtr, bool); static elf_symbol_sptr -build_elf_symbol_from_reference(read_context&, const xmlNodePtr, - bool); +build_elf_symbol_from_reference(read_context&, const xmlNodePtr); static string_elf_symbols_map_sptr build_elf_symbol_db(read_context&, const xmlNodePtr, bool); @@ -2818,8 +2817,7 @@ build_elf_symbol(read_context& ctxt, const xmlNodePtr node, /// /// @return a shared pointer the resutling elf_symbol. static elf_symbol_sptr -build_elf_symbol_from_reference(read_context& ctxt, const xmlNodePtr node, - bool function_symbol) +build_elf_symbol_from_reference(read_context& ctxt, const xmlNodePtr node) { elf_symbol_sptr nil; @@ -2838,20 +2836,12 @@ build_elf_symbol_from_reference(read_context& ctxt, const xmlNodePtr node, if (name.empty()) return nil; - string_elf_symbols_map_sptr sym_db = - (function_symbol) - ? ctxt.get_corpus()->get_fun_symbol_map_sptr() - : ctxt.get_corpus()->get_var_symbol_map_sptr(); + const elf_symbols& symbols = + ctxt.get_corpus()->get_symtab()->lookup_symbol(name); - string_elf_symbols_map_type::const_iterator i = sym_db->find(name); - if (i != sym_db->end()) - { - for (elf_symbols::const_iterator s = i->second.begin(); - s != i->second.end(); - ++s) - if ((*s)->get_id_string() == sym_id) - return *s; - } + for (const auto& symbol : symbols) + if (symbol->get_id_string() == sym_id) + return symbol; } return nil; @@ -3102,8 +3092,7 @@ build_function_decl(read_context& ctxt, ctxt.push_decl_to_current_scope(fn_decl, add_to_current_scope); - elf_symbol_sptr sym = build_elf_symbol_from_reference(ctxt, node, - /*function_sym=*/true); + elf_symbol_sptr sym = build_elf_symbol_from_reference(ctxt, node); if (sym) fn_decl->set_symbol(sym); @@ -3334,8 +3323,7 @@ build_var_decl(read_context& ctxt, locus, mangled_name, vis, bind)); - elf_symbol_sptr sym = build_elf_symbol_from_reference(ctxt, node, - /*function_sym=*/false); + elf_symbol_sptr sym = build_elf_symbol_from_reference(ctxt, node); if (sym) decl->set_symbol(sym); From patchwork Wed Jan 27 12:58:43 2021 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: 41844 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 F1B7C397282F; Wed, 27 Jan 2021 12:59:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1B7C397282F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752372; bh=4xlQWq6ZiNMl4TodJWi/BpVITdNy2BcIlaHLKO+6T6A=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=CvfUyZFMh+bep0ae/4Q27pzKidtUJjm1RjYqjGNfpbmCYfi+jLV4PVfzbIKbJeDnJ ryi+NrjC1XGy4zTKSpT3NbWeqrj0qACmqevbMydM6XQwrtAufdz3l8zT8WFNSjq9PS bUcvJFPpDCsthCpl5MypjVoXB2hiaj0E0w/i9A9E= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by sourceware.org (Postfix) with ESMTPS id A86EF3972827 for ; Wed, 27 Jan 2021 12:59:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A86EF3972827 Received: by mail-wm1-x34a.google.com with SMTP id l21so816585wmj.1 for ; Wed, 27 Jan 2021 04:59:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=4xlQWq6ZiNMl4TodJWi/BpVITdNy2BcIlaHLKO+6T6A=; b=jm8T4Ozq2IltCVJu1fUIuZyPQstM5Rhp5fVMSWtBe1XGX+gzlsS1E2MFzx3g8LiJ89 /BvBXqFfxK+CJzx/2ptzr1r/s7Za2hPMojo41BbQrgFo/cAkYAz0r8An0kvs0oq6c6/i MWYsTDV+qwzkSLnjYNxmy5gdUODKUvw0Kno0EQRlU48Me9w/2rg0CwcC9dUnHMX7s33G UAN6avv6OeCjj96MwsqzOJOi9f7Q00QFDR03kuol43o4t3dn2k79J1IL0I1DFSWgVVmP w22+MwRHTsT2PXx3ZXWuSFwV1lcylgs62hoWHI/yXUeKkviw1RxAZYFnzbAs4w8fJZFu 3jmQ== X-Gm-Message-State: AOAM532FONrbTiDoOa1MsOyLM8cm8v9dS+fylsmh2pBItH/5m/rL6rul dA5wMrhjkEYhI77I0bNlg+7wiQ9hGApHon1zYwY4q++DjZ0t1nV+Ch4oQSjuOocsVivdPuJh75h McfVvllvl5W8NT3NjDPcUXaTr5+Q0xCv2MNjvMPIygoJD05+cyNDE8OVhECnfI9GyGqTwqSw= X-Google-Smtp-Source: ABdhPJxMuslW/0iTq0fG5VUz2oWp2wbHLTkEGAysUl+6rqivBXNfmzhonACMFAzqrEEDIeuYUPcOV3jSMtYllg== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:a7b:c7c8:: with SMTP id z8mr4111851wmk.72.1611752368747; Wed, 27 Jan 2021 04:59:28 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:43 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-11-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 10/20] dwarf-reader: read_context: use new symtab in *_symbols_is_exported To: libabigail@sourceware.org X-Spam-Status: No, score=-23.4 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" Testing whether a symbol is exported can be simplified using the new symtab implementation. The same holds true for whether a symbol is exported via ksymtab in case of linux kernel binaries. So, do that. * src/abg-dwarf-reader.cc (function_symbol_is_exported): Use new symtab implementation. (variable_symbol_is_exported): Likewise. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- src/abg-dwarf-reader.cc | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 9f533e64959c..3a93fe0df5d0 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -5807,11 +5807,11 @@ public: elf_symbol_sptr function_symbol_is_exported(GElf_Addr symbol_address) const { - elf_symbol_sptr symbol = lookup_elf_fn_symbol_from_address(symbol_address); + elf_symbol_sptr symbol = symtab()->lookup_symbol(symbol_address); if (!symbol) return symbol; - if (!symbol->is_public()) + if (!symbol->is_function() || !symbol->is_public()) return elf_symbol_sptr(); address_set_sptr set; @@ -5820,16 +5820,8 @@ public: if (looking_at_linux_kernel_binary) { - if ((set = linux_exported_fn_syms())) - { - if (set->find(symbol_address) != set->end()) - return symbol; - } - if ((set = linux_exported_gpl_fn_syms())) - { - if (set->find(symbol_address) != set->end()) - return symbol; - } + if (symbol->is_in_ksymtab()) + return symbol; return elf_symbol_sptr(); } @@ -5847,11 +5839,11 @@ public: elf_symbol_sptr variable_symbol_is_exported(GElf_Addr symbol_address) const { - elf_symbol_sptr symbol = lookup_elf_var_symbol_from_address(symbol_address); + elf_symbol_sptr symbol = symtab()->lookup_symbol(symbol_address); if (!symbol) return symbol; - if (!symbol->is_public()) + if (!symbol->is_variable() || !symbol->is_public()) return elf_symbol_sptr(); address_set_sptr set; @@ -5860,16 +5852,8 @@ public: if (looking_at_linux_kernel_binary) { - if ((set = linux_exported_var_syms())) - { - if (set->find(symbol_address) != set->end()) - return symbol; - } - if ((set = linux_exported_gpl_var_syms())) - { - if (set->find(symbol_address) != set->end()) - return symbol; - } + if (symbol->is_in_ksymtab()) + return symbol; return elf_symbol_sptr(); } From patchwork Wed Jan 27 12:58:44 2021 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: 41845 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 456F3397282F; Wed, 27 Jan 2021 12:59:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 456F3397282F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752377; bh=AW6PqywtYXcdy82W/FCIAWl0A9/kJfJdysVmE5rtrzI=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=CK3gmgC5ns/FkA1hU3Nyz+zRH5DJh/NNwPcI+y72EUyKGRgCVn519a7MAazMD6YIV nwngwZjChdWayq6nTbqWEj4JDBkGDOLV3mvr+w+bYJLJom+qHl15LdTFCrdFQYRhXb x2LpGm+0vaVwjnMBaJvjFidnqjaVEQ7Uk+QSuIJI= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by sourceware.org (Postfix) with ESMTPS id 68B523971C3C for ; Wed, 27 Jan 2021 12:59:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 68B523971C3C Received: by mail-qv1-xf49.google.com with SMTP id z8so1216635qva.23 for ; Wed, 27 Jan 2021 04:59:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=AW6PqywtYXcdy82W/FCIAWl0A9/kJfJdysVmE5rtrzI=; b=LF8RmI3snhQDNEF3YcXCwqHhXwKYUfLS2dKU4DzjmhodImww0TCEPgDqaLVaG/oqbR /i6kQVgJL93O6Is1936WvmXNN/f0zo3JhccR0b1vl+4yr1vztBjM/GtaXx5gRP7VSPaM nkfseUXKWG1v9CiPVn+UK5zwqe52tmDe64Y0OzwW1fMFmQx2l9IfW/09NQIIrviR7wG8 g+a+IaB5NEBbXbNXM9ODzzuqp6UUZ7RTjcgW0O0qP0vOWeM9adpRFd3D929HfnqDWJYf GaRcixJRyBKuitvwwRBgTNowXUwb0NGEv4A6H6rPcgenZbyjRTX0dPPI1ZkAEcY4qFI5 dGWg== X-Gm-Message-State: AOAM533mIEUCIXrvMJ3peeGFLOlzYx8BnjxSz+krUY6KsmSCgYTY3STz DJMKsI90rR03q2SZsUvP/mMmvHDlEZkTo6IvMu8CYlOI9qgUEcBOPxilqnUmvmz9Yrx5lhhVh8r XCHPljsnxC+MqVUKZzPOfyXk01tecKM+0oJADIz79DvmUG2MxAhE+jQEIxVoVHWM446sax/Y= X-Google-Smtp-Source: ABdhPJy9quT8q8xZLTVXzSvEpdO+dVBS3vb7l5SQP7R1aHaa/f1Mj5LOR3QvMZZPqAIuL8YBYOysW7uYqZwIlg== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:a0c:b414:: with SMTP id u20mr10343223qve.57.1611752370941; Wed, 27 Jan 2021 04:59:30 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:44 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-12-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 11/20] Switch kernel stuff over to new symtab and drop unused code To: libabigail@sourceware.org X-Spam-Status: No, score=-21.6 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, 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" Now that the new symtab implementation is capable of reading the ksymtab, we can switch over the implementation to gather information from there and delete all now-obsolete code. * src/abg-dwarf-reader.cc (read_context::ksymtab_format_): Delete. (read_context::ksymtab_entry_size_): Likewise. (read_context::nb_ksymtab_entries_): Likewise. (read_context::nb_ksymtab_gpl_entries_): Likewise. (read_context::ksymtab_section_): Likewise. (read_context::ksymtab_reloc_section_): Likewise. (read_context::ksymtab_gpl_section_): Likewise. (read_context::ksymtab_gpl_reloc_section_): Likewise. (read_context::ksymtab_strings_section_): Likewise. (read_context::linux_exported_fn_syms): Likewise. (read_context::linux_exported_var_syms): Likewise. (read_context::linux_exported_gpl_fn_syms): Likewise. (read_context::linux_exported_gpl_var_syms): Likewise. (read_context::initialize): Remove initializations accordingly. (read_context::find_ksymtab_section): Delete. (read_context::find_ksymtab_gpl_section): Likewise. (read_context::find_ksymtab_reloc_section): Likewise. (read_context::find_ksymtab_gpl_reloc_section): Likewise. (read_context::find_ksymtab_strings_section): Likewise. (read_context::find_any_ksymtab_section): Likewise. (read_context::find_any_ksymtab_reloc_section): Likewise. (read_context::lookup_elf_symbol_from_index): Adjust. (read_context::linux_exported_fn_syms): Delete. (read_context::create_or_get_linux_exported_fn_syms): Likewise. (read_context::linux_exported_var_syms): Likewise. (read_context::create_or_get_linux_exported_var_syms): Likewise. (read_context::linux_exported_gpl_fn_syms): Delete. (read_context::create_or_get_linux_exported_gpl_fn_syms): Likewise. (read_context::linux_exported_gpl_var_syms): Likewise. (read_context::create_or_get_linux_exported_gpl_var_syms): Likewise. (read_context::try_reading_first_ksymtab_entry): Likewise. (read_context::try_reading_first_ksymtab_entry_using_pre_v4_19_format): Likewise. (read_context::try_reading_first_ksymtab_entry_using_v4_19_format): Likewise. (read_context::get_ksymtab_format_module): Likewise. (read_context::get_ksymtab_format): Likewise. (read_context::get_ksymtab_symbol_value_size): Likewise. (read_context::get_ksymtab_entry_size): Likewise. (read_context::get_nb_ksymtab_entries): Likewise. (read_context::get_nb_ksymtab_gpl_entries): Likewise. (read_context::populate_symbol_map_from_ksymtab): Likewise. (read_context::populate_symbol_map_from_ksymtab_reloc): Likewise. (read_context::load_kernel_symbol_table): Likewise. (read_context::load_ksymtab_symbols): Likewise. (read_context::load_ksymtab_gpl_symbols): Likewise. (read_context::load_linux_specific_exported_symbol_maps): Likewise. (read_context::load_symbol_maps): Do not load kernel symbol maps. (read_context::maybe_adjust_sym_address_from_v4_19_ksymtab): Delete. (read_context::add_fn_symbols_to_map): Likewise. (read_context::add_var_symbols_to_map): Likewise. (read_context::read_debug_info_into_corpus): Fill export maps from new symtab. (read_context::lookup_elf_fn_symbol_from_address): Delete. (read_context::lookup_elf_var_symbol_from_address): Likewise. (read_context::lookup_elf_symbol_from_address): Likewise. (read_context::lookup_public_function_symbol_from_elf): Likewise. (read_context::fun_entry_addr_sym_map_sptr): Likewise. (read_context::fun_entry_addr_sym_map): Likewise. (read_context::var_addr_sym_map): Likewise. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- src/abg-dwarf-reader.cc | 1191 +-------------------------------------- 1 file changed, 19 insertions(+), 1172 deletions(-) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 3a93fe0df5d0..693fae82040e 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -2145,26 +2145,6 @@ public: // ppc64 elf v1 binaries. This section contains the procedure // descriptors on that platform. mutable Elf_Scn* opd_section_; - /// The format of the special __ksymtab section from the linux - /// kernel binary. - mutable ksymtab_format ksymtab_format_; - /// The size of one entry of the __ksymtab section. - mutable size_t ksymtab_entry_size_; - /// The number of entries in the __ksymtab section. - mutable size_t nb_ksymtab_entries_; - /// The number of entries in the __ksymtab_gpl section. - mutable size_t nb_ksymtab_gpl_entries_; - /// The special __ksymtab and __ksymtab_gpl sections from linux - /// kernel or module binaries. The former is used to store - /// references to symbols exported using the EXPORT_SYMBOL macro - /// from the linux kernel. The latter is used to store references - /// to symbols exported using the EXPORT_SYMBOL_GPL macro from the - /// linux kernel. - mutable Elf_Scn* ksymtab_section_; - mutable Elf_Scn* ksymtab_reloc_section_; - mutable Elf_Scn* ksymtab_gpl_section_; - mutable Elf_Scn* ksymtab_gpl_reloc_section_; - mutable Elf_Scn* ksymtab_strings_section_; Dwarf_Die* cur_tu_die_; mutable dwarf_expr_eval_context dwarf_expr_eval_context_; // A set of maps (one per kind of die source) that associates a decl @@ -2248,10 +2228,6 @@ public: string_elf_symbols_map_sptr var_syms_; string_elf_symbols_map_sptr undefined_fun_syms_; string_elf_symbols_map_sptr undefined_var_syms_; - address_set_sptr linux_exported_fn_syms_; - address_set_sptr linux_exported_var_syms_; - address_set_sptr linux_exported_gpl_fn_syms_; - address_set_sptr linux_exported_gpl_var_syms_; vector dt_needed_; string dt_soname_; string elf_architecture_; @@ -2350,15 +2326,6 @@ public: elf_path_ = elf_path; symtab_section_ = 0; opd_section_ = 0; - ksymtab_format_ = UNDEFINED_KSYMTAB_FORMAT; - ksymtab_entry_size_ = 0; - nb_ksymtab_entries_ = 0; - nb_ksymtab_gpl_entries_ = 0; - ksymtab_section_ = 0; - ksymtab_reloc_section_ = 0; - ksymtab_gpl_section_ = 0; - ksymtab_gpl_reloc_section_ = 0; - ksymtab_strings_section_ = 0; cur_tu_die_ = 0; exported_decls_builder_ = 0; @@ -2404,10 +2371,6 @@ public: var_syms_.reset(); undefined_fun_syms_.reset(); undefined_var_syms_.reset(); - linux_exported_fn_syms_.reset(); - linux_exported_var_syms_.reset(); - linux_exported_gpl_fn_syms_.reset(); - linux_exported_gpl_var_syms_.reset(); dt_needed_.clear(); dt_soname_.clear(); elf_architecture_.clear(); @@ -5362,97 +5325,6 @@ public: return opd_section_; } - /// Return the __ksymtab section of a linux kernel ELF file (either - /// a vmlinux binary or a kernel module). - /// - /// @return the __ksymtab section if found, nil otherwise. - Elf_Scn* - find_ksymtab_section() const - { - if (!ksymtab_section_) - ksymtab_section_ = elf_helpers::find_ksymtab_section(elf_handle()); - return ksymtab_section_; - } - - /// Return the __ksymtab_gpl section of a linux kernel ELF file - /// (either a vmlinux binary or a kernel module). - /// - /// @return the __ksymtab_gpl section if found, nil otherwise. - Elf_Scn* - find_ksymtab_gpl_section() const - { - if (!ksymtab_gpl_section_) - ksymtab_gpl_section_ = - elf_helpers::find_ksymtab_gpl_section(elf_handle()); - return ksymtab_gpl_section_; - } - - /// Return the .rel{a,}__ksymtab section of a linux kernel ELF file (either - /// a vmlinux binary or a kernel module). - /// - /// @return the .rel{a,}__ksymtab section if found, nil otherwise. - Elf_Scn* - find_ksymtab_reloc_section() const - { - if (!ksymtab_reloc_section_) - ksymtab_reloc_section_ = - find_relocation_section(elf_handle(), find_ksymtab_section()); - return ksymtab_reloc_section_; - } - - /// Return the .rel{a,}__ksymtab_gpl section of a linux kernel ELF file - /// (either a vmlinux binary or a kernel module). - /// - /// @return the .rel{a,}__ksymtab_gpl section if found, nil otherwise. - Elf_Scn* - find_ksymtab_gpl_reloc_section() const - { - if (!ksymtab_gpl_reloc_section_) - ksymtab_gpl_reloc_section_ = - find_relocation_section(elf_handle(), find_ksymtab_gpl_section()); - return ksymtab_gpl_reloc_section_; - } - - /// Return the __ksymtab_strings section of a linux kernel ELF file - /// (either a vmlinux binary or a kernel module). - /// - /// @return the __ksymtab_strings section if found, nil otherwise. - Elf_Scn* - find_ksymtab_strings_section() const - { - if (!ksymtab_strings_section_) - ksymtab_strings_section_ = - dwarf_reader::find_ksymtab_strings_section(elf_handle()); - return ksymtab_strings_section_; - } - - /// Return either a __ksymtab or a __ksymtab_gpl section, in case - /// only the __ksymtab_gpl exists. - /// - /// @return the __ksymtab section if it exists, or the - /// __ksymtab_gpl; or NULL if neither is found. - Elf_Scn* - find_any_ksymtab_section() const - { - Elf_Scn *result = find_ksymtab_section(); - if (!result) - result = find_ksymtab_gpl_section(); - return result; - } - - /// Return either a .rel{a,}__ksymtab or a .rel{a,}__ksymtab_gpl section - /// - /// @return the .rel{a,}__ksymtab section if it exists, or the - /// .rel{a,}__ksymtab_gpl; or NULL if neither is found. - Elf_Scn* - find_any_ksymtab_reloc_section() const - { - Elf_Scn *result = find_ksymtab_reloc_section(); - if (!result) - result = find_ksymtab_gpl_reloc_section(); - return result; - } - /// Lookup an elf symbol, referred to by its index, from the .symtab /// section. /// @@ -5548,7 +5420,7 @@ public: elf_symbol::visibility vis = stv_to_elf_symbol_visibility(GELF_ST_VISIBILITY(native_sym.st_other)); - Elf_Scn *strings_section = find_ksymtab_strings_section(); + Elf_Scn* strings_section = find_ksymtab_strings_section(elf_handle()); size_t strings_ndx = strings_section ? elf_ndxscn(strings_section) : 0; @@ -5710,92 +5582,6 @@ public: return result; } - /// Given the address of the beginning of a function, lookup the - /// symbol of the function, build an instance of @ref elf_symbol out - /// of it and return it. - /// - /// @param symbol_start_addr the address of the beginning of the - /// function to consider. - /// - /// @param sym the resulting symbol. This is set iff the function - /// returns true. - /// - /// @return the elf symbol found at address @p symbol_start_addr, or - /// nil if none was found. - elf_symbol_sptr - lookup_elf_fn_symbol_from_address(GElf_Addr symbol_start_addr) const - { - addr_elf_symbol_sptr_map_type::const_iterator i, - nil = fun_entry_addr_sym_map().end(); - - if ((i = fun_entry_addr_sym_map().find(symbol_start_addr)) == nil) - return elf_symbol_sptr(); - - return i->second; - } - - /// Given the address of a global variable, lookup the symbol of the - /// variable, build an instance of @ref elf_symbol out of it and - /// return it. - /// - /// @param symbol_start_addr the address of the beginning of the - /// variable to consider. - /// - /// @param the symbol found, iff the function returns true. - /// - /// @return the elf symbol found or nil if none was found. - elf_symbol_sptr - lookup_elf_var_symbol_from_address(GElf_Addr symbol_start_addr) const - { - addr_elf_symbol_sptr_map_type::const_iterator i, - nil = var_addr_sym_map().end(); - - if ((i = var_addr_sym_map().find(symbol_start_addr)) == nil) - return elf_symbol_sptr(); - - return i->second; - } - - /// Lookup an elf symbol, knowing its address. - /// - /// This function first looks for a function symbol having this - /// address; if it doesn't find any, then it looks for a variable - /// symbol. - /// - /// @param symbol_addr the address of the symbol of the symbol we - /// are looking for. Note that the address is a relative offset - /// starting from the beginning of the .text section. Addresses - /// that are presen in the symbol table (the one named .symtab). - /// - /// @return the elf symbol if found, or nil otherwise. - elf_symbol_sptr - lookup_elf_symbol_from_address(GElf_Addr symbol_addr) const - { - elf_symbol_sptr result = lookup_elf_fn_symbol_from_address(symbol_addr); - if (!result) - result = lookup_elf_var_symbol_from_address(symbol_addr); - return result; - } - - /// Look in the symbol tables of the underying elf file and see if - /// we find a symbol of a given name of function type. - /// - /// @param sym_name the name of the symbol to look for. - /// - /// @param syms the public function symbols that were found, with - /// the name @p sym_name. - /// - /// @return true iff the symbol was found. - bool - lookup_public_function_symbol_from_elf(const string& sym_name, - vector& syms) - { - return dwarf_reader::lookup_public_function_symbol_from_elf(env(), - elf_handle(), - sym_name, - syms); - } - /// Test if a given function symbol has been exported. /// /// @param symbol_address the address of the symbol we are looking @@ -5894,20 +5680,6 @@ public: return fun_addr_sym_map_; } - /// Getter for a pointer to the map that associates the address of - /// an entry point of a function with the symbol of that function. - /// - /// Note that on non-"PPC64 ELFv1" binaries, this map is the same as - /// the one that assciates the address of a function with the symbol - /// of that function. - /// - /// @return a pointer to the map that associates the address of an - /// entry point of a function with the symbol of that function. - const addr_elf_symbol_sptr_map_sptr& - fun_entry_addr_sym_map_sptr() const - {return const_cast(this)->fun_entry_addr_sym_map_sptr();} - - /// Getter for the map that associates the address of an entry point /// of a function with the symbol of that function. /// @@ -5921,19 +5693,6 @@ public: fun_entry_addr_sym_map() {return *fun_entry_addr_sym_map_sptr();} - /// Getter for the map that associates the address of an entry point - /// of a function with the symbol of that function. - /// - /// Note that on non-"PPC64 ELFv1" binaries, this map is the same as - /// the one that assciates the address of a function with the symbol - /// of that function. - /// - /// @return the map that associates the address of an entry point of - /// a function with the symbol of that function. - const addr_elf_symbol_sptr_map_type& - fun_entry_addr_sym_map() const - { return *fun_entry_addr_sym_map_sptr();} - /// Getter for the map of function symbols (name -> sym). /// /// @return a shared pointer to the map of function symbols. @@ -5998,130 +5757,6 @@ public: return undefined_var_syms_; } - /// Getter for the set of addresses of function symbols that are - /// explicitely exported, for a linux kernel (module) binary. These - /// are the addresses of function symbols present in the __ksymtab - /// section - address_set_sptr& - linux_exported_fn_syms() - {return linux_exported_fn_syms_;} - - /// Getter for the set of addresses of functions that are - /// explicitely exported, for a linux kernel (module) binary. These - /// are the addresses of function symbols present in the __ksymtab - /// section. - /// - /// @return the set of addresses of exported function symbols. - const address_set_sptr& - linux_exported_fn_syms() const - {return const_cast(this)->linux_exported_fn_syms();} - - /// Create an empty set of addresses of functions exported from a - /// linux kernel (module) binary, or return the one that already - /// exists. - /// - /// @return the set of addresses of exported function symbols. - address_set_sptr& - create_or_get_linux_exported_fn_syms() - { - if (!linux_exported_fn_syms_) - linux_exported_fn_syms_.reset(new address_set_type); - return linux_exported_fn_syms_; - } - - /// Getter for the set of addresses of v ariables that are - /// explicitely exported, for a linux kernel (module) binary. These - /// are the addresses of variable symbols present in the __ksymtab - /// section. - /// - /// @return the set of addresses of exported variable symbols. - address_set_sptr& - linux_exported_var_syms() - {return linux_exported_var_syms_;} - - /// Getter for the set of addresses of variables that are - /// explicitely exported, for a linux kernel (module) binary. These - /// are the addresses of variable symbols present in the __ksymtab - /// section. - /// - /// @return the set of addresses of exported variable symbols. - const address_set_sptr& - linux_exported_var_syms() const - {return const_cast(this)->linux_exported_var_syms();} - - - /// Create an empty set of addresses of variables exported from a - /// linux kernel (module) binary, or return the one that already - /// exists. - /// - /// @return the set of addresses of exported variable symbols. - address_set_sptr& - create_or_get_linux_exported_var_syms() - { - if (!linux_exported_var_syms_) - linux_exported_var_syms_.reset(new address_set_type); - return linux_exported_var_syms_; - } - - - /// Getter for the set of addresses of function symbols that are - /// explicitely exported as GPL, for a linux kernel (module) binary. - /// These are the addresses of function symbols present in the - /// __ksymtab_gpl section. - address_set_sptr& - linux_exported_gpl_fn_syms() - {return linux_exported_gpl_fn_syms_;} - - /// Getter for the set of addresses of function symbols that are - /// explicitely exported as GPL, for a linux kernel (module) binary. - /// These are the addresses of function symbols present in the - /// __ksymtab_gpl section. - const address_set_sptr& - linux_exported_gpl_fn_syms() const - {return const_cast(this)->linux_exported_gpl_fn_syms();} - - /// Create an empty set of addresses of GPL functions exported from - /// a linux kernel (module) binary, or return the one that already - /// exists. - /// - /// @return the set of addresses of exported function symbols. - address_set_sptr& - create_or_get_linux_exported_gpl_fn_syms() - { - if (!linux_exported_gpl_fn_syms_) - linux_exported_gpl_fn_syms_.reset(new address_set_type); - return linux_exported_gpl_fn_syms_; - } - - /// Getter for the set of addresses of variable symbols that are - /// explicitely exported as GPL, for a linux kernel (module) binary. - /// These are the addresses of variable symbols present in the - /// __ksymtab_gpl section. - address_set_sptr& - linux_exported_gpl_var_syms() - {return linux_exported_gpl_var_syms_;} - - /// Getter for the set of addresses of variable symbols that are - /// explicitely exported as GPL, for a linux kernel (module) binary. - /// These are the addresses of variable symbols present in the - /// __ksymtab_gpl section. - const address_set_sptr& - linux_exported_gpl_var_syms() const - {return const_cast(this)->linux_exported_gpl_var_syms();} - - /// Create an empty set of addresses of GPL variables exported from - /// a linux kernel (module) binary, or return the one that already - /// exists. - /// - /// @return the set of addresses of exported variable symbols. - address_set_sptr& - create_or_get_linux_exported_gpl_var_syms() - { - if (!linux_exported_gpl_var_syms_) - linux_exported_gpl_var_syms_.reset(new address_set_type); - return linux_exported_gpl_var_syms_; - } - /// Getter for the ELF dt_needed tag. const vector& dt_needed() const @@ -6137,28 +5772,6 @@ public: elf_architecture() const {return elf_architecture_;} - /// Getter for the map of global variables symbol address -> global - /// variable symbol index. - /// - /// @return the map. Note that this initializes the map once when - /// its nedded. - const addr_elf_symbol_sptr_map_type& - var_addr_sym_map() const - {return const_cast(this)->var_addr_sym_map();} - - /// Getter for the map of global variables symbol address -> global - /// variable symbol index. - /// - /// @return the map. Note that this initializes the map once when - /// its nedded. - addr_elf_symbol_sptr_map_type& - var_addr_sym_map() - { - if (!var_addr_sym_map_) - maybe_load_symbol_maps(); - return *var_addr_sym_map_; - } - /// Load the maps address -> function symbol, address -> variable /// symbol and the maps of function and variable undefined symbols. /// @@ -6383,364 +5996,6 @@ public: return true; } - /// Try reading the first __ksymtab section entry. - /// - /// We lookup the symbol from the raw section passed as an argument. For - /// that, consider endianess and adjust for potential Elf relocations before - /// looking up the symbol in the .symtab section. - // - /// Optionally, support position relative relocations by considering the - /// ksymtab entry as 32 bit and applying the relocation relative to the - /// section header (i.e. the symbol position as we are reading the first - /// symbol). - /// - /// @param section the ksymtab section to consider. - /// - /// @param position_relative_relocations if true, then consider that - /// the section designated by @p section contains position-relative - /// relocated symbol addresses. - /// - /// @param symbol_offset if different from zero - /// If symbol_offset is != 0, adjust the position we consider the section - /// start. That is useful to read the ksymtab with a slight offset. - /// - /// Note, this function does not support relocatable ksymtab entries (as for - /// example in kernel modules). Using this function for ksymtabs where - /// relocations need to be applied for the entries we are reading here, will - /// yield wrong results. - /// - /// @return the symbol resulting from the lookup of the symbol address we - /// got from reading the first entry of the ksymtab or null if no such entry - /// could be found. - elf_symbol_sptr - try_reading_first_ksymtab_entry(Elf_Scn* section, - bool position_relative_relocations, - int symbol_offset = 0) const - { - Elf_Data* elf_data = elf_rawdata(section, 0); - uint8_t* bytes = reinterpret_cast(elf_data->d_buf); - bool is_big_endian = architecture_is_big_endian(elf_handle()); - elf_symbol_sptr symbol; - GElf_Addr symbol_address = 0; - - unsigned char symbol_value_size; - if (position_relative_relocations) - symbol_value_size = sizeof(int32_t); - else - symbol_value_size = get_architecture_word_size(elf_handle()); - - const int read_offset = (symbol_offset * symbol_value_size); - bytes += read_offset; - - if (position_relative_relocations) - { - int32_t offset = 0; - ABG_ASSERT(read_int_from_array_of_bytes(bytes, symbol_value_size, - is_big_endian, offset)); - GElf_Shdr section_header; - gelf_getshdr(section, §ion_header); - // the actual symbol address is relative to its position. Since we do - // not know the position, we take the beginning of the section, add the - // read_offset that we might have and finally apply the offset we - // read from the section. - symbol_address = section_header.sh_addr + read_offset + offset; - } - else - ABG_ASSERT(read_int_from_array_of_bytes(bytes, symbol_value_size, - is_big_endian, symbol_address)); - - symbol_address = maybe_adjust_fn_sym_address(symbol_address); - symbol = lookup_elf_symbol_from_address(symbol_address); - return symbol; - } - - /// Try reading the first __ksymtab section entry as if it is in the - /// pre-v4_19 format, that is without position relative relocations. - /// - /// @return the symbol resulting from the lookup of the symbol - /// address we got from reading the first entry of the ksymtab - /// section assuming the pre-v4.19 format. If null, it means the - /// __ksymtab section is not in the pre-v4.19 format. - elf_symbol_sptr - try_reading_first_ksymtab_entry_using_pre_v4_19_format() const - { - Elf_Scn *section = find_any_ksymtab_section(); - return try_reading_first_ksymtab_entry(section, false); - } - - /// Try reading the first __ksymtab section entry as if it is in the - /// v4_19 format, that is with position relative relocations. - /// - /// @return the symbol resulting from the lookup of the symbol - /// address we got from reading the first entry of the ksymtab - /// section assuming the v4.19 format. If null, it means the - /// __ksymtab section is not in the v4.19 format. - elf_symbol_sptr - try_reading_first_ksymtab_entry_using_v4_19_format() const - { - Elf_Scn *section = find_any_ksymtab_section(); - return try_reading_first_ksymtab_entry(section, true); - } - - /// Try to determine the format of the __ksymtab and __ksymtab_gpl - /// sections of Linux kernel modules. - /// - /// This is important because we need to know the format of these - /// sections to be able to read from them. - /// - /// @return the format the __ksymtab[_gpl] sections. - enum ksymtab_format - get_ksymtab_format_module() const - { - Elf_Scn *section = find_any_ksymtab_reloc_section(); - - ABG_ASSERT(section); - - // Libdwfl has a weird quirk where, in the process of obtaining an Elf - // descriptor via dwfl_module_getelf(), it will apply all relocations it - // knows how to and it will zero the relocation info after applying it. If - // the .rela__ksymtab* section contained only simple (absolute) relocations, - // they will have been all applied and sh_size will be 0. For arches that - // support relative ksymtabs, simple relocations only appear in pre-4.19 - // kernel modules. - GElf_Shdr section_mem; - GElf_Shdr *section_shdr = gelf_getshdr(section, §ion_mem); - if (section_shdr->sh_size == 0) - return PRE_V4_19_KSYMTAB_FORMAT; - - bool is_relasec = (section_shdr->sh_type == SHT_RELA); - - // If we still have a normal non-zeroed relocation section, we can guess - // what format the ksymtab is in depending on what types of relocs it - // contains. - - uint64_t type; - Elf_Data *section_data = elf_getdata(section, 0); - if (is_relasec) - { - GElf_Rela rela; - gelf_getrela(section_data, 0, &rela); - type = GELF_R_TYPE(rela.r_info); - } - else - { - GElf_Rel rel; - gelf_getrel(section_data, 0, &rel); - type = GELF_R_TYPE(rel.r_info); - } - - // Sigh, I dislike the arch-dependent code here, but this seems to be a - // reliable heuristic for kernel modules for now. Relative ksymtabs only - // supported on x86 and arm64 as of v4.19. - ksymtab_format format; - switch (type) - { - case R_X86_64_64: // Same as R_386_32, fallthrough -#ifdef HAVE_R_AARCH64_ABS64_MACRO - case R_AARCH64_ABS64: -#endif - format = PRE_V4_19_KSYMTAB_FORMAT; - break; - case R_X86_64_PC32: // Same as R_386_PC32, fallthrough -#ifdef HAVE_R_AARCH64_PREL32_MACRO - case R_AARCH64_PREL32: -#endif - format = V4_19_KSYMTAB_FORMAT; - break; - default: - // Fall back to other methods of determining the ksymtab format. - format = UNDEFINED_KSYMTAB_FORMAT; - break; - } - return format; - } - - /// Determine the format of the __ksymtab and __ksymtab_gpl - /// sections. - /// - /// This is important because we need the know the format of these - /// sections to be able to read from them. - /// - /// @return the format the __ksymtab[_gpl] sections. - enum ksymtab_format - get_ksymtab_format() const - { - if (!find_any_ksymtab_section()) - ksymtab_format_ = UNDEFINED_KSYMTAB_FORMAT; - else - { - if (ksymtab_format_ == UNDEFINED_KSYMTAB_FORMAT) - { - // Since Linux kernel modules are relocatable, we can first try - // using a heuristic based on relocations to guess the ksymtab format. - if (is_linux_kernel_module(elf_handle())) - { - ksymtab_format_ = get_ksymtab_format_module(); - if (ksymtab_format_ != UNDEFINED_KSYMTAB_FORMAT) - return ksymtab_format_; - } - - // If it's not a kernel module or we couldn't determine its format - // with relocations, fall back to the heuristics below. - - // OK this is a dirty little heuristic to determine the - // format of the ksymtab section. - // - // We try to read the first ksymtab entry assuming a - // pre-v4.19 format. If that succeeds then we are in the - // pr-v4.19 format. Otherwise, try reading it assuming a - // v4.19 format. For now, we just support - // PRE_V4_19_KSYMTAB_FORMAT and V4_19_KSYMTAB_FORMAT. - if (try_reading_first_ksymtab_entry_using_pre_v4_19_format()) - ksymtab_format_ = PRE_V4_19_KSYMTAB_FORMAT; - else if (try_reading_first_ksymtab_entry_using_v4_19_format()) - ksymtab_format_ = V4_19_KSYMTAB_FORMAT; - else - // If a new format emerges, then we need to add its - // support above. - ABG_ASSERT_NOT_REACHED; - } - } - return ksymtab_format_; - } - - /// Getter of the size of the symbol value part of an entry of the - /// ksymtab section. - /// - /// @return the size of the symbol value part of the entry of the - /// ksymtab section. - unsigned char - get_ksymtab_symbol_value_size() const - { - unsigned char result = 0; - ksymtab_format format = get_ksymtab_format(); - if (format == UNDEFINED_KSYMTAB_FORMAT) - ; - else if (format == PRE_V4_19_KSYMTAB_FORMAT) - result = get_architecture_word_size(elf_handle()); - else if (format == V4_19_KSYMTAB_FORMAT) - result = 4; - else - ABG_ASSERT_NOT_REACHED; - - return result; - } - - /// Getter of the size of one entry of the ksymtab section. - /// - /// @return the size of one entry of the ksymtab section. - unsigned char - get_ksymtab_entry_size() const - { - if (ksymtab_entry_size_ == 0) - { - const unsigned char symbol_size = get_ksymtab_symbol_value_size(); - Elf_Scn* ksymtab = find_any_ksymtab_section(); - if (ksymtab) - { - GElf_Shdr ksymtab_shdr; - gelf_getshdr(ksymtab, &ksymtab_shdr); - - // ksymtab entries have the following layout - // - // struct { - // T symbol_address; // .symtab entry - // T name_address; // .strtab entry - // } - // - // with T being a suitable type to represent the absolute, - // relocatable or position relative value of the address. T's size - // is determined by get_ksymtab_symbol_value_size(). - // - // Since Kernel v5.4, the entries have the following layout - // - // struct { - // T symbol_address; // .symtab entry - // T name_address; // .strtab entry - // T namespace; // .strtab entry - // } - // - // To determine the ksymtab entry size, find the next entry that - // refers to a valid .symtab entry. The offset to that one is what - // we are searching for. - for (unsigned entries = 2; entries <= 3; ++entries) - { - const unsigned candidate_size = entries * symbol_size; - - // if there is exactly one entry, section size == entry size - // (this looks like an optimization, but in fact it prevents - // from illegal reads if there is actually only one entry) - if (ksymtab_shdr.sh_size == candidate_size) - { - ksymtab_entry_size_ = candidate_size; - break; - } - - // otherwise check whether the symbol following the candidate - // number of entries is a valid ELF symbol. For that we read - // the ksymtab with the given offset and if the symbol is - // valid, we found our entry size. - const ksymtab_format format = get_ksymtab_format(); - if (try_reading_first_ksymtab_entry - (ksymtab, format == V4_19_KSYMTAB_FORMAT, entries)) - { - ksymtab_entry_size_ = candidate_size; - break; - } - } - ABG_ASSERT(ksymtab_entry_size_ != 0); - } - } - - return ksymtab_entry_size_; - } - - /// Getter of the number of entries that are present in the ksymtab - /// section. - /// - /// @return the number of entries that are present in the ksymtab - /// section. - size_t - get_nb_ksymtab_entries() const - { - if (nb_ksymtab_entries_ == 0) - { - Elf_Scn *section = find_ksymtab_section(); - if (section) - { - GElf_Shdr header_mem; - GElf_Shdr *section_header = gelf_getshdr(section, &header_mem); - size_t entry_size = get_ksymtab_entry_size(); - ABG_ASSERT(entry_size); - nb_ksymtab_entries_ = section_header->sh_size / entry_size; - } - } - return nb_ksymtab_entries_; - } - - /// Getter of the number of entries that are present in the - /// ksymtab_gpl section. - /// - /// @return the number of entries that are present in the - /// ksymtab_gpl section. - size_t - get_nb_ksymtab_gpl_entries() - { - if (nb_ksymtab_gpl_entries_ == 0) - { - Elf_Scn *section = find_ksymtab_gpl_section(); - if (section) - { - GElf_Shdr header_mem; - GElf_Shdr *section_header = gelf_getshdr(section, &header_mem); - size_t entry_size = get_ksymtab_entry_size(); - ABG_ASSERT(entry_size); - nb_ksymtab_gpl_entries_ = section_header->sh_size / entry_size; - } - } - return nb_ksymtab_gpl_entries_; - } - /// Test if a given ELF symbol was suppressed by a suppression /// specification. /// @@ -6756,328 +6011,6 @@ public: symbol->get_type())); } - /// Populate the symbol map by reading exported symbols from the - /// ksymtab directly. - /// - /// @param section the ksymtab section to read from - /// - /// @param exported_fns_set the set of exported functions - /// - /// @param exported_vars_set the set of exported variables - /// - /// @param nb_entries the number of ksymtab entries to read - /// - /// @return true upon successful completion, false otherwise. - bool - populate_symbol_map_from_ksymtab(Elf_Scn *section, - address_set_sptr exported_fns_set, - address_set_sptr exported_vars_set, - size_t nb_entries) - { - // The data of the section. - Elf_Data *elf_data = elf_rawdata(section, 0); - - // An array-of-bytes view of the elf data above. Something we can - // actually program with. Phew. - uint8_t *bytes = reinterpret_cast(elf_data->d_buf); - - // This is where to store an address of a symbol that we read from - // the section. - GElf_Addr symbol_address = 0, adjusted_symbol_address = 0; - - // So the section is an array of entries. Each entry describes a - // symbol. Each entry is made of two words. - // - // The first word is the address of a symbol. The second one is - // the address of a static global variable symbol which value is - // the string representing the symbol name. That string is in the - // __ksymtab_strings section. Here, we are only interested in the - // first entry. - // - // Lets thus walk the array of entries, and let's read just the - // symbol address part of each entry. - bool is_big_endian = architecture_is_big_endian(elf_handle()); - elf_symbol_sptr symbol; - unsigned char symbol_value_size = get_ksymtab_symbol_value_size(); - - for (size_t i = 0, entry_offset = 0; - i < nb_entries; - ++i, entry_offset = get_ksymtab_entry_size() * i) - { - symbol_address = 0; - ABG_ASSERT(read_int_from_array_of_bytes(&bytes[entry_offset], - symbol_value_size, - is_big_endian, - symbol_address)); - - // Starting from linux kernel v4.19, it can happen that the - // address value read from the ksymtab[_gpl] section might - // need some decoding to get the real symbol address that has - // a meaning in the .symbol section. - symbol_address = - maybe_adjust_sym_address_from_v4_19_ksymtab(symbol_address, - entry_offset, section); - - // We might also want to adjust the symbol address, depending - // on if we are looking at an ET_REL, an executable or a - // shared object binary. - adjusted_symbol_address = maybe_adjust_fn_sym_address(symbol_address); - - if (adjusted_symbol_address == 0) - // The resulting symbol address is zero, not sure this - // valid; ignore it. - continue; - - // OK now the symbol address should be in a suitable form to - // be used to look the symbol up in the usual .symbol section - // (aka ELF symbol table). - symbol = lookup_elf_symbol_from_address(adjusted_symbol_address); - if (!symbol) - { - adjusted_symbol_address = - maybe_adjust_var_sym_address(symbol_address); - symbol = lookup_elf_symbol_from_address(adjusted_symbol_address); - if (!symbol) - // This must be a symbol that is of type neither FUNC - // (function) nor OBJECT (variable). There are for intance, - // symbols of type 'NOTYPE' in the ksymtab symbol table. I - // am not sure what those are. - continue; - } - - // If the symbol was suppressed by a suppression - // specification then drop it on the floor. - if (is_elf_symbol_suppressed(symbol)) - continue; - - address_set_sptr set; - if (symbol->is_function()) - { - ABG_ASSERT(lookup_elf_fn_symbol_from_address - (adjusted_symbol_address)); - set = exported_fns_set; - } - else if (symbol->is_variable()) - { - ABG_ASSERT(lookup_elf_var_symbol_from_address - (adjusted_symbol_address)); - set = exported_vars_set; - } - else - ABG_ASSERT_NOT_REACHED; - set->insert(adjusted_symbol_address); - } - return true; - } - - /// Populate the symbol map by extracting the exported symbols from a - /// ksymtab rela section. - /// - /// @param section the ksymtab section to read from - /// - /// @param exported_fns_set the set of exported functions - /// - /// @param exported_vars_set the set of exported variables - /// - /// @return true upon successful completion, false otherwise. - bool - populate_symbol_map_from_ksymtab_reloc(Elf_Scn *reloc_section, - address_set_sptr exported_fns_set, - address_set_sptr exported_vars_set) - { - GElf_Shdr reloc_section_mem; - GElf_Shdr *reloc_section_shdr = gelf_getshdr(reloc_section, - &reloc_section_mem); - size_t reloc_count = - reloc_section_shdr->sh_size / reloc_section_shdr->sh_entsize; - - Elf_Data *reloc_section_data = elf_getdata(reloc_section, 0); - - bool is_relasec = (reloc_section_shdr->sh_type == SHT_RELA); - elf_symbol_sptr symbol; - GElf_Sym native_symbol; - for (unsigned int i = 0; i < reloc_count; i++) - { - if (is_relasec) - { - GElf_Rela rela; - gelf_getrela(reloc_section_data, i, &rela); - symbol = lookup_elf_symbol_from_index(GELF_R_SYM(rela.r_info), - native_symbol); - } - else - { - GElf_Rel rel; - gelf_getrel(reloc_section_data, i, &rel); - symbol = lookup_elf_symbol_from_index(GELF_R_SYM(rel.r_info), - native_symbol); - } - - ABG_ASSERT(symbol); - - // If the symbol is a linux string constant then ignore it. - if (symbol->get_is_linux_string_cst()) - continue; - - if (!symbol->is_function() && !symbol->is_variable()) - { - if (do_log()) - { - if (symbol->get_type() == elf_symbol::NOTYPE_TYPE) - cerr << "skipping NOTYPE symbol " - << symbol->get_name() - << " shndx: " - << symbol->get_index() - << " @" - << elf_path() - << "\n"; - else if (symbol->get_type() == elf_symbol::SECTION_TYPE) - cerr << "skipping SECTION symbol " - << "shndx: " - << symbol->get_index() - << " @" - << elf_path() - << "\n"; - } - continue; - } - - // If the symbol was suppressed by a suppression - // specification then drop it on the floor. - if (is_elf_symbol_suppressed(symbol)) - continue; - - // If we are looking at an ET_REL (relocatable) binary, then - // the symbol value of native_symbol is relative to the - // section that symbol is defined in. We need to translate it - // into an absolute (okay, binary-relative, rather) address. - GElf_Addr symbol_address = - maybe_adjust_et_rel_sym_addr_to_abs_addr(elf_handle(), - &native_symbol); - - address_set_sptr set; - if (symbol->is_function()) - { - ABG_ASSERT(lookup_elf_fn_symbol_from_address(symbol_address)); - set = exported_fns_set; - } - else if (symbol->is_variable()) - { - ABG_ASSERT(lookup_elf_var_symbol_from_address(symbol_address)); - set = exported_vars_set; - } - else - ABG_ASSERT_NOT_REACHED; - set->insert(symbol_address); - } - return true; - } - - /// Load a given kernel symbol table. - /// - /// One can thus retrieve the resulting symbols by using the - /// accessors read_context::linux_exported_fn_syms(), - /// read_context::linux_exported_var_syms(), - /// read_context::linux_exported_gpl_fn_syms(), or - /// read_context::linux_exported_gpl_var_syms(). - /// - /// @param kind the kind of kernel symbol table to load. - /// - /// @return true upon successful completion, false otherwise. - bool - load_kernel_symbol_table(kernel_symbol_table_kind kind) - { - Elf_Scn *section = 0, *reloc_section = 0; - address_set_sptr linux_exported_fns_set, linux_exported_vars_set; - - switch (kind) - { - case KERNEL_SYMBOL_TABLE_KIND_UNDEFINED: - break; - case KERNEL_SYMBOL_TABLE_KIND_KSYMTAB: - section = find_ksymtab_section(); - reloc_section = find_ksymtab_reloc_section(); - linux_exported_fns_set = create_or_get_linux_exported_fn_syms(); - linux_exported_vars_set = create_or_get_linux_exported_var_syms(); - break; - case KERNEL_SYMBOL_TABLE_KIND_KSYMTAB_GPL: - section = find_ksymtab_gpl_section(); - reloc_section = find_ksymtab_gpl_reloc_section(); - linux_exported_fns_set = create_or_get_linux_exported_gpl_fn_syms(); - linux_exported_vars_set = create_or_get_linux_exported_gpl_var_syms(); - break; - } - - if (!linux_exported_vars_set || !linux_exported_fns_set || !section) - return false; - - ksymtab_format format = get_ksymtab_format(); - - // Although pre-v4.19 kernel modules can have a relocation section for the - // __ksymtab section, libdwfl zeroes the rela section after applying - // "simple" absolute relocations via dwfl_module_getelf(). For v4.19 and - // above, we get PC-relative relocations so dwfl_module_getelf() doesn't - // apply those relocations and we're safe to read the relocation section to - // determine which exported symbols are in the ksymtab. - if (!reloc_section || format == PRE_V4_19_KSYMTAB_FORMAT) - { - size_t nb_entries = 0; - if (kind == KERNEL_SYMBOL_TABLE_KIND_KSYMTAB) - nb_entries = get_nb_ksymtab_entries(); - else if (kind == KERNEL_SYMBOL_TABLE_KIND_KSYMTAB_GPL) - nb_entries = get_nb_ksymtab_gpl_entries(); - - if (!nb_entries) - return false; - - return populate_symbol_map_from_ksymtab( - section, linux_exported_fns_set, linux_exported_vars_set, - nb_entries); - } - else - return populate_symbol_map_from_ksymtab_reloc(reloc_section, - linux_exported_fns_set, - linux_exported_vars_set); - } - - /// Load the special __ksymtab section. This is for linux kernel - /// (module) files. - /// - /// @return true upon successful completion, false otherwise. - bool - load_ksymtab_symbols() - { - return load_kernel_symbol_table(KERNEL_SYMBOL_TABLE_KIND_KSYMTAB); - } - - /// Load the special __ksymtab_gpl section. This is for linux kernel - /// (module) files. - /// - /// @return true upon successful completion, false otherwise. - bool - load_ksymtab_gpl_symbols() - { - return load_kernel_symbol_table(KERNEL_SYMBOL_TABLE_KIND_KSYMTAB_GPL); - } - - /// Load linux kernel (module) specific exported symbol sections. - /// - /// @return true upon successful completion, false otherwise. - bool - load_linux_specific_exported_symbol_maps() - { - bool loaded = false; - if (!linux_exported_fn_syms_ - || !linux_exported_var_syms_) - loaded |= load_ksymtab_symbols(); - - if (!linux_exported_gpl_fn_syms_ - || !linux_exported_gpl_var_syms_) - loaded |= load_ksymtab_gpl_symbols(); - - return loaded; - } - /// Load the maps of function symbol address -> function symbol, /// global variable symbol address -> variable symbol and also the /// maps of function and variable undefined symbols. @@ -7120,11 +6053,7 @@ public: load_var_map, load_undefined_fun_map, load_undefined_var_map)) - { - if (load_in_linux_kernel_mode() && is_linux_kernel(elf_handle())) - return load_linux_specific_exported_symbol_maps(); return true; - } return false; } return true; @@ -7204,36 +6133,6 @@ public: load_elf_architecture(); } - /// Convert the value of the symbol address part of a post V4.19 - /// ksymtab entry (that contains place-relative addresses) into its - /// corresponding symbol value in the .symtab section. The value of - /// the symbol in .symtab equals to addr_offset + address-of-ksymtab - /// + addr. - /// - /// @param addr the address read from the ksymtab section. - /// - /// @param addr_offset the offset at which @p addr was read. - /// - /// @param ksymtab_section the kymstab section @p addr was read - /// from. - GElf_Addr - maybe_adjust_sym_address_from_v4_19_ksymtab(GElf_Addr addr, - size_t addr_offset, - Elf_Scn *ksymtab_section) const - { - GElf_Addr result = addr; - - if (get_ksymtab_format() == V4_19_KSYMTAB_FORMAT) - { - int32_t offset = addr; - GElf_Shdr mem; - GElf_Shdr *section_header = gelf_getshdr(ksymtab_section, &mem); - result = offset + section_header->sh_addr + addr_offset; - } - - return result; - } - /// This is a sub-routine of maybe_adjust_fn_sym_address and /// maybe_adjust_var_sym_address. /// @@ -15903,34 +14802,6 @@ build_function_decl(read_context& ctxt, return result; } -/// Add a set of addresses (representing function symbols) to a -/// function symbol name -> symbol map. -/// -/// For a given symbol address, the function retrieves the name of the -/// symbol as well as the symbol itself and inserts an entry {symbol -/// name, symbol} into a map of symbol name -> symbol map. -/// -/// @param syms the set of symbol addresses to consider. -/// -/// @param map the map to populate. -/// -/// @param ctxt the context in which we are loading a given ELF file. -static void -add_fn_symbols_to_map(address_set_type& syms, - string_elf_symbols_map_type& map, - read_context& ctxt) -{ - for (address_set_type::iterator i = syms.begin(); i != syms.end(); ++i) - { - elf_symbol_sptr sym = ctxt.lookup_elf_fn_symbol_from_address(*i); - ABG_ASSERT(sym); - string_elf_symbols_map_type::iterator it = - ctxt.fun_syms().find(sym->get_name()); - ABG_ASSERT(it != ctxt.fun_syms().end()); - map.insert(*it); - } -} - /// Add a symbol to a symbol map. /// /// @param sym the symbol to add. @@ -15954,34 +14825,6 @@ add_symbol_to_map(const elf_symbol_sptr& sym, it->second.push_back(sym); } -/// Add a set of addresses (representing variable symbols) to a -/// variable symbol name -> symbol map. -/// -/// For a given symbol address, the variable retrieves the name of the -/// symbol as well as the symbol itself and inserts an entry {symbol -/// name, symbol} into a map of symbol name -> symbol map. -/// -/// @param syms the set of symbol addresses to consider. -/// -/// @param map the map to populate. -/// -/// @param ctxt the context in which we are loading a given ELF file. -static void -add_var_symbols_to_map(address_set_type& syms, - string_elf_symbols_map_type& map, - read_context& ctxt) -{ - for (address_set_type::iterator i = syms.begin(); i != syms.end(); ++i) - { - elf_symbol_sptr sym = ctxt.lookup_elf_var_symbol_from_address(*i); - ABG_ASSERT(sym); - string_elf_symbols_map_type::iterator it = - ctxt.var_syms().find(sym->get_name()); - ABG_ASSERT(it != ctxt.var_syms().end()); - map.insert(*it); - } -} - /// Read all @ref abigail::translation_unit possible from the debug info /// accessible through a DWARF Front End Library handle, and stuff /// them into a libabigail ABI Corpus. @@ -16025,22 +14868,26 @@ read_debug_info_into_corpus(read_context& ctxt) { string_elf_symbols_map_sptr exported_fn_symbols_map (new string_elf_symbols_map_type); - add_fn_symbols_to_map(*ctxt.linux_exported_fn_syms(), - *exported_fn_symbols_map, - ctxt); - add_fn_symbols_to_map(*ctxt.linux_exported_gpl_fn_syms(), - *exported_fn_symbols_map, - ctxt); + auto filter = ctxt.symtab()->make_filter(); + filter.set_functions(); + + for (const auto& symbol : + symtab_reader::filtered_symtab(*ctxt.symtab(), filter)) + { + (*exported_fn_symbols_map)[symbol->get_name()].push_back(symbol); + } + ctxt.current_corpus()->set_fun_symbol_map(exported_fn_symbols_map); - string_elf_symbols_map_sptr exported_var_symbols_map - (new string_elf_symbols_map_type); - add_var_symbols_to_map(*ctxt.linux_exported_var_syms(), - *exported_var_symbols_map, - ctxt); - add_var_symbols_to_map(*ctxt.linux_exported_gpl_var_syms(), - *exported_var_symbols_map, - ctxt); + string_elf_symbols_map_sptr exported_var_symbols_map( + new string_elf_symbols_map_type); + filter = ctxt.symtab()->make_filter(); + filter.set_variables(); + for (const auto& symbol : + symtab_reader::filtered_symtab(*ctxt.symtab(), filter)) + { + (*exported_var_symbols_map)[symbol->get_name()].push_back(symbol); + } ctxt.current_corpus()->set_var_symbol_map(exported_var_symbols_map); } else From patchwork Wed Jan 27 12:58:45 2021 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: 41846 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 984033972827; Wed, 27 Jan 2021 12:59:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 984033972827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752377; bh=BB7rkhQWHrLI3ZRS7W2Gfg1lpUdW13Q1RJames8VjK0=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=pHsuytpr8nSJHdnqSBQxCZyKGxAvlRMASSCoTrdxMu3Lpe0tzc4kPHkxq7XNZj81g GQFpYqlXtufe6J7JNHaxPF3IO4q9+qK14iFsV4KK7fa3y2WkG1VZUposC4+avmxoaw KUILkxeiUnuS8jKOoBdeBDwK3rnPrKslaYgrTA9k= 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 1AE6C3972827 for ; Wed, 27 Jan 2021 12:59:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1AE6C3972827 Received: by mail-wr1-x449.google.com with SMTP id n14so910107wru.6 for ; Wed, 27 Jan 2021 04:59:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=BB7rkhQWHrLI3ZRS7W2Gfg1lpUdW13Q1RJames8VjK0=; b=fEGC6awxtgPi9JzioDrNPZXHc6/fhABDuubQiSaRRUYtp9raSwc2/8lg+EPDFqi7t0 gco1B2ZLj41Ybd2xlwCQnHpnVFRPx8Fav77WNE3MfUmG/ZfNeILTaktgrwYNxhruaRVZ unv1DbsnZjCtCv77gJSHHnLcLW1BjA/B+ZkctQIwykdNKRgJ82eHKPk/9J42j40ziAnB SnVHNQVhNafjGygN76E3wz+R2Ej6mj5gdrBmzEOYkBVi6ZsCADgx8wwmwXm0YI/Hmpt0 gfI7BWwXs5PgLozoxE0DwnIsid9VeAwShRKfHLrbfWstgQ+mOxdoC/LaSd1CzFw9gmEm fpdg== X-Gm-Message-State: AOAM532llNbb8eA14bTSDV9Tusj80O2pM78HsWl6y3Ur3hwhSs39wkhf Zr/XM3VoG42AhIzZ3X5+a0pilelFYghsrRAPSTwiOoW63rRhgcq8CrtLKVgKuE3TgqqwU2HBJLy jCF738Dam6SqwHPJi1oBEOYz1KhIfal1Xt8Ajcj/mqFwCkWcRsnnwB/mS/MYS2s1wvqLy9x8= X-Google-Smtp-Source: ABdhPJx98fcbZ+REFVEnqOQmYeUUrankvlkvSwJR8KXCMgDQiqqKv0eiSlm/rT1Dr5dms9Y8YJu7SpfGZiI6ZQ== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:a05:600c:258:: with SMTP id 24mr4091531wmj.161.1611752373182; Wed, 27 Jan 2021 04:59:33 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:45 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-13-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 12/20] abg-elf-helpers: migrate ppc64 specific helpers To: libabigail@sourceware.org X-Spam-Status: No, score=-23.2 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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" This migrates more helpers to abg-elf-helpers: lookup_ppc64_elf_fn_entry_point_address with dependencies read_uint64_from_array_of_bytes read_int_from_array_of_bytes address_is_in_opd_section with dependency address_is_in_section read_context::find_opd_section and read_context::opd_section_ are obsolete. * src/abg-dwarf-reader.cc (read_context::opd_section_): Delete. (read_context::find_opd_section): Delete. (read_context::read_uint64_from_array_of_bytes): Delete. (read_context::read_int_from_array_of_bytes): Delete. (read_context::lookup_ppc64_elf_fn_entry_point_address): Delete. (read_context::address_is_in_opd_section): Delete. (read_context::address_is_in_section): Delete. (read_context::load_symbol_maps_from_symtab_section): Adjust. * src/abg-elf-helpers.cc (read_int_from_array_of_bytes): New. (read_uint64_from_array_of_bytes): New. (lookup_ppc64_elf_fn_entry_point_address): New. (address_is_in_section): New. (address_is_in_opd_section): New. * src/abg-elf-helpers.h (lookup_ppc64_elf_fn_entry_point_address): New declaration. (address_is_in_opd_section): New declaration. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- src/abg-dwarf-reader.cc | 208 +--------------------------------------- src/abg-elf-helpers.cc | 186 +++++++++++++++++++++++++++++++++++ src/abg-elf-helpers.h | 8 ++ 3 files changed, 198 insertions(+), 204 deletions(-) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 693fae82040e..b2a7144afe9d 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -2141,10 +2141,6 @@ public: mutable Elf* elf_handle_; string elf_path_; mutable Elf_Scn* symtab_section_; - // The "Official procedure descriptor section, aka .opd", used in - // ppc64 elf v1 binaries. This section contains the procedure - // descriptors on that platform. - mutable Elf_Scn* opd_section_; Dwarf_Die* cur_tu_die_; mutable dwarf_expr_eval_context dwarf_expr_eval_context_; // A set of maps (one per kind of die source) that associates a decl @@ -2325,7 +2321,6 @@ public: elf_handle_ = 0; elf_path_ = elf_path; symtab_section_ = 0; - opd_section_ = 0; cur_tu_die_ = 0; exported_decls_builder_ = 0; @@ -5312,19 +5307,6 @@ public: return symtab_section_; } - /// Return the "Official Procedure descriptors section." This - /// section is named .opd, and is usually present only on PPC64 - /// ELFv1 binaries. - /// - /// @return the .opd section, if found. Return nil otherwise. - Elf_Scn* - find_opd_section() const - { - if (!opd_section_) - opd_section_ = elf_helpers::find_opd_section(elf_handle()); - return opd_section_; - } - /// Lookup an elf symbol, referred to by its index, from the .symtab /// section. /// @@ -5436,152 +5418,6 @@ public: return sym; } - /// Read 8 bytes and convert their value into an uint64_t. - /// - /// @param bytes the array of bytes to read the next 8 bytes from. - /// Note that this array must be at least 8 bytes long. - /// - /// @param result where to store the resuting uint64_t that was read. - /// - /// @param is_big_endian if true, read the 8 bytes in Big Endian - /// mode, otherwise, read them in Little Endian. - /// - /// @param true if the 8 bytes could be read, false otherwise. - bool - read_uint64_from_array_of_bytes(const uint8_t *bytes, - bool is_big_endian, - uint64_t &result) const - { - return read_int_from_array_of_bytes(bytes, 8, is_big_endian, result); - } - - /// Read N bytes and convert their value into an integer type T. - /// - /// Note that N cannot be bigger than 8 for now. The type passed needs to be - /// at least of the size of number_of_bytes. - /// - /// @param bytes the array of bytes to read the next 8 bytes from. - /// Note that this array must be at least 8 bytes long. - /// - /// @param number_of_bytes the number of bytes to read. This number - /// cannot be bigger than 8. - /// - /// @param is_big_endian if true, read the 8 bytes in Big Endian - /// mode, otherwise, read them in Little Endian. - /// - /// @param result where to store the resuting integer that was read. - /// - /// - /// @param true if the 8 bytes could be read, false otherwise. - template - bool - read_int_from_array_of_bytes(const uint8_t *bytes, - unsigned char number_of_bytes, - bool is_big_endian, - T &result) const - { - if (!bytes) - return false; - - ABG_ASSERT(number_of_bytes <= 8); - ABG_ASSERT(number_of_bytes <= sizeof(T)); - - T res = 0; - - const uint8_t *cur = bytes; - if (is_big_endian) - { - // In Big Endian, the most significant byte is at the lowest - // address. - const uint8_t* msb = cur; - res = *msb; - - // Now read the remaining least significant bytes. - for (uint i = 1; i < number_of_bytes; ++i) - res = (res << 8) | ((T)msb[i]); - } - else - { - // In Little Endian, the least significant byte is at the - // lowest address. - const uint8_t* lsb = cur; - res = *lsb; - // Now read the remaining most significant bytes. - for (uint i = 1; i < number_of_bytes; ++i) - res = res | (((T)lsb[i]) << i * 8); - } - - result = res; - return true; - } - - /// Lookup the address of the function entry point that corresponds - /// to the address of a given function descriptor. - /// - /// On PPC64, a function pointer is the address of a function - /// descriptor. Function descriptors are located in the .opd - /// section. Each function descriptor is a triplet of three - /// addresses, each one on 64 bits. Among those three address only - /// the first one is of any interest to us: the address of the entry - /// point of the function. - /// - /// This function returns the address of the entry point of the - /// function whose descriptor's address is given. - /// - /// http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.html#FUNC-DES - /// - /// https://www.ibm.com/developerworks/community/blogs/5894415f-be62-4bc0-81c5-3956e82276f3/entry/deeply_understand_64_bit_powerpc_elf_abi_function_descriptors?lang=en - /// - /// @param fn_desc_address the address of the function descriptor to - /// consider. - /// - /// @return the address of the entry point of the function whose - /// descriptor has the address @p fn_desc_address. If there is no - /// .opd section (e.g because we are not on ppc64) or more generally - /// if the function descriptor could not be found then this function - /// just returns the address of the fuction descriptor. - GElf_Addr - lookup_ppc64_elf_fn_entry_point_address(GElf_Addr fn_desc_address) const - { - if (!elf_handle()) - return fn_desc_address; - - if (!architecture_is_ppc64(elf_handle())) - return fn_desc_address; - - bool is_big_endian = architecture_is_big_endian(elf_handle()); - - Elf_Scn *opd_section = find_opd_section(); - if (!opd_section) - return fn_desc_address; - - GElf_Shdr header_mem; - // The section header of the .opd section. - GElf_Shdr *opd_sheader = gelf_getshdr(opd_section, &header_mem); - - // The offset of the function descriptor entry, in the .opd - // section. - size_t fn_desc_offset = fn_desc_address - opd_sheader->sh_addr; - Elf_Data *elf_data = elf_rawdata(opd_section, 0); - - // Ensure that the opd_section has at least 8 bytes, starting from - // the offset we want read the data from. - if (elf_data->d_size <= fn_desc_offset + 8) - return fn_desc_address; - - // A pointer to the data of the .opd section, that we can actually - // do something with. - uint8_t * bytes = (uint8_t*) elf_data->d_buf; - - // The resulting address we are looking for is going to be formed - // in this variable. - GElf_Addr result = 0; - ABG_ASSERT(read_uint64_from_array_of_bytes(bytes + fn_desc_offset, - is_big_endian, result)); - - return result; - } - /// Test if a given function symbol has been exported. /// /// @param symbol_address the address of the symbol we are looking @@ -5890,13 +5726,15 @@ public: // symbol that are in the .opd section. GElf_Addr fn_desc_addr = sym->st_value; GElf_Addr fn_entry_point_addr = - lookup_ppc64_elf_fn_entry_point_address(fn_desc_addr); + lookup_ppc64_elf_fn_entry_point_address( + elf_handle(), fn_desc_addr); addr_elf_symbol_sptr_map_type::const_iterator it2 = fun_entry_addr_sym_map().find(fn_entry_point_addr); if (it2 == fun_entry_addr_sym_map().end()) fun_entry_addr_sym_map()[fn_entry_point_addr] = symbol; - else if (address_is_in_opd_section(fn_desc_addr)) + else if (address_is_in_opd_section(elf_handle(), + fn_desc_addr)) { // Either // @@ -6059,24 +5897,6 @@ public: return true; } - /// Return true if an address is in the ".opd" section that is - /// present on the ppc64 platform. - /// - /// @param addr the address to consider. - /// - /// @return true iff @p addr is designates a word that is in the - /// ".opd" section. - bool - address_is_in_opd_section(Dwarf_Addr addr) - { - Elf_Scn * opd_section = find_opd_section(); - if (!opd_section) - return false; - if (address_is_in_section(addr, opd_section)) - return true; - return false; - } - /// Load the symbol maps if necessary. /// /// @return true iff the symbol maps has been loaded by this @@ -6227,26 +6047,6 @@ public: return addr; } - /// Test if a given address is in a given section. - /// - /// @param addr the address to consider. - /// - /// @param section the section to consider. - bool - address_is_in_section(Dwarf_Addr addr, Elf_Scn* section) const - { - if (!section) - return false; - - GElf_Shdr sheader_mem; - GElf_Shdr* sheader = gelf_getshdr(section, &sheader_mem); - - if (sheader->sh_addr <= addr && addr <= sheader->sh_addr + sheader->sh_size) - return true; - - return false; - } - /// For a relocatable (*.o) elf file, this function expects an /// absolute address, representing a global variable symbol. It /// then extracts the address of the {.data,.data1,.rodata,.bss} diff --git a/src/abg-elf-helpers.cc b/src/abg-elf-helpers.cc index 5130e5b64f7a..fb9f3af67bfc 100644 --- a/src/abg-elf-helpers.cc +++ b/src/abg-elf-helpers.cc @@ -848,6 +848,153 @@ architecture_is_big_endian(Elf* elf_handle) return is_big_endian; } +/// Read N bytes and convert their value into an integer type T. +/// +/// Note that N cannot be bigger than 8 for now. The type passed needs to be at +/// least of the size of number_of_bytes. +/// +/// @param bytes the array of bytes to read the next 8 bytes from. +/// Note that this array must be at least 8 bytes long. +/// +/// @param number_of_bytes the number of bytes to read. This number +/// cannot be bigger than 8. +/// +/// @param is_big_endian if true, read the 8 bytes in Big Endian +/// mode, otherwise, read them in Little Endian. +/// +/// @param result where to store the resuting integer that was read. +/// +/// +/// @param true if the 8 bytes could be read, false otherwise. +template +bool +read_int_from_array_of_bytes(const uint8_t* bytes, + unsigned char number_of_bytes, + bool is_big_endian, + T& result) +{ + if (!bytes) + return false; + + ABG_ASSERT(number_of_bytes <= 8); + ABG_ASSERT(number_of_bytes <= sizeof(T)); + + T res = 0; + + const uint8_t* cur = bytes; + if (is_big_endian) + { + // In Big Endian, the most significant byte is at the lowest + // address. + const uint8_t* msb = cur; + res = *msb; + + // Now read the remaining least significant bytes. + for (uint i = 1; i < number_of_bytes; ++i) + res = (res << 8) | ((T)msb[i]); + } + else + { + // In Little Endian, the least significant byte is at the + // lowest address. + const uint8_t* lsb = cur; + res = *lsb; + // Now read the remaining most significant bytes. + for (uint i = 1; i < number_of_bytes; ++i) + res = res | (((T)lsb[i]) << i * 8); + } + + result = res; + return true; +} + +/// Read 8 bytes and convert their value into an uint64_t. +/// +/// @param bytes the array of bytes to read the next 8 bytes from. +/// Note that this array must be at least 8 bytes long. +/// +/// @param result where to store the resuting uint64_t that was read. +/// +/// @param is_big_endian if true, read the 8 bytes in Big Endian +/// mode, otherwise, read them in Little Endian. +/// +/// @param true if the 8 bytes could be read, false otherwise. +bool +read_uint64_from_array_of_bytes(const uint8_t* bytes, + bool is_big_endian, + uint64_t& result) +{ + return read_int_from_array_of_bytes(bytes, 8, is_big_endian, result); +} + + +/// Lookup the address of the function entry point that corresponds +/// to the address of a given function descriptor. +/// +/// On PPC64, a function pointer is the address of a function +/// descriptor. Function descriptors are located in the .opd +/// section. Each function descriptor is a triplet of three +/// addresses, each one on 64 bits. Among those three address only +/// the first one is of any interest to us: the address of the entry +/// point of the function. +/// +/// This function returns the address of the entry point of the +/// function whose descriptor's address is given. +/// +/// http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.html#FUNC-DES +/// +/// https://www.ibm.com/developerworks/community/blogs/5894415f-be62-4bc0-81c5-3956e82276f3/entry/deeply_understand_64_bit_powerpc_elf_abi_function_descriptors?lang=en +/// +/// @param fn_desc_address the address of the function descriptor to +/// consider. +/// +/// @return the address of the entry point of the function whose +/// descriptor has the address @p fn_desc_address. If there is no +/// .opd section (e.g because we are not on ppc64) or more generally +/// if the function descriptor could not be found then this function +/// just returns the address of the fuction descriptor. +GElf_Addr +lookup_ppc64_elf_fn_entry_point_address(Elf* elf_handle, GElf_Addr fn_desc_address) +{ + if (!elf_handle) + return fn_desc_address; + + if (!architecture_is_ppc64(elf_handle)) + return fn_desc_address; + + bool is_big_endian = architecture_is_big_endian(elf_handle); + + Elf_Scn* opd_section = find_opd_section(elf_handle); + if (!opd_section) + return fn_desc_address; + + GElf_Shdr header_mem; + // The section header of the .opd section. + GElf_Shdr* opd_sheader = gelf_getshdr(opd_section, &header_mem); + + // The offset of the function descriptor entry, in the .opd + // section. + size_t fn_desc_offset = fn_desc_address - opd_sheader->sh_addr; + Elf_Data* elf_data = elf_rawdata(opd_section, 0); + + // Ensure that the opd_section has at least 8 bytes, starting from + // the offset we want read the data from. + if (elf_data->d_size <= fn_desc_offset + 8) + return fn_desc_address; + + // A pointer to the data of the .opd section, that we can actually + // do something with. + uint8_t* bytes = (uint8_t*)elf_data->d_buf; + + // The resulting address we are looking for is going to be formed + // in this variable. + GElf_Addr result = 0; + ABG_ASSERT(read_uint64_from_array_of_bytes(bytes + fn_desc_offset, + is_big_endian, result)); + + return result; +} + /// Test if the ELF binary denoted by a given ELF handle is a Linux /// Kernel Module. /// @@ -1012,5 +1159,44 @@ maybe_adjust_et_rel_sym_addr_to_abs_addr(Elf* elf_handle, GElf_Sym* sym) return addr + section_header.sh_addr; } +/// Test if a given address is in a given section. +/// +/// @param addr the address to consider. +/// +/// @param section the section to consider. +bool +address_is_in_section(Dwarf_Addr addr, Elf_Scn* section) +{ + if (!section) + return false; + + GElf_Shdr sheader_mem; + GElf_Shdr* sheader = gelf_getshdr(section, &sheader_mem); + + if (sheader->sh_addr <= addr && addr <= sheader->sh_addr + sheader->sh_size) + return true; + + return false; +} + +/// Return true if an address is in the ".opd" section that is +/// present on the ppc64 platform. +/// +/// @param addr the address to consider. +/// +/// @return true iff @p addr is designates a word that is in the +/// ".opd" section. +bool +address_is_in_opd_section(Elf* elf_handle, Dwarf_Addr addr) +{ + Elf_Scn * opd_section = find_opd_section(elf_handle); + if (!opd_section) + return false; + if (address_is_in_section(addr, opd_section)) + return true; + return false; +} + + } // end namespace elf_helpers } // end namespace abigail diff --git a/src/abg-elf-helpers.h b/src/abg-elf-helpers.h index b4f3293d2bd6..a06232738052 100644 --- a/src/abg-elf-helpers.h +++ b/src/abg-elf-helpers.h @@ -12,6 +12,7 @@ #include "config.h" +#include #include #include @@ -133,6 +134,10 @@ architecture_is_ppc64(Elf* elf_handle); bool architecture_is_big_endian(Elf* elf_handle); +GElf_Addr +lookup_ppc64_elf_fn_entry_point_address(Elf* elf_handle, + GElf_Addr fn_desc_address); + // // Helpers for Linux Kernel Binaries // @@ -162,6 +167,9 @@ is_dso(Elf* elf_handle); GElf_Addr maybe_adjust_et_rel_sym_addr_to_abs_addr(Elf* elf_handle, GElf_Sym* sym); +bool +address_is_in_opd_section(Elf* elf_handle, Dwarf_Addr addr); + } // end namespace elf_helpers } // end namespace abigail From patchwork Wed Jan 27 12:58:46 2021 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: 41847 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 DC6CF397303B; Wed, 27 Jan 2021 12:59:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC6CF397303B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752377; bh=3UNTVFfJXRA44mQ6KDmlIB5otHyQCbI6yIrMyf/LedE=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=V0Rj94t6GtC8poK7YwV1RMRu0vXMtE8oT32i/F6CAYz9emYUvWrKeozzfLkUzG6/C epIelUlgs5asiIlRyGp/ojld6Zn/0f0wYpK9LZvRaPJ5r6W9Vcp+d8PF0I7he+ob7V fGy/plIJW91wvqAMKDyT+BegTmHzeoI9vvtE9/pk= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by sourceware.org (Postfix) with ESMTPS id 99323397282F for ; Wed, 27 Jan 2021 12:59:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 99323397282F Received: by mail-qk1-x74a.google.com with SMTP id 185so1379900qkl.6 for ; Wed, 27 Jan 2021 04:59:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=3UNTVFfJXRA44mQ6KDmlIB5otHyQCbI6yIrMyf/LedE=; b=uiABgXxlBsq9cymZQLP9ezeN0db0w6jW7jC7qya1U9vTjKwa8Lfxjzgcjxw7fVRmDv QGAHeweJOc+Vmezf3y9XzD8tDj5/KqZytRHRDJ9In8pvSmEwC+sRpnUiUTCjbKvbtG1C NGsca8uq4KaSB2GmNOwj4r+bxUW5KQsSKsPeIL6ddkwwLLEnb5trBO720SMqO5Z/rJ2F 4l8Eu1CCXP162t5wF+YRJFZ5scQEbN6kE3BLrJa/B5jBGpa2TTv5VTlrKOIGeqZGmFW2 nutRmGSYo6140p+352/EnUMFv0ztTPIxEwkwGmVb3jPZ3jvViHNrI/utAba4yclkG5Mc UudQ== X-Gm-Message-State: AOAM531ZnT0bc6rP9i3sOCl0W7TlrZmxR/iBinDCjvbkNCo8/Ti039bz p6lyz0fwPk/uiLh/3i/1uaI55sjgYaBFOK9Zgg7XngroHND5A4Iaf9fNtL9etKZ+EiFHr9k5cae WGAT/ohlF8pTb43O0i5a65q0CJwbthPtp4n0Q5Bz7r7CzuR1vFBdzjc/Ifsf0qdvGwGdjP4Y= X-Google-Smtp-Source: ABdhPJxYuxxLiAVlEtkXMdamB32SLtd4wIgLV3Bf0dEGOh84RVYixeEDlhnCbm+9CUMEUyrxIEs16v1Qwy1QrA== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:a0c:b409:: with SMTP id u9mr10322770qve.51.1611752375149; Wed, 27 Jan 2021 04:59:35 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:46 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-14-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 13/20] symtab_reader: add support for ppc64 ELFv1 binaries To: libabigail@sourceware.org X-Spam-Status: No, score=-22.8 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" When loading the symtab from an ppc64 binary, also keep track of the function entry addresses as a key for the symbol lookup. That accommodates the differences in DWARF pointing to the function entry address while the symbol table points to the function pointer. The implementation is mostly copied and adopted from abg-dwarf-reader's read_context to add this functionality also to the new symtab reader. * src/abg-symtab-reader.cc (symtab::lookup_symbol): fall back to lookup the address in entry_addr_symbol_map_. (symtab::load): update the function entry address map for ppc64 targets. (symtab::update_function_entry_address_symbol_map): New function implementation. * src/abg-symtab-reader.h (symtab::entry_addr_symbol_map_): New data member. (symtab::update_function_entry_address_symbol_map): New function declaration. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- src/abg-symtab-reader.cc | 93 ++++++++++++++++++++++++++++++++++++++-- src/abg-symtab-reader.h | 8 ++++ 2 files changed, 98 insertions(+), 3 deletions(-) diff --git a/src/abg-symtab-reader.cc b/src/abg-symtab-reader.cc index 4576be2a0b42..7318fdfce52e 100644 --- a/src/abg-symtab-reader.cc +++ b/src/abg-symtab-reader.cc @@ -100,9 +100,15 @@ const elf_symbol_sptr& symtab::lookup_symbol(GElf_Addr symbol_addr) const { static const elf_symbol_sptr empty_result; - const auto it = addr_symbol_map_.find(symbol_addr); - if (it != addr_symbol_map_.end()) - return it->second; + const auto addr_it = addr_symbol_map_.find(symbol_addr); + if (addr_it != addr_symbol_map_.end()) + return addr_it->second; + else + { + const auto entry_it = entry_addr_symbol_map_.find(symbol_addr); + if (entry_it != entry_addr_symbol_map_.end()) + return entry_it->second; + } return empty_result; } @@ -197,6 +203,8 @@ symtab::load_(Elf* elf_handle, const bool is_kernel = elf_helpers::is_linux_kernel(elf_handle); std::unordered_set exported_kernel_symbols; + const bool is_ppc64 = elf_helpers::architecture_is_ppc64(elf_handle); + for (size_t i = 0; i < number_syms; ++i) { GElf_Sym *sym, sym_mem; @@ -304,6 +312,10 @@ symtab::load_(Elf* elf_handle, elf_helpers::maybe_adjust_et_rel_sym_addr_to_abs_addr(elf_handle, sym); + if (is_ppc64 && symbol_sptr->is_function()) + update_function_entry_address_symbol_map(elf_handle, sym, + symbol_sptr); + const auto result = addr_symbol_map_.emplace(symbol_value, symbol_sptr); if (!result.second) @@ -364,5 +376,80 @@ symtab::load_(string_elf_symbols_map_sptr function_symbol_map, return true; } +void +symtab::update_function_entry_address_symbol_map( + Elf* elf_handle, + GElf_Sym* native_symbol, + const elf_symbol_sptr& symbol_sptr) +{ + + // For ppc64 ELFv1 binaries, we need to build a function entry point address + // -> function symbol map. This is in addition to the function pointer -> + // symbol map. This is because on ppc64 ELFv1, a function pointer is + // different from a function entry point address. + // + // On ppc64 ELFv1, the DWARF DIE of a function references the address of the + // entry point of the function symbol; whereas the value of the function + // symbol is the function pointer. As these addresses are different, if I we + // want to get to the symbol of a function from its entry point address (as + // referenced by DWARF function DIEs) we must have the two maps I mentionned + // right above. + // + // In other words, we need a map that associates a function entry point + // address with the symbol of that function, to be able to get the function + // symbol that corresponds to a given function DIE, on ppc64. + // + // The value of the function pointer (the value of the symbol) usually refers + // to the offset of a table in the .opd section. But sometimes, for a symbol + // named "foo", the corresponding symbol named ".foo" (note the dot before + // foo) which value is the entry point address of the function; that entry + // point address refers to a region in the .text section. + // + // So we are only interested in values of the symbol that are in the .opd + // section. + const GElf_Addr fn_desc_addr = native_symbol->st_value; + const GElf_Addr fn_entry_point_addr = + elf_helpers::lookup_ppc64_elf_fn_entry_point_address(elf_handle, + fn_desc_addr); + + const std::pair& result = + entry_addr_symbol_map_.emplace(fn_entry_point_addr, symbol_sptr); + + const addr_symbol_map_type::const_iterator it = result.first; + const bool was_inserted = result.second; + if (!was_inserted + && elf_helpers::address_is_in_opd_section(elf_handle, fn_desc_addr)) + { + // Either + // + // 'symbol' must have been registered as an alias for + // it->second->get_main_symbol() + // + // Or + // + // if the name of 'symbol' is foo, then the name of it2->second is + // ".foo". That is, foo is the name of the symbol when it refers to the + // function descriptor in the .opd section and ".foo" is an internal name + // for the address of the entry point of foo. + // + // In the latter case, we just want to keep a reference to "foo" as .foo + // is an internal name. + + const bool two_symbols_alias = + it->second->get_main_symbol()->does_alias(*symbol_sptr); + const bool symbol_is_foo_and_prev_symbol_is_dot_foo = + (it->second->get_name() == std::string(".") + symbol_sptr->get_name()); + + ABG_ASSERT(two_symbols_alias + || symbol_is_foo_and_prev_symbol_is_dot_foo); + + if (symbol_is_foo_and_prev_symbol_is_dot_foo) + // Let's just keep a reference of the symbol that the user sees in the + // source code (the one named foo). The symbol which name is prefixed + // with a "dot" is an artificial one. + entry_addr_symbol_map_[fn_entry_point_addr] = symbol_sptr; + } +} + } // end namespace symtab_reader } // end namespace abigail diff --git a/src/abg-symtab-reader.h b/src/abg-symtab-reader.h index 4c5e3b85c22d..2906bab818b0 100644 --- a/src/abg-symtab-reader.h +++ b/src/abg-symtab-reader.h @@ -251,12 +251,20 @@ private: typedef std::unordered_map addr_symbol_map_type; addr_symbol_map_type addr_symbol_map_; + /// Lookup map function entry address -> symbol + addr_symbol_map_type entry_addr_symbol_map_; + bool load_(Elf* elf_handle, ir::environment* env, symbol_predicate is_suppressed); bool load_(string_elf_symbols_map_sptr function_symbol_map, string_elf_symbols_map_sptr variables_symbol_map); + + void + update_function_entry_address_symbol_map(Elf* elf_handle, + GElf_Sym* native_symbol, + const elf_symbol_sptr& symbol_sptr); }; /// Helper class to allow range-for loops on symtabs for C++11 and later code. From patchwork Wed Jan 27 12:58:47 2021 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: 41848 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 C72683971C3C; Wed, 27 Jan 2021 12:59:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C72683971C3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752382; bh=mWWVwPNTlI0pdwpcwUXgN8kgRAkU+s+RqrD4jj3CqOc=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Dw9oS5TFC0t+7YZQF03Vtb3dQBreFKJzd3B3ZhEB3Th0u9GyD7LxM24aFEPAKgskR QLKfwBrhovcb5Kzfk8Ne2TZboT/+JCzOuwgzfIZI3tOTQiZ6rgbeAJifZDhaHrUfun QMNiktypH4fcpzJCzvcVk3iER89au/n3NUvgk20c= 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 AEA833973039 for ; Wed, 27 Jan 2021 12:59:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AEA833973039 Received: by mail-wr1-x449.google.com with SMTP id z9so902062wro.11 for ; Wed, 27 Jan 2021 04:59:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=mWWVwPNTlI0pdwpcwUXgN8kgRAkU+s+RqrD4jj3CqOc=; b=aZdthjDopUki0kWNugBFs9DXEGmBKVjqQ7Fg6mQC7lrdYf61e2absEeKT1CxqPuYHl ZYErr0uYX4yaHQEQDmmK0Wbur3tyi75qnP71+MIl5udQwG95V/SiEGHXPfSWoetM4/cA NU+BSKzLucZb1PN677O3mfbxVmxoHtha1/UwNUTnckAbD74xmMDXwoLkhXXW8PFyyh1i Pv4T45FbyQ11aEkpTlXv6ysEIqUYPmKmv/53hgKp6Ow7gMAGIZpfDYPro64C8FdrB3uS PiPAcEZPhIQbiGRu3LAFLfum8JgZn+34dsHHoMahGsHat465OSk8Rbg5OCU2WUh8Ff26 0TnQ== X-Gm-Message-State: AOAM530aMmje5SfAvwHvkcH6Q7yBZrPatfqbvP9JV4QAZW/wStJP+bfw AldU45uzTjQEaHQTwocsbt3c8yyfJZBDrYVN9qDc9e+AZ0laB2mOG3MabbBNrYm8mrfCyCY72D8 ebm8fH7hihxTyUSuI4nd5yp+kFTraAg5nSpGD6hFb+3T1TZx8vCvd4wjnsck0QNDec3XzV58= X-Google-Smtp-Source: ABdhPJyECQg5N0xNeNQhPwQqLUPleuC9cHdDwrcu/qyTMimCUxFO5WRc654EWwtHJYWAGO7cU2gWEuqWKL6Rcw== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:adf:dd81:: with SMTP id x1mr11145840wrl.249.1611752377518; Wed, 27 Jan 2021 04:59:37 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:47 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-15-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 14/20] abg-corpus: remove symbol maps and their setters To: libabigail@sourceware.org X-Spam-Status: No, score=-23.2 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" With the prework in previous commits, we are now able to drop the public symbols maps in corpus::priv and replace them by private members with access through getters. The getters use the new symtab implementation to generate the maps on the fly. Setters are not required anymore and are removed. Also remove redundant getters. We could also remove the getters for the symbol maps and the local caching variable and leave it all to lookup_symbol, but this is left for a later change. * include/abg-corpus.h (corpus::set_fun_symbol_map): Remove method declaration. (corpus::set_undefined_fun_symbol_map): Likewise. (corpus::set_var_symbol_map): Likewise. (corpus::set_undefined_var_symbol_map): Likewise. (corpus::get_fun_symbol_map_sptr): Likewise. (corpus::get_undefined_fun_symbol_map_sptr): Likewise. (corpus::get_var_symbol_map_sptr): Likewise. (corpus::get_undefined_var_symbol_map_sptr): Likewise. * src/abg-corpus-priv.h (corpus::priv::var_symbol_map): make private and mutable (corpus::priv::undefined_var_symbol_map): Likewise. (corpus::priv::fun_symbol_map): Likewise. (corpus::priv::undefined_fun_symbol_map): Likewise. (corpus::priv::get_fun_symbol_map): New method declaration. (corpus::priv::get_undefined_fun_symbol_map): Likewise. (corpus::priv::get_var_symbol_map): Likewise. (corpus::priv::get_undefined_var_symbol_map): Likewise. * src/abg-corpus.cc (corpus::priv::get_fun_symbol_map): New method implementation. (corpus::priv::get_undefined_fun_symbol_map): Likewise. (corpus::priv::get_var_symbol_map): Likewise. (corpus::priv::get_undefined_var_symbol_map): Likewise. (corpus::is_empty): depend on symtab only. (corpus::set_fun_symbol_map): Remove method. (corpus::set_undefined_fun_symbol_map): Likewise. (corpus::set_var_symbol_map): Likewise. (corpus::set_undefined_var_symbol_map): Likewise. (corpus::get_fun_symbol_map_sptr): Likewise. (corpus::get_undefined_fun_symbol_map_sptr): Likewise. (corpus::get_var_symbol_map_sptr): Likewise. (corpus::get_undefined_var_symbol_map_sptr): Likewise. (corpus::get_fun_symbol_map): Use corpus::priv proxy method. (corpus::get_undefined_fun_symbol_map): Likewise. (corpus::get_var_symbol_map): Likewise. (corpus::get_undefined_var_symbol_map): Likewise. * src/abg-dwarf-reader.cc (read_debug_info_into_corpus): Do not set corpus symbol maps anymore. * src/abg-reader.cc (read_corpus_from_input): Likewise. * tests/test-symtab.cc (assert_symbol_count): Do not access the corpus symbol maps through sptr anymore. * tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Adjust expected test output. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- include/abg-corpus.h | 24 --- src/abg-corpus-priv.h | 21 ++- src/abg-corpus.cc | 139 +++++++----------- src/abg-dwarf-reader.cc | 45 ------ src/abg-reader.cc | 11 -- .../data/test-read-dwarf/PR25007-sdhci.ko.abi | 2 - tests/test-symtab.cc | 15 +- 7 files changed, 79 insertions(+), 178 deletions(-) diff --git a/include/abg-corpus.h b/include/abg-corpus.h index 425702182056..09f057d705f7 100644 --- a/include/abg-corpus.h +++ b/include/abg-corpus.h @@ -158,27 +158,9 @@ public: const symtab_reader::symtab_sptr& get_symtab() const; - void - set_fun_symbol_map(string_elf_symbols_map_sptr); - - void - set_undefined_fun_symbol_map(string_elf_symbols_map_sptr); - - void - set_var_symbol_map(string_elf_symbols_map_sptr); - - void - set_undefined_var_symbol_map(string_elf_symbols_map_sptr); - - const string_elf_symbols_map_sptr - get_fun_symbol_map_sptr() const; - virtual const string_elf_symbols_map_type& get_fun_symbol_map() const; - const string_elf_symbols_map_sptr - get_undefined_fun_symbol_map_sptr() const; - const string_elf_symbols_map_type& get_undefined_fun_symbol_map() const; @@ -188,15 +170,9 @@ public: const elf_symbols& get_sorted_undefined_fun_symbols() const; - const string_elf_symbols_map_sptr - get_var_symbol_map_sptr() const; - virtual const string_elf_symbols_map_type& get_var_symbol_map() const; - const string_elf_symbols_map_sptr - get_undefined_var_symbol_map_sptr() const; - const string_elf_symbols_map_type& get_undefined_var_symbol_map() const; diff --git a/src/abg-corpus-priv.h b/src/abg-corpus-priv.h index c8bf7f9d4cf6..27a6524c8b42 100644 --- a/src/abg-corpus-priv.h +++ b/src/abg-corpus-priv.h @@ -15,6 +15,7 @@ #define __ABG_CORPUS_PRIV_H__ #include "abg-internal.h" +#include "abg-ir.h" #include "abg-regex.h" #include "abg-sptr-utils.h" #include "abg-symtab-reader.h" @@ -681,11 +682,7 @@ struct corpus::priv string_tu_map_type path_tu_map; vector fns; vector vars; - string_elf_symbols_map_sptr var_symbol_map; - string_elf_symbols_map_sptr undefined_var_symbol_map; symtab_reader::symtab_sptr symtab_; - string_elf_symbols_map_sptr fun_symbol_map; - string_elf_symbols_map_sptr undefined_fun_symbol_map; // The type maps contained in this data member are populated if the // corpus follows the One Definition Rule and thus if there is only // one copy of a type with a given name, per corpus. Otherwise, if @@ -706,10 +703,14 @@ private: priv(); mutable abg_compat::optional sorted_var_symbols; + mutable abg_compat::optional var_symbol_map; mutable abg_compat::optional sorted_undefined_var_symbols; + mutable abg_compat::optional undefined_var_symbol_map; mutable abg_compat::optional unrefed_var_symbols; mutable abg_compat::optional sorted_fun_symbols; + mutable abg_compat::optional fun_symbol_map; mutable abg_compat::optional sorted_undefined_fun_symbols; + mutable abg_compat::optional undefined_fun_symbol_map; mutable abg_compat::optional unrefed_fun_symbols; public: @@ -731,18 +732,30 @@ public: const elf_symbols& get_sorted_fun_symbols() const; + const string_elf_symbols_map_type& + get_fun_symbol_map() const; + const elf_symbols& get_sorted_undefined_fun_symbols() const; + const string_elf_symbols_map_type& + get_undefined_fun_symbol_map() const; + const elf_symbols& get_unreferenced_function_symbols() const; const elf_symbols& get_sorted_var_symbols() const; + const string_elf_symbols_map_type& + get_var_symbol_map() const; + const elf_symbols& get_sorted_undefined_var_symbols() const; + const string_elf_symbols_map_type& + get_undefined_var_symbol_map() const; + const elf_symbols& get_unreferenced_variable_symbols() const; diff --git a/src/abg-corpus.cc b/src/abg-corpus.cc index f9f51a360707..94615bc727ff 100644 --- a/src/abg-corpus.cc +++ b/src/abg-corpus.cc @@ -331,6 +331,18 @@ corpus::priv::get_sorted_fun_symbols() const return *sorted_fun_symbols; } +const string_elf_symbols_map_type& +corpus::priv::get_fun_symbol_map() const +{ + if (!fun_symbol_map) + { + fun_symbol_map = string_elf_symbols_map_type(); + for (const auto& symbol : get_sorted_fun_symbols()) + (*fun_symbol_map)[symbol->get_name()].push_back(symbol); + } + return *fun_symbol_map; +} + /// Getter for a sorted vector of the function symbols undefined in /// this corpus. /// @@ -352,6 +364,18 @@ corpus::priv::get_sorted_undefined_fun_symbols() const return *sorted_undefined_fun_symbols; } +const string_elf_symbols_map_type& +corpus::priv::get_undefined_fun_symbol_map() const +{ + if (!undefined_fun_symbol_map) + { + undefined_fun_symbol_map = string_elf_symbols_map_type(); + for (const auto& symbol : get_sorted_undefined_fun_symbols()) + (*undefined_fun_symbol_map)[symbol->get_name()].push_back(symbol); + } + return *undefined_fun_symbol_map; +} + /// Return a list of symbols that are not referenced by any function of /// corpus::get_functions(). /// @@ -425,6 +449,18 @@ corpus::priv::get_sorted_var_symbols() const return *sorted_var_symbols; } +const string_elf_symbols_map_type& +corpus::priv::get_var_symbol_map() const +{ + if (!var_symbol_map) + { + var_symbol_map = string_elf_symbols_map_type(); + for (const auto& symbol : get_sorted_var_symbols()) + (*var_symbol_map)[symbol->get_name()].push_back(symbol); + } + return *var_symbol_map; +} + /// Getter for a sorted vector of the variable symbols undefined in /// this corpus. /// @@ -446,6 +482,18 @@ corpus::priv::get_sorted_undefined_var_symbols() const return *sorted_undefined_var_symbols; } +const string_elf_symbols_map_type& +corpus::priv::get_undefined_var_symbol_map() const +{ + if (!undefined_var_symbol_map) + { + undefined_var_symbol_map = string_elf_symbols_map_type(); + for (const auto& symbol : get_sorted_undefined_var_symbols()) + (*undefined_var_symbol_map)[symbol->get_name()].push_back(symbol); + } + return *undefined_var_symbol_map; +} + /// Return a list of symbols that are not referenced by any variable of /// corpus::get_variables(). /// @@ -883,10 +931,7 @@ corpus::is_empty() const } } return (members_empty - && priv_->fun_symbol_map - && priv_->fun_symbol_map->empty() - && priv_->var_symbol_map - && priv_->var_symbol_map->empty() + && !get_symtab()->has_symbols() && priv_->soname.empty() && priv_->needed.empty()); } @@ -920,69 +965,12 @@ 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. -void -corpus::set_fun_symbol_map(string_elf_symbols_map_sptr map) -{priv_->fun_symbol_map = map;} - -/// Setter for the map of function symbols that are undefined in this -/// corpus. -/// -/// @param map a new map for function symbols not defined in this -/// corpus. The key of the map is the name of the function symbol. -/// The value is a vector of all the function symbols that have the -/// same name. -void -corpus::set_undefined_fun_symbol_map(string_elf_symbols_map_sptr map) -{priv_->undefined_fun_symbol_map = map;} - -/// Setter of the variable symbols map. -/// -/// @param map a shared pointer to the new variable symbols map. -void -corpus::set_var_symbol_map(string_elf_symbols_map_sptr map) -{priv_->var_symbol_map = map;} - -/// Setter for the map of variable symbols that are undefined in this -/// corpus. -/// -/// @param map a new map for variable symbols not defined in this -/// corpus. The key of the map is the name of the variable symbol. -/// The value is a vector of all the variable symbols that have the -/// same name. -void -corpus::set_undefined_var_symbol_map(string_elf_symbols_map_sptr map) -{priv_->undefined_var_symbol_map = map;} - -/// Getter for the function symbols map. -/// -/// @return a shared pointer to the function symbols map. -const string_elf_symbols_map_sptr -corpus::get_fun_symbol_map_sptr() const -{ - if (!priv_->fun_symbol_map) - priv_->fun_symbol_map.reset(new string_elf_symbols_map_type); - return priv_->fun_symbol_map; -} - /// Getter for the function symbols map. /// /// @return a reference to the function symbols map. const string_elf_symbols_map_type& corpus::get_fun_symbol_map() const -{return *get_fun_symbol_map_sptr();} - -/// Getter for the map of function symbols that are undefined in this -/// corpus. -/// -/// @return the map of function symbols not defined in this corpus. -/// The key of the map is the name of the function symbol. The value -/// is a vector of all the function symbols that have the same name. -const string_elf_symbols_map_sptr -corpus::get_undefined_fun_symbol_map_sptr() const -{return priv_->undefined_fun_symbol_map;} +{return priv_->get_fun_symbol_map();} /// Getter for the map of function symbols that are undefined in this /// corpus. @@ -992,7 +980,7 @@ corpus::get_undefined_fun_symbol_map_sptr() const /// is a vector of all the function symbols that have the same name. const string_elf_symbols_map_type& corpus::get_undefined_fun_symbol_map() const -{return *get_undefined_fun_symbol_map_sptr();} +{return priv_->get_undefined_fun_symbol_map();} const elf_symbols& corpus::get_sorted_fun_symbols() const @@ -1010,33 +998,12 @@ const elf_symbols& corpus::get_sorted_undefined_var_symbols() const { return priv_->get_sorted_undefined_var_symbols(); } -/// Getter for the variable symbols map. -/// -/// @return a shared pointer to the variable symbols map. -const string_elf_symbols_map_sptr -corpus::get_var_symbol_map_sptr() const -{ - if (!priv_->var_symbol_map) - priv_->var_symbol_map.reset(new string_elf_symbols_map_type); - return priv_->var_symbol_map; -} - /// Getter for the variable symbols map. /// /// @return a reference to the variabl symbols map. const string_elf_symbols_map_type& corpus::get_var_symbol_map() const -{return *get_var_symbol_map_sptr();} - -/// Getter for the map of variable symbols that are undefined in this -/// corpus. -/// -/// @return the map of variable symbols not defined in this corpus. -/// The key of the map is the name of the variable symbol. The value -/// is a vector of all the variable symbols that have the same name. -const string_elf_symbols_map_sptr -corpus::get_undefined_var_symbol_map_sptr() const -{return priv_->undefined_var_symbol_map;} +{return priv_->get_var_symbol_map();} /// Getter for the map of variable symbols that are undefined in this /// corpus. @@ -1046,7 +1013,7 @@ corpus::get_undefined_var_symbol_map_sptr() const /// is a vector of all the variable symbols that have the same name. const string_elf_symbols_map_type& corpus::get_undefined_var_symbol_map() const -{return *get_undefined_var_symbol_map_sptr();} +{return priv_->get_undefined_var_symbol_map();} /// Look in the function symbols map for a symbol with a given name. /// diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index b2a7144afe9d..6d4e8ae23c53 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -14661,51 +14661,6 @@ read_debug_info_into_corpus(read_context& ctxt) // 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() - && is_linux_kernel(ctxt.elf_handle())) - { - string_elf_symbols_map_sptr exported_fn_symbols_map - (new string_elf_symbols_map_type); - auto filter = ctxt.symtab()->make_filter(); - filter.set_functions(); - - for (const auto& symbol : - symtab_reader::filtered_symtab(*ctxt.symtab(), filter)) - { - (*exported_fn_symbols_map)[symbol->get_name()].push_back(symbol); - } - - ctxt.current_corpus()->set_fun_symbol_map(exported_fn_symbols_map); - - string_elf_symbols_map_sptr exported_var_symbols_map( - new string_elf_symbols_map_type); - filter = ctxt.symtab()->make_filter(); - filter.set_variables(); - for (const auto& symbol : - symtab_reader::filtered_symtab(*ctxt.symtab(), filter)) - { - (*exported_var_symbols_map)[symbol->get_name()].push_back(symbol); - } - ctxt.current_corpus()->set_var_symbol_map(exported_var_symbols_map); - } - else - { - ctxt.current_corpus()->set_fun_symbol_map(ctxt.fun_syms_sptr()); - ctxt.current_corpus()->set_var_symbol_map(ctxt.var_syms_sptr()); - } - - ctxt.current_corpus()->set_undefined_fun_symbol_map - (ctxt.undefined_fun_syms_sptr()); - ctxt.current_corpus()->set_undefined_var_symbol_map - (ctxt.undefined_var_syms_sptr()); - } - else - { - ctxt.current_corpus()->set_fun_symbol_map(ctxt.fun_syms_sptr()); - ctxt.current_corpus()->set_var_symbol_map(ctxt.var_syms_sptr()); - } // Get out now if no debug info is found. if (!ctxt.dwarf()) diff --git a/src/abg-reader.cc b/src/abg-reader.cc index c26689ae17ca..296e1e2115d1 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -1908,17 +1908,6 @@ read_corpus_from_input(read_context& ctxt) // 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); - fn_sym_db.reset(); - } - if (var_sym_db) - { - corp.set_var_symbol_map(var_sym_db); - var_sym_db.reset(); - } } ctxt.get_environment()->canonicalization_is_done(false); diff --git a/tests/data/test-read-dwarf/PR25007-sdhci.ko.abi b/tests/data/test-read-dwarf/PR25007-sdhci.ko.abi index 1167e5aa478a..4c9a766f1c7c 100644 --- a/tests/data/test-read-dwarf/PR25007-sdhci.ko.abi +++ b/tests/data/test-read-dwarf/PR25007-sdhci.ko.abi @@ -37,8 +37,6 @@ - - diff --git a/tests/test-symtab.cc b/tests/test-symtab.cc index ff467d8ad345..2df766de1c5c 100644 --- a/tests/test-symtab.cc +++ b/tests/test-symtab.cc @@ -89,17 +89,19 @@ assert_symbol_count(const std::string& path, REQUIRE((status & dwarf_reader::STATUS_OK)); const corpus& corpus = *corpus_ptr; + size_t total_symbols = 0; + if (function_symbols != N) { CHECK(corpus.get_sorted_fun_symbols().size() == function_symbols); CHECK(corpus.get_fun_symbol_map().size() == function_symbols); - CHECK(corpus.get_fun_symbol_map_sptr()->size() == function_symbols); + total_symbols += function_symbols; } if (variable_symbols != N) { CHECK(corpus.get_sorted_var_symbols().size() == variable_symbols); CHECK(corpus.get_var_symbol_map().size() == variable_symbols); - CHECK(corpus.get_var_symbol_map_sptr()->size() == variable_symbols); + total_symbols += variable_symbols; } if (undefined_variable_symbols != N) { @@ -107,8 +109,7 @@ assert_symbol_count(const std::string& path, == undefined_function_symbols); CHECK(corpus.get_undefined_fun_symbol_map().size() == undefined_function_symbols); - CHECK(corpus.get_undefined_fun_symbol_map_sptr()->size() - == undefined_function_symbols); + total_symbols += undefined_function_symbols; } if (undefined_function_symbols != N) { @@ -116,10 +117,12 @@ assert_symbol_count(const std::string& path, == undefined_variable_symbols); CHECK(corpus.get_undefined_var_symbol_map().size() == undefined_variable_symbols); - CHECK(corpus.get_undefined_var_symbol_map_sptr()->size() - == undefined_variable_symbols); + total_symbols += undefined_variable_symbols; } + // assert the corpus reports being empty consistently with the symbol count + CHECK(corpus.is_empty() == (total_symbols == 0)); + return corpus_ptr; } From patchwork Wed Jan 27 12:58:48 2021 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: 41849 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 1E989397303B; Wed, 27 Jan 2021 12:59:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E989397303B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752385; bh=mSOfuSB+cMfD+WsDnzY7Ou1pU0ypNDQuUIauBM0bb6M=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=nmFBpvVPO9OYyzqqdo/CAX9aQcPbZZ8pRMsf3naitQOqrwN4ryIxMPaNRmBG79Xru K7dN0DI9v8EvIvmcO3jgwUM5IvA076oPmona90M3gN2m9Z1UEUAtK07FbFtPr8xgPD BnYWzLkX83SYvZ4XJrFM6S/nB6AEdw2kRvuaKrs4= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by sourceware.org (Postfix) with ESMTPS id 7860439730F8 for ; Wed, 27 Jan 2021 12:59:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7860439730F8 Received: by mail-qk1-x74a.google.com with SMTP id s66so1373009qkh.10 for ; Wed, 27 Jan 2021 04:59:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=mSOfuSB+cMfD+WsDnzY7Ou1pU0ypNDQuUIauBM0bb6M=; b=DgOXWBRROKdezxNv4Qpj1pkwtk/JrYg/MrIG71svvDBaYV3qzDyJ2u9wV3xVipzwdB G+mUDISFT896nTEMIAnKHhyYUhz5qHLbV5GmjtYI5iLAUGldRgph4JhOHr3AsTyjTzU/ hhNUX/GFTOKZUWr71oqrIIxOaINlYeP1+R3Rf+6/k3T1rkA9wDx1LOJ1Zi87qyxOkVLY DEzf5RZsYe0jopaAE1VokNs+ehb0lmGhUlQZuqJQ4uI1JGoJQrt0qX6tc6qOOyJkMdhD 3CaGE3grSbENKnD8olhH10hcOb235BIRx0nh/Xx27OR2MO59i6CPTAPdE7TSa0kpStUZ 105w== X-Gm-Message-State: AOAM533ExMDRDh2SGJJLlGGRQhOFrVWMfJq4LmEqzIWIX5EhLgYGs2nj 3lBDv5uoQCKTqh7X7gCZ3LUSYyv8NmYOD060UHt3bSC2faaML67jDtuztJvvHqLr/CxxlW+/Ve/ jHqJxpc641nBG/iVD/qlP9A8UP9mCdzuEe5M1x8j/VqTKoyb29lXqYZHSnKluOxuDkl/baY8= X-Google-Smtp-Source: ABdhPJzpeAUo3syRDxu6YUmIw1HQXi3Kg11p6gSumBTrvIYm9U359eBFwn+PhmvyphTp0kwwQqqJkMY51rJRng== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:ad4:576a:: with SMTP id r10mr9774619qvx.29.1611752379958; Wed, 27 Jan 2021 04:59:39 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:48 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-16-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 15/20] dwarf reader: drop (now) unused code related to symbol table reading To: libabigail@sourceware.org X-Spam-Status: No, score=-22.0 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, 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" The introduction of the new symtab reader incorporated much of the existing functionality. Now that the most code parts are migrated to the new symtab reader, we can safely remove the old code paths. Ignoring the symbol table is not a thing anymore. The new symtab reader does read the symtab unconditionally for consistency reasons. Hence also remove all functionality around conditional symtab reading. * include/abg-dwarf-reader.h (set_ignore_symbol_table): Remove. (get_ignore_symbol_table): Likewise. * src/abg-dwarf-reader.cc (add_symbol_to_map): Likewise. (read_context::options_type::ignore_symbol_table): Likewise. (read_context::options_type): Adjust. (read_context::fun_addr_sym_map_): Remove. (read_context::fun_entry_addr_sym_map_): Likewise. (read_context::fun_syms_): Likewise. (read_context::var_addr_sym_map_): Likewise. (read_context::var_syms_): Likewise. (read_context::undefined_fun_syms_): Likewise. (read_context::undefined_var_syms_): Likewise. (read_context::initialize): Adjust. (read_context::lookup_elf_symbol_from_index): Remove. (read_context::fun_entry_addr_sym_map_sptr): Likewise. (read_context::fun_entry_addr_sym_map): Likewise. (read_context::fun_syms_sptr): Likewise. (read_context::fun_syms): Likewise. (read_context::var_syms_sptr): Likewise. (read_context::var_syms): Likewise. (read_context::undefined_fun_syms_sptr): Likewise. (read_context::undefined_var_syms_sptr): Likewise. (read_context::load_symbol_maps_from_symtab_section): Likewise. (read_context::load_symbol_maps): Likewise. (read_context::maybe_load_symbol_maps): Likewise. (set_ignore_symbol_table): Likewise. (get_ignore_symbol_table): Likewise. (create_default_var_sym): Likewise. (build_var_decl): Adjust. (function_is_suppressed): Likewise. (variable_is_suppressed): Likewise. (build_function_decl): Likewise. (add_symbol_to_map): Remove. (read_corpus_from_elf): Adjust. (build_corpus_group_from_kernel_dist_under): Likewise. * tools/abidw.cc (main): Likewise. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- include/abg-dwarf-reader.h | 6 - src/abg-dwarf-reader.cc | 742 +------------------------------------ src/abg-tools-utils.cc | 13 - tools/abidw.cc | 2 - 4 files changed, 12 insertions(+), 751 deletions(-) diff --git a/include/abg-dwarf-reader.h b/include/abg-dwarf-reader.h index c80956ac7ac0..a328fb0e741b 100644 --- a/include/abg-dwarf-reader.h +++ b/include/abg-dwarf-reader.h @@ -180,12 +180,6 @@ set_drop_undefined_syms(read_context& ctxt, void set_do_log(read_context& ctxt, bool f); -void -set_ignore_symbol_table(read_context &ctxt, bool f); - -bool -get_ignore_symbol_table(const read_context &ctxt); - void set_environment(read_context& ctxt, ir::environment*); diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 6d4e8ae23c53..91451208ef11 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -282,10 +282,6 @@ static bool operator<(const imported_unit_point& l, const imported_unit_point& r) {return l.offset_of_import < r.offset_of_import;} -static void -add_symbol_to_map(const elf_symbol_sptr& sym, - string_elf_symbols_map_type& map); - static bool get_parent_die(const read_context& ctxt, const Dwarf_Die* die, @@ -1902,92 +1898,6 @@ struct dwarf_expr_eval_context // // --------------------------------------- -/// An enum for the diffent kinds of linux kernel specific symbol -/// tables. -enum kernel_symbol_table_kind -{ - /// This is for an undefined kind of kernel symbol table. - KERNEL_SYMBOL_TABLE_KIND_UNDEFINED, - - /// The __ksymtab symbol table. - KERNEL_SYMBOL_TABLE_KIND_KSYMTAB, - - /// The __ksymtab_gpl symbol table. - KERNEL_SYMBOL_TABLE_KIND_KSYMTAB_GPL -}; - -/// An enum which specifies the format of the kernel symbol table -/// (__ksymtab or __ksymtab_gpl). -enum ksymtab_format -{ - /// This enumerator means that no __ksymtab format has been - /// determined yet. - UNDEFINED_KSYMTAB_FORMAT, - - /// Before Linux v4.19, the format of the __ksymtab (and the - /// __ksymtab_gpl) section was the following. - /// - /// It's an array of entries. Each entry describes a symbol. Each - /// entry is made of two words. each is of the word size of the - /// architecture. (8-bytes on a 64 bits arch and 4-bytes on a 32 - /// bits arch) The first word is the address of a symbol. The - /// second one is the address of a static global variable symbol - /// which value is the string representing the symbol name. That - /// string is in the __ksymtab_strings section. - /// - /// So we are mostly interested in the symbol address part of each - /// entry. - /// - /// Thus this enumerator means that we have the pre v4.19 __ksymtab - /// section format. - PRE_V4_19_KSYMTAB_FORMAT, - - /// Since, Linux v4.19, the format of the __ksymtab section has - /// changed. The commit that changed is - /// https://github.com/torvalds/linux/commit/7290d58095712a89f845e1bca05334796dd49ed2. - /// - /// The __ksymtab and __ksymtab_gpl sections each are an array of - /// entries. Each entry describes a symbol. Each entry is made of - /// two words. Each word is 4-bytes length. The first word is the - /// 'place-relative' address of a symbol. The second one is the - /// 'place-relative' address of a static global variable symbol - /// which value is the string representing the symbol name. That - /// string is in the __ksymtab_strings section. - /// - /// Below is the description of what a "place-relative address" - /// means. For that, we are going to define the meaning of four - /// values: 'N', 'S', 'O', and 'A'. - /// - /// *** 'N' and '0' *** - /// Suppose 'N' is the value of the number stored at offset 'O' (big - /// oh, not zero) in the __ksymtab section. - /// - /// *** 'S'*** - /// That N designates a symbol in the symtab section which value is - /// S. So S is the symbol value (in the .symtab symbol table) - /// referred to by the number N found at offset 'O'. - /// - /// *** 'A' *** - /// Also, suppose the __ksymtab section will be loaded at memory - /// address A, as indicated by the 'address' field of the section - /// header describing the __ksymtab section. - /// - /// So here is the formula that gives us S, from N: - /// - /// S = N + O + A. - /// - /// Storing addresses this way does away with the need to have - /// relocations for the __ksymtab section. So in effect, vmlinux - /// binaries implementing this new format of __ksymtab won't have - /// any .rela__ksymtab relocation section for the __ksymtab section - /// in particular (nor any relocation section at all). - /// - /// - /// Note that we are mostly interested in the symbol address part of - /// each entry. - V4_19_KSYMTAB_FORMAT -}; // end enum ksymtab_format - /// The context used to build ABI corpus from debug info in DWARF /// format. /// @@ -2006,7 +1916,6 @@ public: environment* env; bool load_in_linux_kernel_mode; bool load_all_types; - bool ignore_symbol_table; bool show_stats; bool do_log; @@ -2014,7 +1923,6 @@ public: : env(), load_in_linux_kernel_mode(), load_all_types(), - ignore_symbol_table(), show_stats(), do_log() {} @@ -2211,19 +2119,6 @@ public: offset_offset_map_type alternate_die_parent_map_; offset_offset_map_type type_section_die_parent_map_; list var_decls_to_add_; - addr_elf_symbol_sptr_map_sptr fun_addr_sym_map_; - // On PPC64, the function entry point address is different from the - // GElf_Sym::st_value value, which is the address of the descriptor - // of the function. The map below thus associates the address of - // the entry point to the function symbol. If we are not on ppc64, - // then this map ought to be empty. Only the fun_addr_sym_map_ is - // used in that case. On ppc64, though, both maps are used. - addr_elf_symbol_sptr_map_sptr fun_entry_addr_sym_map_; - string_elf_symbols_map_sptr fun_syms_; - addr_elf_symbol_sptr_map_sptr var_addr_sym_map_; - string_elf_symbols_map_sptr var_syms_; - string_elf_symbols_map_sptr undefined_fun_syms_; - string_elf_symbols_map_sptr undefined_var_syms_; vector dt_needed_; string dt_soname_; string elf_architecture_; @@ -2359,13 +2254,6 @@ public: alternate_die_parent_map_.clear(); type_section_die_parent_map_.clear(); var_decls_to_add_.clear(); - fun_addr_sym_map_.reset(); - fun_entry_addr_sym_map_.reset(); - fun_syms_.reset(); - var_addr_sym_map_.reset(); - var_syms_.reset(); - undefined_fun_syms_.reset(); - undefined_var_syms_.reset(); dt_needed_.clear(); dt_soname_.clear(); elf_architecture_.clear(); @@ -5336,88 +5224,6 @@ public: return true; } - /// Given the index of a symbol into the symbol table of an ELF - /// file, look the symbol up, build an instace of @ref elf_symbol - /// and return it. - /// - /// @param symbol_index the index of the symbol into the symbol - /// table of the current elf file. - /// - /// @return the elf symbol found or nil if none was found. - elf_symbol_sptr - lookup_elf_symbol_from_index(size_t symbol_index) - { - GElf_Sym s; - elf_symbol_sptr result = - lookup_elf_symbol_from_index(symbol_index, s); - return result; - } - - /// Lookup an ELF symbol given its index into the .symtab section. - /// - /// This function returns both the native symbol (from libelf) and - /// the @p abigail::ir::elf_symbol instance, which is the - /// libabigail-specific representation of the symbol. - /// - /// @param symbol_index the index of the symbol to look for. - /// - /// @param native_sym output parameter. This is set to the native - /// ELF symbol found iff the function returns a non-nil value. - /// - /// @return an instance of libabigail::ir::elf_symbol representing - /// the ELF symbol found, iff one was found. Otherwise, returns - /// nil. - elf_symbol_sptr - lookup_elf_symbol_from_index(size_t symbol_index, - GElf_Sym &native_sym) - { - if (!lookup_native_elf_symbol_from_index(symbol_index, native_sym)) - return elf_symbol_sptr(); - - Elf_Scn* symtab_section = find_symbol_table_section(); - if (!symtab_section) - return elf_symbol_sptr(); - - GElf_Shdr header_mem; - GElf_Shdr* symtab_sheader = gelf_getshdr(symtab_section, - &header_mem); - - Elf_Data* symtab = elf_getdata(symtab_section, 0); - ABG_ASSERT(symtab); - - bool sym_is_defined = native_sym.st_shndx != SHN_UNDEF; - bool sym_is_common = native_sym.st_shndx == SHN_COMMON; // this occurs in - // relocatable - // files. - const char* name_str = elf_strptr(elf_handle(), - symtab_sheader->sh_link, - native_sym.st_name); - if (name_str == 0) - name_str = ""; - - elf_symbol::version ver; - elf_helpers::get_version_for_symbol(elf_handle(), symbol_index, - sym_is_defined, ver); - - elf_symbol::visibility vis = - stv_to_elf_symbol_visibility(GELF_ST_VISIBILITY(native_sym.st_other)); - - Elf_Scn* strings_section = find_ksymtab_strings_section(elf_handle()); - size_t strings_ndx = strings_section - ? elf_ndxscn(strings_section) - : 0; - - elf_symbol_sptr sym = - elf_symbol::create(env(), symbol_index, native_sym.st_size, - name_str, stt_to_elf_symbol_type - (GELF_ST_TYPE(native_sym.st_info)), - stb_to_elf_symbol_binding - (GELF_ST_BIND(native_sym.st_info)), - sym_is_defined, sym_is_common, ver, vis, - native_sym.st_shndx == strings_ndx); - return sym; - } - /// Test if a given function symbol has been exported. /// /// @param symbol_address the address of the symbol we are looking @@ -5497,102 +5303,6 @@ public: 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. - /// - /// Note that on non-"PPC64 ELFv1" binaries, this map is the same as - /// the one that assciates the address of a function with the symbol - /// of that function. - /// - /// @return a pointer to the map that associates the address of an - /// entry point of a function with the symbol of that function. - addr_elf_symbol_sptr_map_sptr& - fun_entry_addr_sym_map_sptr() - { - if (!fun_entry_addr_sym_map_ && !fun_addr_sym_map_) - maybe_load_symbol_maps(); - if (architecture_is_ppc64(elf_handle())) - return fun_entry_addr_sym_map_; - return fun_addr_sym_map_; - } - - /// Getter for the map that associates the address of an entry point - /// of a function with the symbol of that function. - /// - /// Note that on non-"PPC64 ELFv1" binaries, this map is the same as - /// the one that assciates the address of a function with the symbol - /// of that function. - /// - /// @return the map that associates the address of an entry point of - /// a function with the symbol of that function. - addr_elf_symbol_sptr_map_type& - fun_entry_addr_sym_map() - {return *fun_entry_addr_sym_map_sptr();} - - /// Getter for the map of function symbols (name -> sym). - /// - /// @return a shared pointer to the map of function symbols. - const string_elf_symbols_map_sptr& - fun_syms_sptr() const - { - maybe_load_symbol_maps(); - return fun_syms_; - } - - /// Getter for the map of function symbols (name -> sym). - /// - /// @return a reference to the map of function symbols. - string_elf_symbols_map_type& - fun_syms() - { - maybe_load_symbol_maps(); - return *fun_syms_; - } - - /// Getter for the map of variable symbols (name -> sym) - /// - /// @return a shared pointer to the map of variable symbols. - const string_elf_symbols_map_sptr - var_syms_sptr() const - { - maybe_load_symbol_maps(); - return var_syms_; - } - - /// Getter for the map of variable symbols (name -> sym) - /// - /// @return a reference to the map of variable symbols. - string_elf_symbols_map_type& - var_syms() - { - maybe_load_symbol_maps(); - return *var_syms_; - } - - /// Getter for the map of undefined function symbols (name -> vector - /// of symbols). - /// - /// @return a (smart) pointer to the map of undefined function - /// symbols. - const string_elf_symbols_map_sptr& - undefined_fun_syms_sptr() const - { - maybe_load_symbol_maps(); - return undefined_fun_syms_; - } - - /// Getter for the map of undefined variable symbols (name -> vector - /// of symbols). - /// - /// @return a (smart) pointer to the map of undefined variable - /// symbols. - const string_elf_symbols_map_sptr& - undefined_var_syms_sptr() const - { - maybe_load_symbol_maps(); - return undefined_var_syms_; - } - /// Getter for the ELF dt_needed tag. const vector& dt_needed() const @@ -5608,232 +5318,6 @@ public: elf_architecture() const {return elf_architecture_;} - /// Load the maps address -> function symbol, address -> variable - /// symbol and the maps of function and variable undefined symbols. - /// - /// @param load_fun_map whether to load the address to function map. - /// - /// @param load_var_map whether to laod the address to variable map. - /// - /// @param load_undefined_fun_map whether to load the undefined - /// function map. - /// - /// @param load_undefined_var_map whether to laod the undefined - /// variable map. - /// - /// @return return true iff the maps have be loaded. - bool - load_symbol_maps_from_symtab_section(bool load_fun_map, - bool load_var_map, - bool load_undefined_fun_map, - bool load_undefined_var_map) - { - Elf_Scn* symtab_section = find_symbol_table_section(); - if (!symtab_section) - return false; - - GElf_Shdr header_mem; - GElf_Shdr* symtab_sheader = gelf_getshdr(symtab_section, - &header_mem); - - // check for bogus section header - if (symtab_sheader->sh_entsize == 0) - return false; - - size_t nb_syms = symtab_sheader->sh_size / symtab_sheader->sh_entsize; - - Elf_Data* symtab = elf_getdata(symtab_section, 0); - if (!symtab) - return false; - - GElf_Ehdr elf_header; - ABG_ASSERT(gelf_getehdr(elf_handle(), &elf_header)); - - bool is_ppc64 = architecture_is_ppc64(elf_handle()); - - for (size_t i = 0; i < nb_syms; ++i) - { - GElf_Sym* sym, sym_mem; - sym = gelf_getsym(symtab, i, &sym_mem); - ABG_ASSERT(sym); - - if ((load_fun_map || load_undefined_fun_map) - && (GELF_ST_TYPE(sym->st_info) == STT_FUNC - || GELF_ST_TYPE(sym->st_info) == STT_GNU_IFUNC)) - { - elf_symbol_sptr symbol = lookup_elf_symbol_from_index(i); - ABG_ASSERT(symbol); - ABG_ASSERT(symbol->is_function()); - - // If the symbol was suppressed by a suppression - // specification then drop it on the floor. - if (is_elf_symbol_suppressed(symbol)) - continue; - - if (load_fun_map && symbol->is_public()) - { - (*fun_syms_)[symbol->get_name()].push_back(symbol); - - { - GElf_Addr symbol_value = - maybe_adjust_et_rel_sym_addr_to_abs_addr(elf_handle(), - sym); - - addr_elf_symbol_sptr_map_type::const_iterator it = - fun_addr_sym_map_->find(symbol_value); - if (it == fun_addr_sym_map_->end()) - (*fun_addr_sym_map_)[symbol_value] = symbol; - else //if (sym->st_value != 0) - it->second->get_main_symbol()->add_alias(symbol); - - if (is_ppc64) - { - // For ppc64 ELFv1 binaries, we need to build a - // function entry point address -> function - // symbol map. This is in addition to the - // function pointer -> symbol map. This is - // because on ppc64 ELFv1, a function pointer is - // different from a function entry point - // address. - // - // On ppc64 ELFv1, the DWARF DIE of a function - // references the address of the entry point of - // the function symbol; whereas the value of the - // function symbol is the function pointer. As - // these addresses are different, if I we want - // to get to the symbol of a function from its - // entry point address (as referenced by DWARF - // function DIEs) we must have the two maps I - // mentionned right above. - // - // In other words, we need a map that associates - // a function enty point address with the symbol - // of that function, to be able to get the - // function symbol that corresponds to a given - // function DIE, on ppc64. - // - // The value of the function pointer (the value - // of the symbol) usually refers to the offset - // of a table in the .opd section. But - // sometimes, for a symbol named "foo", the - // corresponding symbol named ".foo" (note the - // dot before foo) which value is the entry - // point address of the function; that entry - // point address refers to a region in the .text - // section. - // - // So we are only interested in values of the - // symbol that are in the .opd section. - GElf_Addr fn_desc_addr = sym->st_value; - GElf_Addr fn_entry_point_addr = - lookup_ppc64_elf_fn_entry_point_address( - elf_handle(), fn_desc_addr); - addr_elf_symbol_sptr_map_type::const_iterator it2 = - fun_entry_addr_sym_map().find(fn_entry_point_addr); - - if (it2 == fun_entry_addr_sym_map().end()) - fun_entry_addr_sym_map()[fn_entry_point_addr] = symbol; - else if (address_is_in_opd_section(elf_handle(), - fn_desc_addr)) - { - // Either - // - // 'symbol' must have been registered as an - // alias for it2->second->get_main_symbol(), - // right before the "if (ppc64)" statement. - // - // Or - // - // if the name of 'symbol' is foo, then the - // name of it2->second is ".foo". That is, - // foo is the name of the symbol when it - // refers to the function descriptor in the - // .opd section and ".foo" is an internal - // name for the address of the entry point - // of foo. - // - // In the latter case, we just want to keep - // a refernce to "foo" as .foo is an - // internal name. - - bool two_symbols_alias = - it2->second->get_main_symbol()->does_alias(*symbol); - bool symbol_is_foo_and_prev_symbol_is_dot_foo = - (it2->second->get_name() - == string(".") + symbol->get_name()); - - ABG_ASSERT(two_symbols_alias - || symbol_is_foo_and_prev_symbol_is_dot_foo); - - if (symbol_is_foo_and_prev_symbol_is_dot_foo) - // Let's just keep a reference of the - // symbol that the user sees in the source - // code (the one named foo). The symbol - // which name is prefixed with a "dot" is - // an artificial one. - fun_entry_addr_sym_map()[fn_entry_point_addr] = symbol; - } - } - } - } - else if (load_undefined_fun_map && !symbol->is_defined()) - (*undefined_fun_syms_)[symbol->get_name()].push_back(symbol); - } - else if ((load_var_map || load_undefined_var_map) - && (GELF_ST_TYPE(sym->st_info) == STT_OBJECT - || GELF_ST_TYPE(sym->st_info) == STT_TLS) - // If the symbol is for an OBJECT, the index of the - // section it refers to cannot be absolute. - // Otherwise that OBJECT is not a variable. - && (sym->st_shndx != SHN_ABS - || GELF_ST_TYPE(sym->st_info) != STT_OBJECT )) - { - elf_symbol_sptr symbol = lookup_elf_symbol_from_index(i); - ABG_ASSERT(symbol); - ABG_ASSERT(symbol->is_variable()); - - if (load_var_map && symbol->is_public()) - { - (*var_syms_)[symbol->get_name()].push_back(symbol); - - if (symbol->is_common_symbol()) - { - string_elf_symbols_map_type::iterator it = - var_syms_->find(symbol->get_name()); - ABG_ASSERT(it != var_syms_->end()); - const elf_symbols& common_sym_instances = it->second; - ABG_ASSERT(!common_sym_instances.empty()); - if (common_sym_instances.size() > 1) - { - elf_symbol_sptr main_common_sym = - common_sym_instances[0]; - ABG_ASSERT(main_common_sym->get_name() - == symbol->get_name()); - ABG_ASSERT(main_common_sym->is_common_symbol()); - ABG_ASSERT(symbol.get() != main_common_sym.get()); - main_common_sym->add_common_instance(symbol); - } - } - else - { - GElf_Addr symbol_value = - maybe_adjust_et_rel_sym_addr_to_abs_addr(elf_handle(), - sym); - addr_elf_symbol_sptr_map_type::const_iterator it = - var_addr_sym_map_->find(symbol_value); - if (it == var_addr_sym_map_->end()) - (*var_addr_sym_map_)[symbol_value] = symbol; - else - it->second->get_main_symbol()->add_alias(symbol); - } - } - else if (load_undefined_var_map && !symbol->is_defined()) - (*undefined_var_syms_)[symbol->get_name()].push_back(symbol); - } - } - return true; - } - /// Test if a given ELF symbol was suppressed by a suppression /// specification. /// @@ -5849,71 +5333,6 @@ public: symbol->get_type())); } - /// Load the maps of function symbol address -> function symbol, - /// global variable symbol address -> variable symbol and also the - /// maps of function and variable undefined symbols. - /// - /// All these maps are loaded only if they are not loaded already. - /// - /// @return true iff everything went fine. - bool - load_symbol_maps() - { - bool load_fun_map = !fun_addr_sym_map_ ; - bool load_var_map = !var_addr_sym_map_; - bool load_undefined_fun_map = !undefined_fun_syms_; - bool load_undefined_var_map = !undefined_var_syms_; - - if (!fun_syms_) - fun_syms_.reset(new string_elf_symbols_map_type); - - if (!fun_addr_sym_map_) - fun_addr_sym_map_.reset(new addr_elf_symbol_sptr_map_type); - - if (!fun_entry_addr_sym_map_ && architecture_is_ppc64(elf_handle())) - fun_entry_addr_sym_map_.reset(new addr_elf_symbol_sptr_map_type); - - if (!var_syms_) - var_syms_.reset(new string_elf_symbols_map_type); - - if (!var_addr_sym_map_) - var_addr_sym_map_.reset(new addr_elf_symbol_sptr_map_type); - - if (!undefined_fun_syms_) - undefined_fun_syms_.reset(new string_elf_symbols_map_type); - - if (!undefined_var_syms_) - undefined_var_syms_.reset(new string_elf_symbols_map_type); - - if (!options_.ignore_symbol_table) - { - if (load_symbol_maps_from_symtab_section(load_fun_map, - load_var_map, - load_undefined_fun_map, - load_undefined_var_map)) - return true; - return false; - } - return true; - } - - /// Load the symbol maps if necessary. - /// - /// @return true iff the symbol maps has been loaded by this - /// invocation. - bool - maybe_load_symbol_maps() const - { - if (!fun_addr_sym_map_ - || !var_addr_sym_map_ - || !fun_syms_ - || !var_syms_ - || !undefined_fun_syms_ - || !undefined_var_syms_) - return const_cast(this)->load_symbol_maps(); - return false; - } - /// Load the DT_NEEDED and DT_SONAME elf TAGS. /// void @@ -6804,46 +6223,6 @@ void set_do_log(read_context& ctxt, bool f) {ctxt.do_log(f);} -/// Setter of the "set_ignore_symbol_table" flag. -/// -/// This flag tells if we should load information about ELF symbol -/// tables. Not loading the symbol tables is a speed optimization -/// that is done when the set of symbols we care about is provided -/// off-hand. This is the case when we are supposed to analyze a -/// Linux kernel binary. In that case, because we have the white list -/// of functions/variable symbols we care about, we don't need to -/// analyze the symbol table; things are thus faster in that case. -/// -/// By default, the symbol table is analyzed so this boolean is set to -/// false. -/// -/// @param ctxt the read context to consider. -/// -/// @param f the new value of the flag. -void -set_ignore_symbol_table(read_context &ctxt, bool f) -{ctxt.options_.ignore_symbol_table = f;} - -/// Getter of the "set_ignore_symbol_table" flag. -/// -/// This flag tells if we should load information about ELF symbol -/// tables. Not loading the symbol tables is a speed optimization -/// that is done when the set of symbols we care about is provided -/// off-hand. This is the case when we are supposed to analyze a -/// Linux kernel binary. In that case, because we have the white list -/// of functions/variable symbols we care about, we don't need to -/// analyze the symbol table; things are thus faster in that case. -/// -/// By default, the symbol table is analyzed so this boolean is set to -/// false. -/// -/// @param ctxt the read context to consider. -/// -/// @return the value of the flag. -bool -get_ignore_symbol_table(const read_context& ctxt) -{return ctxt.options_.ignore_symbol_table;} - /// Test if a given DIE is anonymous /// /// @param die the DIE to consider. @@ -13967,33 +13346,6 @@ build_or_get_var_decl_if_not_suppressed(read_context& ctxt, return var; } -/// Create a variable symbol with a given name. -/// -/// @param sym_name the name of the variable symbol. -/// -/// @param env the environment to create the default symbol in. -/// -/// @return the newly created symbol. -static elf_symbol_sptr -create_default_var_sym(const string& sym_name, const environment *env) -{ - elf_symbol::version ver; - elf_symbol::visibility vis = elf_symbol::DEFAULT_VISIBILITY; - elf_symbol_sptr result = - elf_symbol::create(env, - /*symbol index=*/ 0, - /*symbol size=*/ 0, - sym_name, - /*symbol type=*/ elf_symbol::OBJECT_TYPE, - /*symbol binding=*/ elf_symbol::GLOBAL_BINDING, - /*symbol is defined=*/ true, - /*symbol is common=*/ false, - /*symbol version=*/ ver, - /*symbol_visibility=*/vis, - /*is_linux_string_cst=*/false); - return result; -} - /// Build a @ref var_decl out of a DW_TAG_variable DIE. /// /// @param ctxt the read context to use. @@ -14065,23 +13417,9 @@ build_var_decl(read_context& ctxt, if (!result->get_symbol()) { elf_symbol_sptr var_sym; - if (get_ignore_symbol_table(ctxt)) - { - string var_name = - result->get_linkage_name().empty() - ? result->get_name() - : result->get_linkage_name(); - - var_sym = create_default_var_sym(var_name, ctxt.env()); - ABG_ASSERT(var_sym); - add_symbol_to_map(var_sym, ctxt.var_syms()); - } - else - { - Dwarf_Addr var_addr; - if (ctxt.get_variable_address(die, var_addr)) - var_sym = var_sym = ctxt.variable_symbol_is_exported(var_addr); - } + Dwarf_Addr var_addr; + if (ctxt.get_variable_address(die, var_addr)) + var_sym = var_sym = ctxt.variable_symbol_is_exported(var_addr); if (var_sym) { @@ -14145,15 +13483,9 @@ function_is_suppressed(const read_context& ctxt, Dwarf_Addr fn_addr; if (!ctxt.get_function_address(function_die, fn_addr)) return true; - if (!get_ignore_symbol_table(ctxt)) - { - // We were not instructed to ignore (avoid loading) the - // symbol table, so we can rely on its presence to see if - // the address corresponds to the address of an exported - // function symbol. - if (!ctxt.function_symbol_is_exported(fn_addr)) - return true; - } + + if (!ctxt.function_symbol_is_exported(fn_addr)) + return true; } return suppr::function_is_suppressed(ctxt, qualified_name, @@ -14260,15 +13592,9 @@ variable_is_suppressed(const read_context& ctxt, Dwarf_Addr var_addr = 0; if (!ctxt.get_variable_address(variable_die, var_addr)) return true; - if (!get_ignore_symbol_table(ctxt)) - { - // We were not instructed to ignore (avoid loading) the - // symbol table, so we can rely on its presence to see if - // the address corresponds to the address of an exported - // variable symbol. - if (!ctxt.variable_symbol_is_exported(var_addr)) - return true; - } + + if (!ctxt.variable_symbol_is_exported(var_addr)) + return true; } return suppr::variable_is_suppressed(ctxt, qualified_name, @@ -14556,23 +13882,9 @@ build_function_decl(read_context& ctxt, if (!result->get_symbol()) { elf_symbol_sptr fn_sym; - if (get_ignore_symbol_table(ctxt)) - { - string fn_name = - result->get_linkage_name().empty() - ? result->get_name() - : result->get_linkage_name(); - - fn_sym = create_default_fn_sym(fn_name, ctxt.env()); - ABG_ASSERT(fn_sym); - add_symbol_to_map(fn_sym, ctxt.fun_syms()); - } - else - { - Dwarf_Addr fn_addr; - if (ctxt.get_function_address(die, fn_addr)) - fn_sym = ctxt.function_symbol_is_exported(fn_addr); - } + Dwarf_Addr fn_addr; + if (ctxt.get_function_address(die, fn_addr)) + fn_sym = ctxt.function_symbol_is_exported(fn_addr); if (fn_sym && !ctxt.symbol_already_belongs_to_a_function(fn_sym)) { @@ -14602,29 +13914,6 @@ build_function_decl(read_context& ctxt, return result; } -/// Add a symbol to a symbol map. -/// -/// @param sym the symbol to add. -/// -/// @param map the symbol map to add the symbol into. -static void -add_symbol_to_map(const elf_symbol_sptr& sym, - string_elf_symbols_map_type& map) -{ - if (!sym) - return; - - string_elf_symbols_map_type::iterator it = map.find(sym->get_name()); - if (it == map.end()) - { - elf_symbols syms; - syms.push_back(sym); - map[sym->get_name()] = syms; - } - else - it->second.push_back(sym); -} - /// Read all @ref abigail::translation_unit possible from the debug info /// accessible through a DWARF Front End Library handle, and stuff /// them into a libabigail ABI Corpus. @@ -15946,13 +15235,6 @@ read_corpus_from_elf(read_context& ctxt, status& status) ctxt.load_elf_properties(); // DT_SONAME, DT_NEEDED, architecture - if (!get_ignore_symbol_table(ctxt)) - { - // Read the symbols for publicly defined decls - if (!ctxt.load_symbol_maps()) - status |= STATUS_NO_SYMBOLS_FOUND; - } - if (!ctxt.symtab() || !ctxt.symtab()->has_symbols()) status |= STATUS_NO_SYMBOLS_FOUND; diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc index 4d0191326dab..51043ece26dc 100644 --- a/src/abg-tools-utils.cc +++ b/src/abg-tools-utils.cc @@ -2573,12 +2573,6 @@ build_corpus_group_from_kernel_dist_under(const string& root, << t << "\n"; - // If we have been given a whitelist of functions and - // variable symbols to look at, then we can avoid loading - // and analyzing the ELF symbol table. - bool do_ignore_symbol_table = !kabi_wl_paths.empty(); - set_ignore_symbol_table(*ctxt, do_ignore_symbol_table); - group.reset(new corpus_group(env.get(), root)); set_read_context_corpus_group(*ctxt, group); @@ -2618,13 +2612,6 @@ build_corpus_group_from_kernel_dist_under(const string& root, /*read_all_types=*/false, /*linux_kernel_mode=*/true); - // If we have been given a whitelist of functions and - // variable symbols to look at, then we can avoid loading - // and analyzing the ELF symbol table. - bool do_ignore_symbol_table = !kabi_wl_paths.empty(); - - set_ignore_symbol_table(*ctxt, do_ignore_symbol_table); - load_generate_apply_suppressions(*ctxt, suppr_paths, kabi_wl_paths, supprs); diff --git a/tools/abidw.cc b/tools/abidw.cc index bf4de28324d0..22f640b4167b 100644 --- a/tools/abidw.cc +++ b/tools/abidw.cc @@ -814,8 +814,6 @@ main(int argc, char* argv[]) set_show_stats(ctxt, opts.show_stats); set_suppressions(ctxt, opts); abigail::dwarf_reader::set_do_log(ctxt, opts.do_log); - if (!opts.kabi_whitelist_supprs.empty()) - set_ignore_symbol_table(ctxt, true); if (opts.check_alt_debug_info_path) { From patchwork Wed Jan 27 12:58:49 2021 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: 41850 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 6DF72397282F; Wed, 27 Jan 2021 12:59:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6DF72397282F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752385; bh=btT+e2TOQQWb1voUq+eQgwED0vSTA8ORu5/sCBNbdDc=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=wPmF9dNLmKrctgrrENUHQ2z2IZBp9n04mNbkpXaPdSt4CE8a4EKyEJ33r1tg5Ctac xL5Pcee5n2OwYzRpp2g9Lmao6AoiJWMCdaCcDQVuDVceDX9i302JwQkeT6WFyG6is8 8nKT0eVgXKvZYw9zKzXDbvDJBKUvd9ZqRKLiIcvQ= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by sourceware.org (Postfix) with ESMTPS id A558339878E2 for ; Wed, 27 Jan 2021 12:59:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A558339878E2 Received: by mail-qt1-x849.google.com with SMTP id j14so1028094qtv.3 for ; Wed, 27 Jan 2021 04:59:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=btT+e2TOQQWb1voUq+eQgwED0vSTA8ORu5/sCBNbdDc=; b=SyXx8XqLoW833/B/7YnxfhifJpXSrb73THzp2mNcAz3k/zzJl+xSsgFcA+T3ALk9NG XtfJEp4UujVHHTQfO5Mjh9YGqeoS1P5WdYDNCazx/xm6rtEvYWGMGeewU7/gNNn9ndVe vC1psicqPj/k+dOmWsXQgh9QU3kaokbq2LCqPYlC2t7OlnP8k4LfMNqDf5uzYjeP5ec3 jmmfo27urEyuTIW5yqecCy8kVkvmEUPzDgvCfm2aZvKRMYQmuo/AyyxBh96pFMxZrjYs SRYLLbCz6GF8NJNFGGW4BRvdw3LEBYS2r789m2lqIGz7P0oc58bAqYwOFWAOreNRGMZ/ wQvw== X-Gm-Message-State: AOAM5330E2SnGk0E46+bxfRCHbtpfastdlHKRyAoq3mdBTEniNfnztzG e6dBSbk7wvOTV6VQAZcBGPgNp6Rm9qt23sb+WlZCwSqTE774xPJFuJSGcnxQ5xm0RFoTYmjGaST cYcZE66WAWUwunfEkDBGK/fq0i2093Sa8Q0B6g0/NoPrMZeqaEb2SYDrdStBNwNcKjhNAgOg= X-Google-Smtp-Source: ABdhPJxzy/OLe7YwTntJ++M4xk40sYUh5aduNgfyd1DzipsJFntojsEp3yzHlBvkqlxOxnTy2hM/X8enOZ8hXQ== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:a0c:c38e:: with SMTP id o14mr10324604qvi.29.1611752382236; Wed, 27 Jan 2021 04:59:42 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:49 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-17-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 16/20] test-symtab: add tests for whitelisted functions To: libabigail@sourceware.org X-Spam-Status: No, score=-22.1 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" Extend the test functionality in test-symtab to allow processing of KMI whitelists and add additional test cases for whitelist handling. * tests/data/Makefile.am: add new test files * tests/data/test-symtab/basic/one_function_one_variable_all.whitelist: New test file, * tests/data/test-symtab/basic/one_function_one_variable_function.whitelist: Likewise. * tests/data/test-symtab/basic/one_function_one_variable_irrelevant.whitelist: Likewise. * tests/data/test-symtab/basic/one_function_one_variable_variable.whitelist: Likewise. * tests/test-symtab.cc (read_corpus): Add support for whitelists. (assert_symbol_count): Likewise. (Symtab::SymtabWithWhitelist): New testcase. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- tests/data/Makefile.am | 4 + .../one_function_one_variable_all.whitelist | 3 + ...e_function_one_variable_function.whitelist | 2 + ...function_one_variable_irrelevant.whitelist | 2 + ...e_function_one_variable_variable.whitelist | 2 + tests/test-symtab.cc | 103 ++++++++++++++++-- 6 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 tests/data/test-symtab/basic/one_function_one_variable_all.whitelist create mode 100644 tests/data/test-symtab/basic/one_function_one_variable_function.whitelist create mode 100644 tests/data/test-symtab/basic/one_function_one_variable_irrelevant.whitelist create mode 100644 tests/data/test-symtab/basic/one_function_one_variable_variable.whitelist diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index a23dbc6343fa..42a94f62f67d 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -1861,6 +1861,10 @@ test-symtab/basic/no_debug_info.c \ test-symtab/basic/no_debug_info.so \ test-symtab/basic/one_function_one_variable.c \ test-symtab/basic/one_function_one_variable.so \ +test-symtab/basic/one_function_one_variable_variable.whitelist \ +test-symtab/basic/one_function_one_variable_function.whitelist \ +test-symtab/basic/one_function_one_variable_irrelevant.whitelist \ +test-symtab/basic/one_function_one_variable_all.whitelist \ test-symtab/basic/one_function_one_variable_undefined.c \ test-symtab/basic/one_function_one_variable_undefined.so \ test-symtab/basic/single_function.c \ diff --git a/tests/data/test-symtab/basic/one_function_one_variable_all.whitelist b/tests/data/test-symtab/basic/one_function_one_variable_all.whitelist new file mode 100644 index 000000000000..02ea310960ff --- /dev/null +++ b/tests/data/test-symtab/basic/one_function_one_variable_all.whitelist @@ -0,0 +1,3 @@ +[abi_whitelist] + exported_function + exported_variable diff --git a/tests/data/test-symtab/basic/one_function_one_variable_function.whitelist b/tests/data/test-symtab/basic/one_function_one_variable_function.whitelist new file mode 100644 index 000000000000..893accc14118 --- /dev/null +++ b/tests/data/test-symtab/basic/one_function_one_variable_function.whitelist @@ -0,0 +1,2 @@ +[abi_whitelist] + exported_function diff --git a/tests/data/test-symtab/basic/one_function_one_variable_irrelevant.whitelist b/tests/data/test-symtab/basic/one_function_one_variable_irrelevant.whitelist new file mode 100644 index 000000000000..180ef9064e8f --- /dev/null +++ b/tests/data/test-symtab/basic/one_function_one_variable_irrelevant.whitelist @@ -0,0 +1,2 @@ +[abi_whitelist] + irrelevant diff --git a/tests/data/test-symtab/basic/one_function_one_variable_variable.whitelist b/tests/data/test-symtab/basic/one_function_one_variable_variable.whitelist new file mode 100644 index 000000000000..49d838f2c559 --- /dev/null +++ b/tests/data/test-symtab/basic/one_function_one_variable_variable.whitelist @@ -0,0 +1,2 @@ +[abi_whitelist] + exported_variable diff --git a/tests/test-symtab.cc b/tests/test-symtab.cc index 2df766de1c5c..ac853e895fef 100644 --- a/tests/test-symtab.cc +++ b/tests/test-symtab.cc @@ -11,11 +11,14 @@ #include #include +#include #include #include "abg-corpus.h" #include "abg-dwarf-reader.h" +#include "abg-fwd.h" #include "abg-ir.h" +#include "abg-tools-utils.h" #include "lib/catch.hpp" #include "test-utils.h" @@ -26,12 +29,16 @@ using dwarf_reader::read_context_sptr; using dwarf_reader::read_corpus_from_elf; using ir::environment; using ir::environment_sptr; +using suppr::suppressions_type; static const std::string test_data_dir = std::string(abigail::tests::get_src_dir()) + "/tests/data/test-symtab/"; dwarf_reader::status -read_corpus(const std::string path, corpus_sptr& result) +read_corpus( + const std::string& path, + corpus_sptr& result, + const std::vector& whitelist_paths = std::vector()) { const std::string& absolute_path = test_data_dir + path; @@ -41,6 +48,15 @@ read_corpus(const std::string path, corpus_sptr& result) absolute_path, debug_info_root_paths, env.get(), /* load_all_type = */ true, /* linux_kernel_mode = */ true); + if (!whitelist_paths.empty()) + { + const suppressions_type& wl_suppr = + tools_utils::gen_suppr_spec_from_kernel_abi_whitelists( + whitelist_paths); + REQUIRE_FALSE(wl_suppr.empty()); + dwarf_reader::add_read_context_suppressions(*ctxt, wl_suppr); + } + dwarf_reader::status status = dwarf_reader::STATUS_UNKNOWN; result = read_corpus_from_elf(*ctxt, status); @@ -76,14 +92,17 @@ TEST_CASE("Symtab::NoDebugInfo", "[symtab, basic]") #define N std::numeric_limits::max() corpus_sptr -assert_symbol_count(const std::string& path, - size_t function_symbols = 0, - size_t variable_symbols = 0, - size_t undefined_function_symbols = 0, - size_t undefined_variable_symbols = 0) +assert_symbol_count( + const std::string& path, + size_t function_symbols = 0, + size_t variable_symbols = 0, + size_t undefined_function_symbols = 0, + size_t undefined_variable_symbols = 0, + const std::vector& whitelist_paths = std::vector()) { corpus_sptr corpus_ptr; - const dwarf_reader::status status = read_corpus(path, corpus_ptr); + const dwarf_reader::status status = + read_corpus(path, corpus_ptr, whitelist_paths); REQUIRE(corpus_ptr); REQUIRE((status & dwarf_reader::STATUS_OK)); @@ -188,6 +207,76 @@ TEST_CASE("Symtab::SimpleSymtabs", "[symtab, basic]") } } +TEST_CASE("Symtab::SymtabWithWhitelist", "[symtab, whitelist]") +{ + GIVEN("a binary with one function and one variable exported") + { + const std::string binary = "basic/one_function_one_variable.so"; + + GIVEN("we read the binary without any whitelists") + { + const corpus_sptr& corpus = assert_symbol_count(binary, 1, 1); + CHECK(corpus->lookup_function_symbol("exported_function")); + CHECK(!corpus->lookup_variable_symbol("exported_function")); + CHECK(corpus->lookup_variable_symbol("exported_variable")); + CHECK(!corpus->lookup_function_symbol("exported_variable")); + } + + GIVEN("we read the binary with all symbols on the whitelists") + { + std::vector whitelists; + whitelists.push_back(test_data_dir + + "basic/one_function_one_variable_all.whitelist"); + const corpus_sptr& corpus = + assert_symbol_count(binary, 1, 1, 0, 0, whitelists); + CHECK(corpus->lookup_function_symbol("exported_function")); + CHECK(!corpus->lookup_variable_symbol("exported_function")); + CHECK(corpus->lookup_variable_symbol("exported_variable")); + CHECK(!corpus->lookup_function_symbol("exported_variable")); + } + + GIVEN("we read the binary with only irrelevant symbols whitelisted") + { + std::vector whitelists; + whitelists.push_back( + test_data_dir + + "basic/one_function_one_variable_irrelevant.whitelist"); + + corpus_sptr corpus_ptr; + const dwarf_reader::status status = + read_corpus(binary, corpus_ptr, whitelists); + REQUIRE(!corpus_ptr); + REQUIRE((status & dwarf_reader::STATUS_NO_SYMBOLS_FOUND)); + } + + GIVEN("we read the binary with only the function whitelisted") + { + std::vector whitelists; + whitelists.push_back( + test_data_dir + "basic/one_function_one_variable_function.whitelist"); + const corpus_sptr& corpus = + assert_symbol_count(binary, 1, 0, 0, 0, whitelists); + CHECK(corpus->lookup_function_symbol("exported_function")); + CHECK(!corpus->lookup_variable_symbol("exported_function")); + CHECK(!corpus->lookup_variable_symbol("exported_variable")); + CHECK(!corpus->lookup_function_symbol("exported_variable")); + } + + GIVEN("we read the binary with only the variable whitelisted") + { + std::vector whitelists; + whitelists.push_back( + test_data_dir + "basic/one_function_one_variable_variable.whitelist"); + const corpus_sptr& corpus = + assert_symbol_count(binary, 0, 1, 0, 0, whitelists); + CHECK(!corpus->lookup_function_symbol("exported_function")); + CHECK(!corpus->lookup_variable_symbol("exported_function")); + CHECK(corpus->lookup_variable_symbol("exported_variable")); + CHECK(!corpus->lookup_function_symbol("exported_variable")); + } + } +} + static const char* kernel_versions[] = { "4.14", "4.19", "5.4", "5.6" }; static const size_t nr_kernel_versions = sizeof(kernel_versions) / sizeof(kernel_versions[0]); From patchwork Wed Jan 27 12:58:50 2021 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: 41854 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 A076A3973039; Wed, 27 Jan 2021 13:01:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A076A3973039 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752497; bh=tzO2Q+GTj72UWdDTXmaUti8NOt5W2S6ETd7NJV0492c=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=mqevW7u5N9Nn5dKj+/+KsY6p0Ek/S7qO/Cm8XUMYO8Qw39AO8HVf+1HZA1r1aRey+ e/cIQxxrgNy/pApVXS/w4bR5EnHlxhitfqUKf+IVQWTsvkKoZTzWpPewEug7CquMFs cpDANpKJT17Rj8cQD37QmOsdzhgaOhycpQLfrauQ= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by sourceware.org (Postfix) with ESMTPS id 87576397303B for ; Wed, 27 Jan 2021 12:59:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 87576397303B Received: by mail-qk1-x74a.google.com with SMTP id u66so1373809qkd.13 for ; Wed, 27 Jan 2021 04:59:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=tzO2Q+GTj72UWdDTXmaUti8NOt5W2S6ETd7NJV0492c=; b=MzxcDmNvih7rgYEEqUUiVeJZEkrdKEHcpMcS8HivHA6TYjdefZOHhl9xVtVFWPQXI2 uXslhv0xNkqfRwGe+2oF6zYNgcxWFyCt5F5tp3kXZxkjpFwTx7vf3RSVnUs5TQVEi0iT okti0tXv1fNUpZ3jQgg04JIYeS9g9T5GAMza5gqOpHq3nEq72tVg134BEjfl7VN8eqml ot8nOWL0ZfQmOeS90lr0pK2wirRJsCKYIc4aTK2dMxmBGMunpKB9NMKWqucM2SuysacW VEjYAE86d402SAPeqwRtrbsVHJkZpc+a1z6hxUKNfw1E08OQeti7KJSKlyJKVE+uukqI 4j2Q== X-Gm-Message-State: AOAM532anEAwCv2pYzIfHBS3PBHp13NI5uMpwwhWUC/QKASOT/tdiM+g 1Zby08LQhHss/+Z8DJsU5hGTC/qbPXJ6U4uEQATAy5CSppuQ3nn4VYBqukOs6OvaqKzTlXOejzB E2Zp0hG/pWzGCcAD2yuFwKJVizrnS/14mnJTf/l5mbMGg8c4YDYfdm65zj7EEa1x6hzR4rKg= X-Google-Smtp-Source: ABdhPJxQcTNy9g8ThZ0UYpwOcnOTbzL7sJ2YO1W5ZgoytwC6JOGKsH7ITjM0V3aA8mVPvNvoEPvaFimCgITfdw== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:a0c:f64c:: with SMTP id s12mr10324265qvm.2.1611752385322; Wed, 27 Jan 2021 04:59:45 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:50 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-18-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 17/20] symtab/dwarf-reader: allow hinting of main symbols for aliases To: libabigail@sourceware.org X-Spam-Status: No, score=-21.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TIME_LIMIT_EXCEEDED, USER_IN_DEF_DKIM_WL autolearn=unavailable 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" In case of aliased symbols, the "main symbol" cannot be deduced from the symtab as this solely contains a name->addr mapping and aliases are represented by multiple names resolving to the same address. Therefore the main symbol can only be picked rather randomly and unpredictable. Unlike DWARF, which contains a single symbol entry for only the main symbol. Hence we can (late) detect the main symbol. Exploiting that property allows to correct the addr->symbol lookup in the symtab to return the correct main symbol and it also allows to correct the aliased symbols to maintain the correct main symbol. This patch adds the `update_main_symbol` functionality to `elf_symbol` to update the main symbol by name (ELF symbols need unique names) and adds `update_main_symbol` to `symtab` that makes use of said new method. When we discover a main symbol during DWARF reading, we instruct the symtab to update the mapping. This creates consistent representations across different builds of the same binary with the same ABI by pinning down the main symbol to the defined one. Knowing the main symbol also helps to keep the correct dwarf information in the representation in the presence of symbol suppressions. A later patch will address that. Some test cases in tests/data need adjustment and they have all been verified to be valid changes. - main symbol changed for various elf symbols - test-annotate/test15-pr18892.so.abi - test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi - test-annotate/test3.so.abi - test-read-dwarf/test15-pr18892.so.abi - test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi - test-read-dwarf/test3.so.abi - test-read-dwarf/test3.so.hash.abi - due to main symbol changes, the symbol diff needs to be corrected - test-diff-dwarf/test12-report.txt - test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt - test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt - the test scenario needed adjustments as the main symbol changed - test-diff-suppr/test23-alias-filter-4.suppr - test-diff-suppr/test23-alias-filter-report-0.txt - test-diff-suppr/test23-alias-filter-report-2.txt As usual, the complete changelog follows. * include/abg-ir.h (elf_symbol::update_main_symbol): New method. * include/abg-symtab-reader.h (symtab::update_main_symbol): New method. * src/abg-dwarf-reader.cc (build_var_decl): Hint symtab about main symbol discovered in DWARF. (build_function_decl): Likewise. * src/abg-ir.cc (elf_symbol::get_main_symbol): Lock the weak_ptr on access in both overloads. (update_main_symbol): New method to allow updating the main symbol. * src/abg-symtab-reader.cc (symtab::update_main_symbol): New method. * data/Makefile.am: Add new test data files. * tests/data/test-annotate/test15-pr18892.so.abi: Updated test file. * tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise. * tests/data/test-annotate/test2.so.abi: Likewise. * tests/data/test-annotate/test3.so.abi: Likewise. * tests/data/test-diff-dwarf/test12-report.txt: Likewise. * tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt: Likewise. * tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt: Likewise. * tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt: Likewise. * tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt: Likewise. * tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt: Likewise. * tests/data/test-diff-suppr/test23-alias-filter-4.suppr: Likewise. * tests/data/test-diff-suppr/test23-alias-filter-report-0.txt: Likewise. * tests/data/test-diff-suppr/test23-alias-filter-report-2.txt: Likewise. * tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi: Likewise. * tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise. * tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Likewise. * tests/data/test-read-dwarf/test11-pr18828.so.abi: Likewise. * tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise. * tests/data/test-read-dwarf/test15-pr18892.so.abi: Likewise. * tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise. * tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise. * tests/data/test-read-dwarf/test2.so.abi: Likewise. * tests/data/test-read-dwarf/test2.so.hash.abi: Likewise. * tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi: Likewise. * tests/data/test-read-dwarf/test3.so.abi: Likewise. * tests/data/test-read-dwarf/test3.so.hash.abi: Likewise. * tests/data/test-symtab/basic/aliases.c: New test source file. * tests/data/test-symtab/basic/aliases.so: Likewise. * tests/test-symtab.cc (Symtab::AliasedFunctionSymbols): New test case. (Symtab::AliasedVariableSymbols): Likewise. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- include/abg-ir.h | 3 + src/abg-dwarf-reader.cc | 16 +- src/abg-ir.cc | 47 +- src/abg-symtab-reader.cc | 31 + src/abg-symtab-reader.h | 3 + tests/data/Makefile.am | 2 + .../test5-fn-changed-report-0.txt | 4 - .../test5-fn-changed-report-1.txt | 4 - .../data/test-annotate/test15-pr18892.so.abi | 918 +++++++-------- ...19-pr19023-libtcmalloc_and_profiler.so.abi | 60 +- tests/data/test-annotate/test2.so.abi | 12 +- tests/data/test-annotate/test3.so.abi | 6 +- tests/data/test-diff-dwarf/test12-report.txt | 7 + .../test36-ppc64-aliases-report-0.txt | 4 +- .../test42-PR21296-clanggcc-report0.txt | 6 +- .../test31-pr18535-libstdc++-report-0.txt | 6 +- .../test31-pr18535-libstdc++-report-1.txt | 6 +- ...bb-4.3-3.20141204.fc23.x86_64-report-0.txt | 6 +- ...bb-4.3-3.20141204.fc23.x86_64-report-1.txt | 6 +- .../test23-alias-filter-4.suppr | 2 +- .../test23-alias-filter-report-0.txt | 4 +- .../test23-alias-filter-report-2.txt | 4 +- .../PR22015-libboost_iostreams.so.abi | 48 +- .../test-read-dwarf/PR22122-libftdc.so.abi | 6 +- .../test-read-dwarf/test10-pr18818-gcc.so.abi | 192 +-- .../test-read-dwarf/test11-pr18828.so.abi | 516 ++++---- .../test-read-dwarf/test12-pr18844.so.abi | 66 +- .../test-read-dwarf/test15-pr18892.so.abi | 918 +++++++-------- .../test-read-dwarf/test16-pr18904.so.abi | 990 ++++++++-------- ...19-pr19023-libtcmalloc_and_profiler.so.abi | 60 +- tests/data/test-read-dwarf/test2.so.abi | 12 +- tests/data/test-read-dwarf/test2.so.hash.abi | 12 +- .../test22-pr19097-libstdc++.so.6.0.17.so.abi | 1042 ++++++++--------- tests/data/test-read-dwarf/test3.so.abi | 6 +- tests/data/test-read-dwarf/test3.so.hash.abi | 6 +- tests/data/test-symtab/basic/aliases.c | 13 + tests/data/test-symtab/basic/aliases.so | Bin 0 -> 17176 bytes tests/test-symtab.cc | 47 + 38 files changed, 2619 insertions(+), 2472 deletions(-) create mode 100644 tests/data/test-symtab/basic/aliases.c create mode 100755 tests/data/test-symtab/basic/aliases.so diff --git a/include/abg-ir.h b/include/abg-ir.h index 23ba16bd327b..a14ee1c23784 100644 --- a/include/abg-ir.h +++ b/include/abg-ir.h @@ -954,6 +954,9 @@ public: bool is_main_symbol() const; + elf_symbol_sptr + update_main_symbol(const std::string&); + elf_symbol_sptr get_next_alias() const; diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 91451208ef11..7d7ffbdc8ebe 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -13419,7 +13419,13 @@ build_var_decl(read_context& ctxt, elf_symbol_sptr var_sym; Dwarf_Addr var_addr; if (ctxt.get_variable_address(die, var_addr)) - var_sym = var_sym = ctxt.variable_symbol_is_exported(var_addr); + { + ctxt.symtab()->update_main_symbol(var_addr, + result->get_linkage_name().empty() + ? result->get_name() + : result->get_linkage_name()); + var_sym = ctxt.variable_symbol_is_exported(var_addr); + } if (var_sym) { @@ -13884,7 +13890,13 @@ build_function_decl(read_context& ctxt, elf_symbol_sptr fn_sym; Dwarf_Addr fn_addr; if (ctxt.get_function_address(die, fn_addr)) - fn_sym = ctxt.function_symbol_is_exported(fn_addr); + { + ctxt.symtab()->update_main_symbol(fn_addr, + result->get_linkage_name().empty() + ? result->get_name() + : result->get_linkage_name()); + fn_sym = ctxt.function_symbol_is_exported(fn_addr); + } if (fn_sym && !ctxt.symbol_already_belongs_to_a_function(fn_sym)) { diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 1ba95dd6c14f..0b31f2014189 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -1754,14 +1754,14 @@ elf_symbol::set_is_suppressed(bool is_suppressed) ///@return the main symbol. const elf_symbol_sptr elf_symbol::get_main_symbol() const -{return elf_symbol_sptr(priv_->main_symbol_);} +{return priv_->main_symbol_.lock();} /// Get the main symbol of an alias chain. /// ///@return the main symbol. elf_symbol_sptr elf_symbol::get_main_symbol() -{return elf_symbol_sptr(priv_->main_symbol_);} +{return priv_->main_symbol_.lock();} /// Tests whether this symbol is the main symbol. /// @@ -1838,6 +1838,49 @@ elf_symbol::add_alias(const elf_symbol_sptr& alias) alias->priv_->main_symbol_ = get_main_symbol(); } +/// Update the main symbol for a group of aliased symbols +/// +/// If after the construction of the symbols (in order of discovery), the +/// actual main symbol can be identified (e.g. as the symbol that actually is +/// defined in the code), this method offers a way of updating the main symbol +/// through one of the aliased symbols. +/// +/// For that, locate the new main symbol by name and update all references to +/// the main symbol among the group of aliased symbols. +/// +/// @param name the name of the main symbol +/// +/// @return the new main elf_symbol +elf_symbol_sptr +elf_symbol::update_main_symbol(const std::string& name) +{ + ABG_ASSERT(is_main_symbol()); + if (!has_aliases() || get_name() == name) + return get_main_symbol(); + + // find the new main symbol + elf_symbol_sptr new_main; + // we've already checked this; check the rest of the aliases + for (elf_symbol_sptr a = get_next_alias(); a.get() != this; + a = a->get_next_alias()) + if (a->get_name() == name) + { + new_main = a; + break; + } + + if (!new_main) + return get_main_symbol(); + + // now update all main symbol references + priv_->main_symbol_ = new_main; + for (elf_symbol_sptr a = get_next_alias(); a.get() != this; + a = a->get_next_alias()) + a->priv_->main_symbol_ = new_main; + + return new_main; +} + /// Return true if the symbol is a common one. /// /// @return true iff the symbol is common. diff --git a/src/abg-symtab-reader.cc b/src/abg-symtab-reader.cc index 7318fdfce52e..a769934e5c05 100644 --- a/src/abg-symtab-reader.cc +++ b/src/abg-symtab-reader.cc @@ -376,6 +376,37 @@ symtab::load_(string_elf_symbols_map_sptr function_symbol_map, return true; } +/// Notify the symtab about the name of the main symbol at a given address. +/// +/// From just alone the symtab we can't guess the main symbol of a bunch of +/// aliased symbols that all point to the same address. During processing of +/// additional information (such as DWARF), this information becomes apparent +/// and we can adjust the addr->symbol lookup map as well as the alias +/// reference of the symbol objects. +/// +/// @param addr the addr that we are updating the main symbol for +/// @param name the name of the main symbol +void +symtab::update_main_symbol(GElf_Addr addr, const std::string& name) +{ + // get one symbol (i.e. the current main symbol) + elf_symbol_sptr symbol = lookup_symbol(addr); + + // The caller might not know whether the addr is associated to an ELF symbol + // that we care about. E.g. the addr could be associated to an ELF symbol, + // but not one in .dynsym when looking at a DSO. Hence, early exit if the + // lookup failed. + if (!symbol) + return; + + // determine the new main symbol by attempting an update + elf_symbol_sptr new_main = symbol->update_main_symbol(name); + + // also update the default symbol we return when looked up by address + if (new_main) + addr_symbol_map_[addr] = new_main; +} + void symtab::update_function_entry_address_symbol_map( Elf* elf_handle, diff --git a/src/abg-symtab-reader.h b/src/abg-symtab-reader.h index 2906bab818b0..a621938c44d7 100644 --- a/src/abg-symtab-reader.h +++ b/src/abg-symtab-reader.h @@ -225,6 +225,9 @@ public: load(string_elf_symbols_map_sptr function_symbol_map, string_elf_symbols_map_sptr variables_symbol_map); + void + update_main_symbol(GElf_Addr addr, const std::string& name); + private: /// Default constructor. Private to enforce creation by factory methods. symtab(); diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 42a94f62f67d..d1358c9e9942 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -1853,6 +1853,8 @@ test-kmi-whitelist/whitelist-with-duplicate-entry \ test-kmi-whitelist/whitelist-with-two-sections \ \ test-symtab/basic/Makefile \ +test-symtab/basic/aliases.c \ +test-symtab/basic/aliases.so \ test-symtab/basic/empty.c \ test-symtab/basic/empty.so \ test-symtab/basic/link_against_me.c \ diff --git a/tests/data/test-abicompat/test5-fn-changed-report-0.txt b/tests/data/test-abicompat/test5-fn-changed-report-0.txt index ccde357d75ce..04676908c7c2 100644 --- a/tests/data/test-abicompat/test5-fn-changed-report-0.txt +++ b/tests/data/test-abicompat/test5-fn-changed-report-0.txt @@ -15,7 +15,3 @@ have sub-types that are different from what application 'test5-fn-changed-app' e 1 data member deletion: 'unsigned char S1::m1', at offset 32 (in bits) - method S0::S0(): - implicit parameter 0 of type 'S0*' has sub-type changes: - pointed to type 'struct S0' changed, as reported earlier - diff --git a/tests/data/test-abicompat/test5-fn-changed-report-1.txt b/tests/data/test-abicompat/test5-fn-changed-report-1.txt index dbdcbe5e7607..b39f650de332 100644 --- a/tests/data/test-abicompat/test5-fn-changed-report-1.txt +++ b/tests/data/test-abicompat/test5-fn-changed-report-1.txt @@ -15,7 +15,3 @@ have sub-types that are different from what application 'test5-fn-changed-app' e 1 data member deletion: 'unsigned char S1::m1', at offset 32 (in bits) at test5-fn-changed-libapp-v0.h:11:1 - method S0::S0(): - implicit parameter 0 of type 'S0*' has sub-type changes: - pointed to type 'struct S0' changed at test5-fn-changed-libapp-v0.h:1:1, as reported earlier - diff --git a/tests/data/test-annotate/test15-pr18892.so.abi b/tests/data/test-annotate/test15-pr18892.so.abi index cacace2a09cf..a79557aa2391 100644 --- a/tests/data/test-annotate/test15-pr18892.so.abi +++ b/tests/data/test-annotate/test15-pr18892.so.abi @@ -193,7 +193,7 @@ - + @@ -207,45 +207,45 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -253,7 +253,7 @@ - + @@ -261,69 +261,69 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -341,7 +341,7 @@ - + @@ -353,19 +353,19 @@ - + - + - + - + - + @@ -373,67 +373,67 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -441,25 +441,25 @@ - + - + - + - + - + - + - + - + @@ -467,39 +467,39 @@ - + - + - + - + - + - + - + - + - + - + @@ -509,43 +509,43 @@ - + - + - + - + - + - + - + - + - + - + - + - + @@ -555,7 +555,7 @@ - + @@ -569,21 +569,21 @@ - + - + - + - + - + @@ -591,13 +591,13 @@ - + - + - + @@ -607,9 +607,9 @@ - + - + @@ -621,19 +621,19 @@ - + - + - + - + - + @@ -641,49 +641,49 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -695,19 +695,19 @@ - + - + - + - + @@ -719,23 +719,23 @@ - + - + - + - + - + @@ -745,7 +745,7 @@ - + @@ -761,93 +761,93 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -2223,11 +2223,11 @@ - + - + @@ -2407,11 +2407,11 @@ - + - + @@ -2429,13 +2429,13 @@ - + - + - + @@ -2443,7 +2443,7 @@ - + @@ -2451,7 +2451,7 @@ - + @@ -2459,69 +2459,69 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -2539,7 +2539,7 @@ - + @@ -2551,19 +2551,19 @@ - + - + - + - + - + @@ -2571,67 +2571,67 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -2639,25 +2639,25 @@ - + - + - + - + - + - + - + - + @@ -2665,39 +2665,39 @@ - + - + - + - + - + - + - + - + - + - + @@ -2707,43 +2707,43 @@ - + - + - + - + - + - + - + - + - + - + - + - + @@ -2753,7 +2753,7 @@ - + @@ -2767,21 +2767,21 @@ - + - + - + - + - + @@ -2789,13 +2789,13 @@ - + - + - + @@ -2805,9 +2805,9 @@ - + - + @@ -2819,19 +2819,19 @@ - + - + - + - + - + @@ -2839,49 +2839,49 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -2893,19 +2893,19 @@ - + - + - + - + @@ -2917,23 +2917,23 @@ - + - + - + - + - + @@ -2943,7 +2943,7 @@ - + @@ -2959,73 +2959,73 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -13772,7 +13772,7 @@ - + @@ -13781,7 +13781,7 @@ - + @@ -13790,7 +13790,7 @@ - + @@ -20235,7 +20235,7 @@ - + @@ -20263,7 +20263,7 @@ - + @@ -20283,7 +20283,7 @@ - + @@ -20310,7 +20310,7 @@ - + @@ -20319,7 +20319,7 @@ - + @@ -20333,14 +20333,14 @@ - + - + @@ -20351,7 +20351,7 @@ - + @@ -20362,7 +20362,7 @@ - + @@ -20395,7 +20395,7 @@ - + @@ -20415,7 +20415,7 @@ - + @@ -20424,21 +20424,21 @@ - + - + - + @@ -20458,7 +20458,7 @@ - + @@ -20478,7 +20478,7 @@ - + @@ -20487,7 +20487,7 @@ - + @@ -20505,7 +20505,7 @@ - + @@ -20514,7 +20514,7 @@ - + @@ -20543,7 +20543,7 @@ - + @@ -20552,7 +20552,7 @@ - + @@ -20561,7 +20561,7 @@ - + @@ -20572,7 +20572,7 @@ - + @@ -20581,7 +20581,7 @@ - + @@ -20604,7 +20604,7 @@ - + @@ -20613,7 +20613,7 @@ - + @@ -20622,7 +20622,7 @@ - + @@ -20649,7 +20649,7 @@ - + @@ -20685,7 +20685,7 @@ - + @@ -20712,7 +20712,7 @@ - + @@ -20744,14 +20744,14 @@ - + - + @@ -20787,14 +20787,14 @@ - + - + @@ -20819,7 +20819,7 @@ - + @@ -20848,7 +20848,7 @@ - + @@ -20861,7 +20861,7 @@ - + @@ -20907,7 +20907,7 @@ - + @@ -20918,7 +20918,7 @@ - + @@ -20936,7 +20936,7 @@ - + @@ -20947,7 +20947,7 @@ - + @@ -20958,7 +20958,7 @@ - + @@ -20989,7 +20989,7 @@ - + @@ -21013,7 +21013,7 @@ - + @@ -21028,7 +21028,7 @@ - + @@ -21041,7 +21041,7 @@ - + @@ -21052,7 +21052,7 @@ - + @@ -21063,7 +21063,7 @@ - + @@ -21074,14 +21074,14 @@ - + - + @@ -21130,7 +21130,7 @@ - + @@ -21148,14 +21148,14 @@ - + - + @@ -21177,7 +21177,7 @@ - + @@ -21186,7 +21186,7 @@ - + @@ -21262,7 +21262,7 @@ - + @@ -21279,7 +21279,7 @@ - + @@ -21342,7 +21342,7 @@ - + @@ -21371,7 +21371,7 @@ - + @@ -21404,7 +21404,7 @@ - + @@ -21417,7 +21417,7 @@ - + @@ -21439,7 +21439,7 @@ - + @@ -21470,7 +21470,7 @@ - + @@ -21479,7 +21479,7 @@ - + @@ -21488,7 +21488,7 @@ - + @@ -21506,7 +21506,7 @@ - + @@ -21517,7 +21517,7 @@ - + @@ -21528,7 +21528,7 @@ - + @@ -21538,7 +21538,7 @@ - + @@ -21549,7 +21549,7 @@ - + @@ -21559,7 +21559,7 @@ - + @@ -21568,7 +21568,7 @@ - + @@ -21576,7 +21576,7 @@ - + @@ -21608,7 +21608,7 @@ - + @@ -21618,7 +21618,7 @@ - + @@ -21627,7 +21627,7 @@ - + @@ -21646,7 +21646,7 @@ - + @@ -21662,7 +21662,7 @@ - + @@ -21671,7 +21671,7 @@ - + @@ -21687,14 +21687,14 @@ - + - + @@ -21710,14 +21710,14 @@ - + - + @@ -21732,7 +21732,7 @@ - + @@ -21745,7 +21745,7 @@ - + @@ -21769,7 +21769,7 @@ - + @@ -21782,7 +21782,7 @@ - + @@ -21795,7 +21795,7 @@ - + @@ -21806,7 +21806,7 @@ - + @@ -21819,7 +21819,7 @@ - + @@ -21832,7 +21832,7 @@ - + @@ -21869,7 +21869,7 @@ - + @@ -21889,7 +21889,7 @@ - + @@ -21907,7 +21907,7 @@ - + @@ -21947,7 +21947,7 @@ - + @@ -21974,7 +21974,7 @@ - + @@ -21983,7 +21983,7 @@ - + @@ -22015,7 +22015,7 @@ - + @@ -22035,7 +22035,7 @@ - + @@ -22048,7 +22048,7 @@ - + @@ -22068,7 +22068,7 @@ - + @@ -22082,7 +22082,7 @@ - + @@ -22096,7 +22096,7 @@ - + @@ -22149,14 +22149,14 @@ - + - + @@ -22180,7 +22180,7 @@ - + @@ -22225,14 +22225,14 @@ - + - + @@ -22255,7 +22255,7 @@ - + @@ -22266,7 +22266,7 @@ - + @@ -22301,7 +22301,7 @@ - + @@ -22315,7 +22315,7 @@ - + @@ -22326,7 +22326,7 @@ - + @@ -22346,7 +22346,7 @@ - + @@ -22355,7 +22355,7 @@ - + @@ -22391,7 +22391,7 @@ - + @@ -22442,7 +22442,7 @@ - + @@ -22451,7 +22451,7 @@ - + @@ -22471,7 +22471,7 @@ - + @@ -22491,7 +22491,7 @@ - + @@ -22502,7 +22502,7 @@ - + @@ -22538,7 +22538,7 @@ - + @@ -22561,14 +22561,14 @@ - + - + @@ -22579,7 +22579,7 @@ - + @@ -22602,7 +22602,7 @@ - + @@ -22647,7 +22647,7 @@ - + @@ -22661,7 +22661,7 @@ - + @@ -22670,7 +22670,7 @@ - + @@ -22714,7 +22714,7 @@ - + @@ -22728,7 +22728,7 @@ - + @@ -22746,7 +22746,7 @@ - + @@ -22760,7 +22760,7 @@ - + @@ -22879,7 +22879,7 @@ - + @@ -22912,7 +22912,7 @@ - + @@ -22932,7 +22932,7 @@ - + @@ -22959,7 +22959,7 @@ - + @@ -23003,7 +23003,7 @@ - + @@ -23096,14 +23096,14 @@ - + - + @@ -23117,7 +23117,7 @@ - + @@ -23126,7 +23126,7 @@ - + @@ -23144,14 +23144,14 @@ - + - + @@ -23169,7 +23169,7 @@ - + @@ -23178,7 +23178,7 @@ - + @@ -23221,7 +23221,7 @@ - + @@ -23237,7 +23237,7 @@ - + @@ -27191,7 +27191,7 @@ - + @@ -27209,7 +27209,7 @@ - + diff --git a/tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi b/tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi index 1ba7ead9d421..ec6cbb3f6bc3 100644 --- a/tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi +++ b/tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi @@ -1098,15 +1098,15 @@ - + - + - + - + @@ -1124,11 +1124,11 @@ - + - + @@ -1138,19 +1138,19 @@ - + - + - + @@ -1164,7 +1164,7 @@ - + @@ -1174,23 +1174,23 @@ - + - + - + - + - + - + @@ -1204,19 +1204,19 @@ - + - + - + - + @@ -24511,7 +24511,7 @@ - + @@ -24528,7 +24528,7 @@ - + @@ -24539,14 +24539,14 @@ - + - + @@ -24571,7 +24571,7 @@ - + @@ -24594,7 +24594,7 @@ - + @@ -24624,14 +24624,14 @@ - + - + @@ -24647,14 +24647,14 @@ - + - + diff --git a/tests/data/test-annotate/test2.so.abi b/tests/data/test-annotate/test2.so.abi index cc40ccd0e3c5..072834a187b5 100644 --- a/tests/data/test-annotate/test2.so.abi +++ b/tests/data/test-annotate/test2.so.abi @@ -7,13 +7,13 @@ - + - + - + - + @@ -55,7 +55,7 @@ - + @@ -96,7 +96,7 @@ - + diff --git a/tests/data/test-annotate/test3.so.abi b/tests/data/test-annotate/test3.so.abi index cbcb456d97c8..ca3790742779 100644 --- a/tests/data/test-annotate/test3.so.abi +++ b/tests/data/test-annotate/test3.so.abi @@ -4,7 +4,7 @@ - + @@ -12,7 +12,7 @@ - + @@ -20,7 +20,7 @@ - + diff --git a/tests/data/test-diff-dwarf/test12-report.txt b/tests/data/test-diff-dwarf/test12-report.txt index e69de29bb2d1..62dd8337d694 100644 --- a/tests/data/test-diff-dwarf/test12-report.txt +++ b/tests/data/test-diff-dwarf/test12-report.txt @@ -0,0 +1,7 @@ +Functions changes summary: 0 Removed, 0 Changed, 1 Added function +Variables changes summary: 0 Removed, 0 Changed, 0 Added variable + +1 Added function: + + [A] 'function int _foo3(int, int)' + diff --git a/tests/data/test-diff-dwarf/test36-ppc64-aliases-report-0.txt b/tests/data/test-diff-dwarf/test36-ppc64-aliases-report-0.txt index 4f4a765f9381..a79c11bed2dc 100644 --- a/tests/data/test-diff-dwarf/test36-ppc64-aliases-report-0.txt +++ b/tests/data/test-diff-dwarf/test36-ppc64-aliases-report-0.txt @@ -3,14 +3,14 @@ Variables changes summary: 0 Removed, 0 Changed, 0 Added variable 4 functions with some indirect sub-type change: - [C] 'method S::S()' has some indirect sub-type changes: + [C] 'method S::S(int)' has some indirect sub-type changes: implicit parameter 0 of type 'S*' has sub-type changes: in pointed to type 'struct S': type size changed from 32 to 64 (in bits) 1 data member insertion: 'int S::m1', at offset 32 (in bits) - [C] 'method S::S(int)' has some indirect sub-type changes: + [C] 'method S::S()' has some indirect sub-type changes: implicit parameter 0 of type 'S*' has sub-type changes: pointed to type 'struct S' changed, as reported earlier diff --git a/tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt b/tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt index 61491027df5c..094a30dd3fee 100644 --- a/tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt +++ b/tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt @@ -1,10 +1,8 @@ -Functions changes summary: 3 Removed, 8 Changed, 0 Added functions +Functions changes summary: 1 Removed, 8 Changed, 0 Added functions Variables changes summary: 0 Removed, 0 Changed, 0 Added variable -3 Removed functions: +1 Removed function: - [D] 'method STR::STR(const char*)' - [D] 'method STR::~STR()' [D] 'method void std::_Tuple_impl<1ul>::_Tuple_impl()' 8 functions with some indirect sub-type change: diff --git a/tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt b/tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt index 10677fccd685..544488c6becf 100644 --- a/tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt +++ b/tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt @@ -1,4 +1,4 @@ -Functions changes summary: 0 Removed, 5 Changed (195 filtered out), 13 Added functions +Functions changes summary: 0 Removed, 5 Changed (206 filtered out), 13 Added functions Variables changes summary: 0 Removed, 0 Changed, 0 Added variable Function symbols changes summary: 0 Removed, 0 Added function symbol not referenced by debug info Variable symbols changes summary: 0 Removed, 6 Added variable symbols not referenced by debug info @@ -97,8 +97,8 @@ Variable symbols changes summary: 0 Removed, 6 Added variable symbols not refere no member function changes (10 filtered); [C] 'method std::codecvt_byname* std::codecvt_byname::codecvt_byname(const char*, std::size_t)' has some indirect sub-type changes: - Please note that the symbol of this function is _ZNSt14codecvt_bynameIwc11__mbstate_tEC1EPKcj@@GLIBCXX_3.4 - and it aliases symbol: _ZNSt14codecvt_bynameIwc11__mbstate_tEC2EPKcj@@GLIBCXX_3.4 + Please note that the symbol of this function is _ZNSt14codecvt_bynameIwc11__mbstate_tEC2EPKcj@@GLIBCXX_3.4 + and it aliases symbol: _ZNSt14codecvt_bynameIwc11__mbstate_tEC1EPKcj@@GLIBCXX_3.4 implicit parameter 0 of type 'std::codecvt_byname*' has sub-type changes: in pointed to type 'class std::codecvt_byname': type size hasn't changed diff --git a/tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt b/tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt index 84667becbc25..c84cd1cd0c78 100644 --- a/tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt +++ b/tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt @@ -1,4 +1,4 @@ -Functions changes summary: 0 Removed, 5 Changed (195 filtered out), 13 Added functions +Functions changes summary: 0 Removed, 5 Changed (206 filtered out), 13 Added functions Variables changes summary: 0 Removed, 0 Changed, 0 Added variable Function symbols changes summary: 0 Removed, 0 Added function symbol not referenced by debug info Variable symbols changes summary: 0 Removed, 6 Added variable symbols not referenced by debug info @@ -97,8 +97,8 @@ Variable symbols changes summary: 0 Removed, 6 Added variable symbols not refere no member function changes (10 filtered); [C] 'method std::codecvt_byname* std::codecvt_byname::codecvt_byname(const char*, std::size_t)' at codecvt.h:462:1 has some indirect sub-type changes: - Please note that the symbol of this function is _ZNSt14codecvt_bynameIwc11__mbstate_tEC1EPKcj@@GLIBCXX_3.4 - and it aliases symbol: _ZNSt14codecvt_bynameIwc11__mbstate_tEC2EPKcj@@GLIBCXX_3.4 + Please note that the symbol of this function is _ZNSt14codecvt_bynameIwc11__mbstate_tEC2EPKcj@@GLIBCXX_3.4 + and it aliases symbol: _ZNSt14codecvt_bynameIwc11__mbstate_tEC1EPKcj@@GLIBCXX_3.4 implicit parameter 0 of type 'std::codecvt_byname*' has sub-type changes: in pointed to type 'class std::codecvt_byname' at codecvt.h:458:1: type size hasn't changed diff --git a/tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt b/tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt index 3616cb3435bd..741487af86f8 100644 --- a/tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt +++ b/tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt @@ -317,20 +317,18 @@ ================ end of changes of 'libtbbmalloc.so.2'=============== ================ changes of 'libtbbmalloc_proxy.so.2'=============== - Functions changes summary: 1 Removed, 0 Changed, 5 Added functions + Functions changes summary: 1 Removed, 0 Changed, 3 Added functions Variables changes summary: 0 Removed, 0 Changed, 0 Added variable 1 Removed function: [D] 'function bool __TBB_internal_find_original_malloc(int, const char**, void**)' {__TBB_internal_find_original_malloc} - 5 Added functions: + 3 Added functions: [A] 'function void __libc_free(void*)' {__libc_free} [A] 'function void* __libc_realloc(void*, size_t)' {__libc_realloc} - [A] 'function void* calloc(size_t, size_t)' {__libc_calloc, aliases calloc} [A] 'function size_t malloc_usable_size(void*)' {malloc_usable_size} - [A] 'function void* valloc(size_t)' {__libc_valloc, aliases valloc} ================ end of changes of 'libtbbmalloc_proxy.so.2'=============== diff --git a/tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt b/tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt index dcd30874496b..9438b4ed8b00 100644 --- a/tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt +++ b/tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt @@ -165,20 +165,18 @@ ================ end of changes of 'libtbbmalloc.so.2'=============== ================ changes of 'libtbbmalloc_proxy.so.2'=============== - Functions changes summary: 1 Removed, 0 Changed, 5 Added functions + Functions changes summary: 1 Removed, 0 Changed, 3 Added functions Variables changes summary: 0 Removed, 0 Changed, 0 Added variable 1 Removed function: [D] 'function bool __TBB_internal_find_original_malloc(int, const char**, void**)' {__TBB_internal_find_original_malloc} - 5 Added functions: + 3 Added functions: [A] 'function void __libc_free(void*)' {__libc_free} [A] 'function void* __libc_realloc(void*, size_t)' {__libc_realloc} - [A] 'function void* calloc(size_t, size_t)' {__libc_calloc, aliases calloc} [A] 'function size_t malloc_usable_size(void*)' {malloc_usable_size} - [A] 'function void* valloc(size_t)' {__libc_valloc, aliases valloc} ================ end of changes of 'libtbbmalloc_proxy.so.2'=============== diff --git a/tests/data/test-diff-suppr/test23-alias-filter-4.suppr b/tests/data/test-diff-suppr/test23-alias-filter-4.suppr index b7429d14505f..16edb095bbbf 100644 --- a/tests/data/test-diff-suppr/test23-alias-filter-4.suppr +++ b/tests/data/test-diff-suppr/test23-alias-filter-4.suppr @@ -1,3 +1,3 @@ [suppress_function] - symbol_name_regexp = function1 + symbol_name_regexp = __private_function allow_other_aliases = no diff --git a/tests/data/test-diff-suppr/test23-alias-filter-report-0.txt b/tests/data/test-diff-suppr/test23-alias-filter-report-0.txt index 0788d48931f7..8b06f3151b63 100644 --- a/tests/data/test-diff-suppr/test23-alias-filter-report-0.txt +++ b/tests/data/test-diff-suppr/test23-alias-filter-report-0.txt @@ -4,8 +4,8 @@ Variables changes summary: 0 Removed, 0 Changed, 0 Added variable 1 function with some indirect sub-type change: [C] 'function void __private_function(S*)' has some indirect sub-type changes: - Please note that the symbol of this function is function1@VERSION_1.0 - and it aliases symbols: __private_function@PRIVATE_1.0, function2@VERSION_1.0 + Please note that the symbol of this function is __private_function@PRIVATE_1.0 + and it aliases symbols: function2@VERSION_1.0, function1@VERSION_1.0 parameter 1 of type 'S*' has sub-type changes: in pointed to type 'typedef S': underlying type 'struct S' changed: diff --git a/tests/data/test-diff-suppr/test23-alias-filter-report-2.txt b/tests/data/test-diff-suppr/test23-alias-filter-report-2.txt index 0788d48931f7..8b06f3151b63 100644 --- a/tests/data/test-diff-suppr/test23-alias-filter-report-2.txt +++ b/tests/data/test-diff-suppr/test23-alias-filter-report-2.txt @@ -4,8 +4,8 @@ Variables changes summary: 0 Removed, 0 Changed, 0 Added variable 1 function with some indirect sub-type change: [C] 'function void __private_function(S*)' has some indirect sub-type changes: - Please note that the symbol of this function is function1@VERSION_1.0 - and it aliases symbols: __private_function@PRIVATE_1.0, function2@VERSION_1.0 + Please note that the symbol of this function is __private_function@PRIVATE_1.0 + and it aliases symbols: function2@VERSION_1.0, function1@VERSION_1.0 parameter 1 of type 'S*' has sub-type changes: in pointed to type 'typedef S': underlying type 'struct S' changed: diff --git a/tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi b/tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi index 1fc1578e66e6..a8bbcf088f87 100644 --- a/tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi +++ b/tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi @@ -36,13 +36,13 @@ - - + + - - + + @@ -50,31 +50,31 @@ - + - + - - + + - - + + - + - + @@ -90,8 +90,8 @@ - - + + @@ -100,8 +100,8 @@ - - + + @@ -506,13 +506,13 @@ - + - + @@ -656,7 +656,7 @@ - + @@ -723,7 +723,7 @@ - + @@ -747,7 +747,7 @@ - + @@ -816,7 +816,7 @@ - + @@ -1418,7 +1418,7 @@ - + @@ -1582,7 +1582,7 @@ - + diff --git a/tests/data/test-read-dwarf/PR22122-libftdc.so.abi b/tests/data/test-read-dwarf/PR22122-libftdc.so.abi index a90c17dfacd6..e7a50ee9ac50 100644 --- a/tests/data/test-read-dwarf/PR22122-libftdc.so.abi +++ b/tests/data/test-read-dwarf/PR22122-libftdc.so.abi @@ -151,8 +151,8 @@ - - + + @@ -4809,7 +4809,7 @@ - + diff --git a/tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi b/tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi index c6fa10347cda..faa3faa186b5 100644 --- a/tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi +++ b/tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi @@ -36,8 +36,8 @@ - - + + @@ -45,24 +45,24 @@ - + - + - - + + - - - - - - + + + + + + @@ -88,16 +88,16 @@ - - + + - + - - + + - + @@ -109,10 +109,10 @@ - - - - + + + + @@ -167,30 +167,30 @@ - + - + - + - + - - + + - - + + - - + + @@ -213,27 +213,27 @@ - - + + - - + + - - + + - - + + - - + + @@ -254,24 +254,24 @@ - - - - + + + + - + - + - - + + - - + + @@ -282,8 +282,8 @@ - - + + @@ -362,9 +362,9 @@ - + - + @@ -1025,7 +1025,7 @@ - + @@ -1536,7 +1536,7 @@ - + @@ -1627,7 +1627,7 @@ - + @@ -1660,7 +1660,7 @@ - + @@ -1705,13 +1705,13 @@ - + - + @@ -1750,7 +1750,7 @@ - + @@ -1758,7 +1758,7 @@ - + @@ -3242,7 +3242,7 @@ - + @@ -3372,7 +3372,7 @@ - + @@ -3392,7 +3392,7 @@ - + @@ -3535,7 +3535,7 @@ - + @@ -3701,13 +3701,13 @@ - + - + @@ -3728,7 +3728,7 @@ - + @@ -3756,7 +3756,7 @@ - + @@ -3965,7 +3965,7 @@ - + @@ -4041,7 +4041,7 @@ - + @@ -4168,20 +4168,20 @@ - + - + - + @@ -4276,20 +4276,20 @@ - + - + - + @@ -4461,7 +4461,7 @@ - + @@ -4629,20 +4629,20 @@ - + - + - + @@ -4722,7 +4722,7 @@ - + @@ -4763,7 +4763,7 @@ - + @@ -4829,13 +4829,13 @@ - + - + @@ -5204,7 +5204,7 @@ - + @@ -5213,7 +5213,7 @@ - + @@ -5264,35 +5264,35 @@ - + - + - + - + - + @@ -5791,7 +5791,7 @@ - + diff --git a/tests/data/test-read-dwarf/test11-pr18828.so.abi b/tests/data/test-read-dwarf/test11-pr18828.so.abi index 1aa056ef2b5f..6734a8e437c7 100644 --- a/tests/data/test-read-dwarf/test11-pr18828.so.abi +++ b/tests/data/test-read-dwarf/test11-pr18828.so.abi @@ -40,24 +40,24 @@ - - - - + + + + - + - - + + - + - - + + @@ -71,22 +71,22 @@ - - - - + + + + - - - - + + + + - - - - + + + + @@ -97,16 +97,16 @@ - - - - + + + + - - + + @@ -115,8 +115,8 @@ - - + + @@ -130,11 +130,11 @@ - - + + - - + + @@ -145,20 +145,20 @@ - - + + - - + + - - + + - - + + @@ -171,8 +171,8 @@ - - + + @@ -183,11 +183,11 @@ - + - - - + + + @@ -205,8 +205,8 @@ - - + + @@ -232,44 +232,44 @@ - - - - - - - - + + + + + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - + + - - + + @@ -326,25 +326,25 @@ - + - - - + + + - - - - - - - - - - + + + + + + + + + + @@ -352,30 +352,30 @@ - - + + - - - - - - + + + + + + - - - - + + + + @@ -383,12 +383,12 @@ - - - - - - + + + + + + @@ -398,31 +398,31 @@ - - - - + + + + - - - - - - + + + + + + - - - - + + + + - - + + @@ -431,34 +431,34 @@ - - - - - - + + + + + + - - + + - - + + - - + + - - + + @@ -469,12 +469,12 @@ - - + + - - + + @@ -494,20 +494,20 @@ - - - - - - + + + + + + - - + + - - + + @@ -518,33 +518,33 @@ - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - - + + + + @@ -568,12 +568,12 @@ - + - + - - + + @@ -3510,7 +3510,7 @@ - + @@ -3544,7 +3544,7 @@ - + @@ -3591,14 +3591,14 @@ - + - + @@ -3829,7 +3829,7 @@ - + @@ -3876,14 +3876,14 @@ - + - + @@ -3937,14 +3937,14 @@ - + - + @@ -4064,13 +4064,13 @@ - + - + @@ -4131,7 +4131,7 @@ - + @@ -4241,13 +4241,13 @@ - + - + @@ -4332,13 +4332,13 @@ - + - + @@ -4378,7 +4378,7 @@ - + @@ -4431,7 +4431,7 @@ - + @@ -4445,7 +4445,7 @@ - + @@ -4500,7 +4500,7 @@ - + @@ -4515,7 +4515,7 @@ - + @@ -4536,7 +4536,7 @@ - + @@ -4722,7 +4722,7 @@ - + @@ -4776,7 +4776,7 @@ - + @@ -4901,14 +4901,14 @@ - + - + @@ -5003,14 +5003,14 @@ - + - + @@ -5250,7 +5250,7 @@ - + @@ -5475,7 +5475,7 @@ - + @@ -5587,7 +5587,7 @@ - + @@ -5647,7 +5647,7 @@ - + @@ -5728,7 +5728,7 @@ - + @@ -7256,7 +7256,7 @@ - + @@ -8548,7 +8548,7 @@ - + @@ -8627,7 +8627,7 @@ - + @@ -8848,7 +8848,7 @@ - + @@ -9064,7 +9064,7 @@ - + @@ -9278,13 +9278,13 @@ - + - + @@ -9864,7 +9864,7 @@ - + @@ -10983,7 +10983,7 @@ - + @@ -11153,11 +11153,11 @@ - + - + @@ -11178,7 +11178,7 @@ - + @@ -11190,7 +11190,7 @@ - + @@ -11265,7 +11265,7 @@ - + @@ -11315,7 +11315,7 @@ - + @@ -11424,7 +11424,7 @@ - + @@ -11460,7 +11460,7 @@ - + @@ -11515,7 +11515,7 @@ - + @@ -11727,7 +11727,7 @@ - + @@ -11749,7 +11749,7 @@ - + @@ -11829,7 +11829,7 @@ - + @@ -11851,7 +11851,7 @@ - + @@ -11894,21 +11894,21 @@ - + - + - + @@ -11922,7 +11922,7 @@ - + @@ -12063,14 +12063,14 @@ - + - + @@ -13032,13 +13032,13 @@ - + - + @@ -13144,7 +13144,7 @@ - + @@ -13163,7 +13163,7 @@ - + @@ -13417,7 +13417,7 @@ - + @@ -13471,7 +13471,7 @@ - + @@ -13550,7 +13550,7 @@ - + @@ -13630,7 +13630,7 @@ - + @@ -13645,7 +13645,7 @@ - + @@ -14005,7 +14005,7 @@ - + @@ -14058,7 +14058,7 @@ - + @@ -14375,14 +14375,14 @@ - + - + @@ -14702,7 +14702,7 @@ - + @@ -14736,7 +14736,7 @@ - + @@ -14758,7 +14758,7 @@ - + @@ -14800,7 +14800,7 @@ - + @@ -14815,7 +14815,7 @@ - + @@ -14945,7 +14945,7 @@ - + @@ -14970,7 +14970,7 @@ - + @@ -15037,7 +15037,7 @@ - + @@ -15062,7 +15062,7 @@ - + @@ -16032,7 +16032,7 @@ - + @@ -16161,13 +16161,13 @@ - + - + diff --git a/tests/data/test-read-dwarf/test12-pr18844.so.abi b/tests/data/test-read-dwarf/test12-pr18844.so.abi index 81dac4eed196..4422b76a7394 100644 --- a/tests/data/test-read-dwarf/test12-pr18844.so.abi +++ b/tests/data/test-read-dwarf/test12-pr18844.so.abi @@ -231,47 +231,47 @@ - - + + - - + + - - + + - - - + + + - + - - + + - - + + - - - - + + + + - - + + @@ -19191,7 +19191,7 @@ - + @@ -19217,7 +19217,7 @@ - + @@ -19231,7 +19231,7 @@ - + @@ -19281,7 +19281,7 @@ - + @@ -19291,7 +19291,7 @@ - + @@ -19378,7 +19378,7 @@ - + @@ -19511,7 +19511,7 @@ - + @@ -23762,14 +23762,14 @@ - + - + @@ -24442,7 +24442,7 @@ - + @@ -25563,7 +25563,7 @@ - + @@ -28277,14 +28277,14 @@ - + - + diff --git a/tests/data/test-read-dwarf/test15-pr18892.so.abi b/tests/data/test-read-dwarf/test15-pr18892.so.abi index 34ff0fb859b8..d4bd4ad68236 100644 --- a/tests/data/test-read-dwarf/test15-pr18892.so.abi +++ b/tests/data/test-read-dwarf/test15-pr18892.so.abi @@ -101,72 +101,72 @@ - + - + - - - - - - + + + + + + - - + + - + - - + + - + - + - - - - + + + + - - - - - + + + + + - - + + - - - + + + - - - + + + - - - + + + - - - + + + @@ -175,209 +175,209 @@ - + - + - - - + + + - + - - + + - + - - + + - - + + - - + + - - + + - + - - + + - - + + - + - - + + - - - - - - + + + + + + - - + + - - - + + + - - - + + + - + - + - + - - + + - - - - - + + + + + - - - + + + - + - + - + - - + + - + - + - + - - + + - - + + - - - - + + + + - + - - - - - + + + + + - - - - + + + + - - - + + + - + - + - + - + - + - - + + - - + + - + - - + + - + @@ -385,50 +385,50 @@ - + - + - + - + - - - + + + - - - + + + - - - + + + - - + + - - - + + + - + - + - - - - - - + + + + + +