From patchwork Fri Jun 19 21:42:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39695 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 18957389852D; Fri, 19 Jun 2020 21:43:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 18957389852D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592602996; bh=zPyZ1/fkBBk2ExWTs5gdlYaB4tTHqlX1Cokq60QzFk8=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=sOvJjq+p0PL0yuJ8u/Z1iA6oXXcZWqiGk8VZnv4yQ7BuqUP3Ld04pkmklyXnq7m4S sv61mPwJsl0VblAkkb3XkqwzNrtxdC2heErJtp8H4bJQ8ip5uN6q1tJd44FSwjllmh bTlIHUaayqItWH4cjQe9ouy/4lBDclqm7Kr+ZkaU= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by sourceware.org (Postfix) with ESMTPS id 56DC1389852D for ; Fri, 19 Jun 2020 21:43:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 56DC1389852D Received: by mail-yb1-xb49.google.com with SMTP id f16so11677625ybp.5 for ; Fri, 19 Jun 2020 14:43:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=zPyZ1/fkBBk2ExWTs5gdlYaB4tTHqlX1Cokq60QzFk8=; b=EdkW3whgkkogh7dn8IvJ8i5rap6Fa/DSgh9znYSVqZem6Coflzjf1MElywMSRx1wqi /aVKf14ZZffC27/+jubDGw+JEgmwt40btKVcYbL1/50uKTkt+bDVgxKeuDdmJAIAVcYI V5ZE9ak2ms8Kdfp97K2FHNIjTUDg3DzXviSTQ668hIkamLFPaHGfVTPkx1Q2fVOEnBqw hDD4py/7HhiDDXErMsutqwAZoKGmwVFAlIVMEtIT/8vtPXASf2xa2a0nnV73cDYdgN9a +5D4Y+zhATRtK+oXlkY4Uzg76wwfVMqgBZSn+f48iXvqxoxygo583MEXd4V7oev660z6 PYaQ== X-Gm-Message-State: AOAM5302oGKPcCngjcdv82zq85mzTgkKRwktX4tfBIbX59oJ7+rVoaso kzGDbP6GcCMgObNc/wmzn2c3BYBiOL1SPtsBYtQcZX8io4wV4JK3Kea/zVHoph5tPw87GMyyEef dAPc6s4rptbW+t9zHaE3xX2brKCG9ba4IX4hC801NGxWkvrFa18ajGzLzJAiVcypvcAFkmNs= X-Google-Smtp-Source: ABdhPJzsRodoIieURLrzokkpT0vDU+thwMmI7grNk8pX099Zdnm/gxHU8tJx94z+s0uq92/k5OZJ0RBFEJ6PRw== X-Received: by 2002:a25:9d0f:: with SMTP id i15mr8979030ybp.508.1592602993772; Fri, 19 Jun 2020 14:43:13 -0700 (PDT) Date: Fri, 19 Jun 2020 23:42:50 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-2-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 01/16] abg-cxx-compat: add simplified version of std::optional To: libabigail@sourceware.org X-Spam-Status: No, score=-23.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, gprocida@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 | 86 ++++++++++++++++++++++++++++++++++++++++ tests/test-cxx-compat.cc | 51 ++++++++++++++++++++++++ 2 files changed, 137 insertions(+) diff --git a/include/abg-cxx-compat.h b/include/abg-cxx-compat.h index 714177183945..1283e9191d46 100644 --- a/include/abg-cxx-compat.h +++ b/include/abg-cxx-compat.h @@ -23,6 +23,8 @@ #ifndef __ABG_CXX_COMPAT_H #define __ABG_CXX_COMPAT_H +// C++11 support (mostly via tr1 if compiled with earlier standard) + #if __cplusplus >= 201103L #include @@ -39,6 +41,18 @@ #endif +// 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 >= 201103L @@ -77,6 +91,78 @@ using std::tr1::unordered_set; #endif +#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 maintainence 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 0a230a54e1a5..adeb7b8d7e4f 100644 --- a/tests/test-cxx-compat.cc +++ b/tests/test-cxx-compat.cc @@ -28,3 +28,54 @@ #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 Fri Jun 19 21:42:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39696 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 61B453938C0E; Fri, 19 Jun 2020 21:43:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61B453938C0E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592602998; bh=MYRweQXk8CqMUKfg24zNmwv8M4of+omF6QZM/LgjajI=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=AAZwNe7E1iH0GDTr6rnSbTJA/OXTX26aFTP7vu/q0c4hUlMcaXQMuLkaLjiU8w/M0 6zqwDXmvzEsuazs+ZBRN/pGVrIDj/tYt8+mopalNCSagb4/XTfkogQQ78WZ1rLwhW5 96La/juwZqVzjoxf4ComdSOLlJ1rS56I+WN5s1bU= 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 405F23898536 for ; Fri, 19 Jun 2020 21:43:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 405F23898536 Received: by mail-qv1-xf4a.google.com with SMTP id q5so7808194qvp.23 for ; Fri, 19 Jun 2020 14:43:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=MYRweQXk8CqMUKfg24zNmwv8M4of+omF6QZM/LgjajI=; b=L0ykvtfjxIpnv1vrJX3cmbHkZMrjJcGrNjs8gnP75zgcery78Cq/iTg7/0g8M6Pzky JENrG42FMUC9i5q2yqpsar9UYKNk068g8Y9LJsDHCF6wK3DJ6qGZE517SA2+no8xk6Wp +yZtzW1GQOuCUuvC/PMqPwmgTw+OqwmIg0ZQ/IJRnzweido0ZCDrWLtqlFZGuwyYNIbx 95TvGjdM0EduwPmUor1OwDiy3pm5dT60xXLFPgNxs2X+g/f68rN9DZ8vKIH9cAj5k2o+ Zaa7N2M16Lru7fSJQo/87tkQK8kfsOc2p8KLYbzY37itnHXfAWifVNNzTFjVX0WSt14J 1A0Q== X-Gm-Message-State: AOAM531w+uv5j4ThjvwqedwUIjqcROKBrLcGD1FFlcGx59RP4ZE03JIh FUeDXx8M966ADmrFJuckXhzTu76kYnqodgGaCHWastD2rZtUOKCMOHAyPGG+iB6NfIZkqTqYron xoswvyUxolskmu2/FfWl9KQ4XmoLZJprhoJ7sEirYCXPQS7BZpqi0QPoCod/cN7hIR6LN+d0= X-Google-Smtp-Source: ABdhPJwYAWJLcgQzz0J3bYPsehdqeA20Mqu6qymIPCj+AgHw7otXtHdtfx5o3QuJ4c/q7SqkiEhRRcqmDegrQQ== X-Received: by 2002:a0c:806e:: with SMTP id 101mr10422685qva.173.1592602995791; Fri, 19 Jun 2020 14:43:15 -0700 (PDT) Date: Fri, 19 Jun 2020 23:42:51 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-3-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 02/16] abg-cxx-compat: more support: std::bind and friends To: libabigail@sourceware.org X-Spam-Status: No, score=-23.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, gprocida@google.com, kernel-team@android.com Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" Add abg_compat::{bind,function,placeholders} to the compatibility layer. That is made use of in a later patch. As usual, for C++ standards that natively support this functionality (C++11 and later), the native implementation is aliased into the abg_compat namespace. * include/abg-cxx-compat.h: add support for abg_compat::{bind,function,placeholders} Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- include/abg-cxx-compat.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/abg-cxx-compat.h b/include/abg-cxx-compat.h index 1283e9191d46..cab2883b231e 100644 --- a/include/abg-cxx-compat.h +++ b/include/abg-cxx-compat.h @@ -58,8 +58,15 @@ namespace abg_compat { #if __cplusplus >= 201103L // +using std::bind; +using std::function; using std::hash; +namespace placeholders +{ +using namespace std::placeholders; +} + // using std::shared_ptr; using std::weak_ptr; @@ -75,8 +82,15 @@ using std::unordered_set; #else // +using std::tr1::bind; +using std::tr1::function; using std::tr1::hash; +namespace placeholders +{ +using namespace std::tr1::placeholders; +} + // using std::tr1::shared_ptr; using std::tr1::weak_ptr; From patchwork Fri Jun 19 21:42:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39697 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 A92E03898531; Fri, 19 Jun 2020 21:43:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A92E03898531 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592603001; bh=b+kjGT73WFLdSPC2x8/fMm9a33v5QVaVEC6QcZ94VhU=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=EVWNnHJs7Dys/hWD01UJwPP+zJisx504bJv6lE6QvQLFGVRnD2OwqyVTCd+fBkUcc UlcXdSchhwoijOP5UsG9yhhM+zMnDTbgVBajYVwKVnSdl5oeTNwl7IR1LEPXyaSopB qlbMkkm1Q6+vrxoBDbApyYUOmhSlHNJcUKRgrc98= 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 7EA4E3938C11 for ; Fri, 19 Jun 2020 21:43:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7EA4E3938C11 Received: by mail-qt1-x84a.google.com with SMTP id w14so8180581qtv.19 for ; Fri, 19 Jun 2020 14:43:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=b+kjGT73WFLdSPC2x8/fMm9a33v5QVaVEC6QcZ94VhU=; b=gH3yzD9+5ACwZS+Xfaw/GijUc5EthXSaHK4+MSZ6k8kSwLmaofP5rBM9xYLtESLeqX /f0NNJFA9Btm9Zq9wQXSi5kq09VQzPb6YjWlNVB85+YFE6ocNDIciVckkm8hzHKqeSXU R1MhWiSIXiwp+iR0B9WTxJ15rG7nBthbmbwV7ee154tKd/+wNt3RqC10WEP4PD22SB0a dA2eSlAhEH6kJvpAXYe27rmgd8OioV1V/ontoq5Nszqcby1zYKXUG+5Rq7KGc26rdY/A VimoS5B6xmZpPa5CpWLNvShX6jX+L7XFD1MzAOsneT3A9uNkNh7M6iQOIqXyN6IHQEVN EP4A== X-Gm-Message-State: AOAM532pcYoY6vSi5E7p9o4KNpNFP9VJYPRLeIVjqJQqkrFB/RyI92ic 2iRZ5fqtL5DxCcswMBxw6btUNBT/di7uIkAVjfX8S1lPNhR+kxhyGdcItGsPJAdzIOfFYGXe3YP BzNNj904Ke7xZTOZmyre6d1RcAjhFNFNW4ULz/2DTWq1e+ZmEt2Z75J4u2wntWsk6QcoxKB4= X-Google-Smtp-Source: ABdhPJwWayJOwJ4sWPK6pwlyDU0IeXr8cTZzT2Jpuld6wJwP4lAbTClvPDd+8O4PhdQluMuubQ3vSGETrDQ1xQ== X-Received: by 2002:a05:6214:aaf:: with SMTP id ew15mr10970465qvb.110.1592602998051; Fri, 19 Jun 2020 14:43:18 -0700 (PDT) Date: Fri, 19 Jun 2020 23:42:52 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-4-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 03/16] abg-ir: elf_symbol: add is_in_ksymtab field To: libabigail@sourceware.org X-Spam-Status: No, score=-22.9 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, gprocida@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 d81de217702b..5766385c8b73 100644 --- a/include/abg-ir.h +++ b/include/abg-ir.h @@ -851,8 +851,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&); @@ -865,17 +866,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; @@ -943,6 +945,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 da3716d503e0..44021132b04d 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -1300,6 +1300,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_; @@ -1314,20 +1315,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), @@ -1338,7 +1341,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; @@ -1384,19 +1388,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. @@ -1443,20 +1458,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; } @@ -1676,6 +1693,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 Fri Jun 19 21:42:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39698 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 1862B3938C24; Fri, 19 Jun 2020 21:43:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1862B3938C24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592603003; bh=MP5iMmhGTZEkmBVsJvuJMEMGDepsLlWrH+zb6wJxKS8=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=UnzqEzCu6N9QF+nbfP9ZKtQ9QfEFBdQM6CsGXDR/4d5TQzQejtwfiD3X8YouJ+Q4g 1RaHXcJWzymYAhwg0w+o1rJyjmY+2ov9VIAF0ZmeBsPXmb70MHIJ8KySLadImLB/5r u6Qx2VpUI5fC6c/qsB+51EHpy8cHeUioF5Ypsmo4= 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 53065388E813 for ; Fri, 19 Jun 2020 21:43:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 53065388E813 Received: by mail-qt1-x849.google.com with SMTP id q21so8170283qtn.20 for ; Fri, 19 Jun 2020 14:43:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=MP5iMmhGTZEkmBVsJvuJMEMGDepsLlWrH+zb6wJxKS8=; b=tAu2cjSNdy2Y6GxvmJn1PlWDsKqK1EnPcmBbTVSW24+nL5EvCA2b5YQtw82TnVldRx /1A2c2uqDNAY3+6soGl5JjE/p/GZJbw3b7cR3O9aw6EGJHEVIwJfqauDe+mK0I1PDI0C /WxuDC7ZJg0fD5qVTEa5kv2JAwjtZ0aYeU36VlxMTVbIqb9HyXC60ljI3scolISi3Fip 5PPyYczmKJA9bbmCOfTA4lmBJIZzqtpoowUKMjG60zw8D5W4fRzQ3qx6Bro5DIlbaTWA gfsUZNfblZfDDtTI3bTaeF9ygKITxcCwcYFpN/BuiILM58vln2QxJ6imWDdUb5nWKqzy wmOA== X-Gm-Message-State: AOAM532/nGM5oOZYWSQ4JDNo9M4MiJOuqI4hd+Bri5BJVgnh7cJ2JjgY kpUubP0iAstHsktwRcDGHrCCHKwir2VVF2NrwxcPxkh3CczTgqHj/RHItKAS0pewHkT8MFCfXuc 5PJWqn+z82pW0r6fxeOi3j89RwTGfdZdTCvuwuauw06n4qM5zQJTsyvC7QBFm3orLTZTXXMA= X-Google-Smtp-Source: ABdhPJyYjvijvRo6McNuv45IY99QT7HCImOt/Ib5N6l/NdGq8kUjc/jQrxuAlnJhKi+i2Xcl0sPjYn9SAi0Uyw== X-Received: by 2002:a05:6214:964:: with SMTP id do4mr11231888qvb.84.1592603000260; Fri, 19 Jun 2020 14:43:20 -0700 (PDT) Date: Fri, 19 Jun 2020 23:42:53 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-5-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 04/16] abg-ir: elf_symbol: add is_suppressed field To: libabigail@sourceware.org X-Spam-Status: No, score=-22.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, gprocida@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. Signed-off-by: Matthias Maennich Reviewed-by: Giuliano Procida --- 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 5766385c8b73..838d3f80695a 100644 --- a/include/abg-ir.h +++ b/include/abg-ir.h @@ -853,7 +853,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&); @@ -877,7 +878,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; @@ -951,6 +953,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 44021132b04d..44529c6617b0 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -1301,6 +1301,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_; @@ -1316,7 +1317,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, @@ -1330,7 +1332,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), @@ -1342,7 +1345,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; @@ -1399,7 +1403,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, @@ -1411,7 +1416,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. @@ -1469,11 +1475,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; } @@ -1701,6 +1708,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 Fri Jun 19 21:42:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39699 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 619DB3898535; Fri, 19 Jun 2020 21:43:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 619DB3898535 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592603006; bh=BT0nIJi6pLi3zCx7vY5LVJFNxHcF2zWQ8zfP3KEG/nM=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=wer3NxKQY/iF2NQKJm+c/Qb7ypBNIW1tpoVqZ1kPbLl05WPiHxtGkkaRj2nDV1qFf WnaQwUEk4derg8eXetTxW/KYZvEcVNMNMMzSMNDoC7y78iDoDgn+kkCYGaOs9wY/m5 LMzahzqhb7djnyPI7VaXhOpmw+2nGvURvyf1LcEI= 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 6062F3938C29 for ; Fri, 19 Jun 2020 21:43:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6062F3938C29 Received: by mail-qt1-x849.google.com with SMTP id y7so8185085qti.8 for ; Fri, 19 Jun 2020 14:43:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=BT0nIJi6pLi3zCx7vY5LVJFNxHcF2zWQ8zfP3KEG/nM=; b=cU0daDgHPigDSLbIZrt6qVjZYIJvPPLtxhfeoDTjRlt7T0MY75C4tn33Mhu6J+R/AE GBrKASdLjmYBgZbM5JOXhWWUsiN4MtXAtAkz/A2UJUtr7ln3p30g+Se/kcfX/OoqaWrn CbNZXxQjuaZIelEDmjl13icLXRfKux/PWekUSFtjAfQdlIcegscGdqI2YU5GfW99j5PO mxiF1Hb+uzJcSN3WIXDCKMwWog6f1qzL47NJ+AjY8PbW9vwjtCkBMoNETYkFzqQjI3IB 1NOgbWfD1wOWkmFcrzWbJ1flua4p5K1svk4LBsXn89yMB30lPSNgwQvT15mIhA1v4/ym +DMQ== X-Gm-Message-State: AOAM530fFxXEqII6Fbl8Ww9Ieo3K6hET4nLGZrDQJwjG/F58HQbDZZqe mxUCbxzitF8WcTuPmzyBXxqBRePzB3+ABS6Mjxg2i9UNXMcE9rRjN5qIrl4VWP8PatUc7AdZgPU u9qeAGPn2wTf6Bm9ovnjcHu7icYipiZv4wOAk5+Zh5ly1R48ey8zntQp9HuM0mz5AQ5L/QHc= X-Google-Smtp-Source: ABdhPJwxOy345swJ++A/bbSEVemru6rrnCuQqKpO7vuy8clX+Z8jN8cOQxTKS+cN+yNIwDnhnZU1iFojEkexfw== X-Received: by 2002:a05:6214:108d:: with SMTP id o13mr10596014qvr.58.1592603002890; Fri, 19 Jun 2020 14:43:22 -0700 (PDT) Date: Fri, 19 Jun 2020 23:42:54 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-6-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 05/16] dwarf-reader split: create abg-symtab-reader.{h, cc} and test case To: libabigail@sourceware.org X-Spam-Status: No, score=-22.4 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, gprocida@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. * include/abg-symtab-reader.h: New header file. * include/Makefile.am: Add new header file abg-symtab-reader.h. * src/Makefile.am: Add new source file abg-symtab-reader.cc. * src/abg-symtab-reader.cc: New source file. * 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 --- include/Makefile.am | 3 ++- include/abg-symtab-reader.h | 39 +++++++++++++++++++++++++++++++++++++ src/Makefile.am | 1 + src/abg-symtab-reader.cc | 36 ++++++++++++++++++++++++++++++++++ tests/Makefile.am | 4 ++++ tests/test-symtab-reader.cc | 30 ++++++++++++++++++++++++++++ 6 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 include/abg-symtab-reader.h create mode 100644 src/abg-symtab-reader.cc create mode 100644 tests/test-symtab-reader.cc diff --git a/include/Makefile.am b/include/Makefile.am index b547525238ec..639906aafe5b 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -25,6 +25,7 @@ abg-version.h \ abg-viz-common.h \ abg-viz-dot.h \ abg-viz-svg.h \ -abg-regex.h +abg-regex.h \ +abg-symtab-reader.h EXTRA_DIST = abg-version.h.in diff --git a/include/abg-symtab-reader.h b/include/abg-symtab-reader.h new file mode 100644 index 000000000000..b61e6399fe93 --- /dev/null +++ b/include/abg-symtab-reader.h @@ -0,0 +1,39 @@ +// -*- Mode: C++ -*- +// +// Copyright (C) 2020 Google, Inc. +// +// This file is part of the GNU Application Binary Interface Generic +// Analysis and Instrumentation Library (libabigail). This library is +// free software; you can redistribute it and/or modify it under the +// terms of the GNU Lesser General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) any +// later version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. + +// You should have received a copy of the GNU Lesser General Public +// License along with this program; see the file COPYING-LGPLV3. If +// not, see . +// +// 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/src/Makefile.am b/src/Makefile.am index 1153a5f8b158..dff17d9c02c1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,6 +41,7 @@ abg-tools-utils.cc \ abg-elf-helpers.h \ abg-elf-helpers.cc \ abg-regex.cc \ +abg-symtab-reader.cc \ $(CXX11_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..1f934d3a7609 --- /dev/null +++ b/src/abg-symtab-reader.cc @@ -0,0 +1,36 @@ +// -*- Mode: C++ -*- +// +// Copyright (C) 2020 Google, Inc. +// +// This file is part of the GNU Application Binary Interface Generic +// Analysis and Instrumentation Library (libabigail). This library is +// free software; you can redistribute it and/or modify it under the +// terms of the GNU Lesser General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) any +// later version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. + +// You should have received a copy of the GNU Lesser General Public +// License along with this program; see the file COPYING-LGPLV3. If +// not, see . +// +// 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/tests/Makefile.am b/tests/Makefile.am index c2d4d1dc5d35..068725326b75 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -50,6 +50,7 @@ runtestkmiwhitelist \ runtestlookupsyms \ runtestreadwrite \ runtestsymtab \ +runtestsymtabreader \ runtesttoolsutils \ $(FEDABIPKGDIFF_TEST) \ $(ZIP_ARCHIVE_TESTS) \ @@ -158,6 +159,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..c2e30d661017 --- /dev/null +++ b/tests/test-symtab-reader.cc @@ -0,0 +1,30 @@ +// -*- Mode: C++ -*- +// +// Copyright (C) 2020 Google, Inc. +// +// This file is part of the GNU Application Binary Interface Generic +// Analysis and Instrumentation Library (libabigail). This library is +// free software; you can redistribute it and/or modify it under the +// terms of the GNU Lesser General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) any +// later version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. + +// You should have received a copy of the GNU Lesser General Public +// License along with this program; see the file COPYING-LGPLV3. If +// not, see . +// +// Author: Matthias Maennich + +/// @file +/// +/// This program tests libabigail's symtab reader. + +#include "lib/catch.hpp" + +#include "abg-symtab-reader.h" + From patchwork Fri Jun 19 21:42:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39700 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 AAA20388F057; Fri, 19 Jun 2020 21:43:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AAA20388F057 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592603010; bh=NSLxqnx28JnM3LSOeTOFP3DTzSWyGvw+o/u0UqLjcgA=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=TQYmS/tU3i60vc+TbdIN3C4JLwezEQcLxUmQCbi2Oa3JbuN443t/LFqawy5g+Aq8r zRa3rUBuck41aODF7RFaYYtsuzta2gjg9FWjSuoY+i3HFKPT2SfSATnp3DfisJF67S PxSFaoqewTsMt+4kL+Rm2JN5J1Bvf/teH9ip7k5Y= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by sourceware.org (Postfix) with ESMTPS id E03763898539 for ; Fri, 19 Jun 2020 21:43:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E03763898539 Received: by mail-yb1-xb49.google.com with SMTP id p22so11500856ybg.21 for ; Fri, 19 Jun 2020 14:43:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=NSLxqnx28JnM3LSOeTOFP3DTzSWyGvw+o/u0UqLjcgA=; b=MWbnrbBjVU+tBwbSMxfz6MYS/Fl09ghUNcInqqLsIyZ0TazUsYqa1IWZpV4MdnagVM fTePAwSdgCaZ4/TBVAqZ/N/8e7giaptNc5wEKWSzRHdcTX+krK5+X3kaWVOgutBzk+8w cksUUTofsu0S0J354bced0et7zuTAp2Thj7rJJlOUBIIzM8VSeJlwRlpX7OP3kDqXD2l hq7TGaVLmvd+PyMggO3CdTkLnHui77wz0JYjS77aZJRB3LfMCqUSC7TBuy1XRoYb/XIw RtYo8lONvb+BOngyIlMklk2/Bztv4mXVaQYSDj1JHji8oKUzJGCRT4zRzcZgluveaFRZ I2RA== X-Gm-Message-State: AOAM532M/bZioMuClzOirgo3ElpjScHin7EyQqbWU65LPhlTG36Uq2Fl yeREeTmedJwRx6OzF35dN8P+DrubImQuobBXXmPunnZRN6rtRFTdTtCjbMnx3D+Mm4MVuYiVzTV bqmjssE1MbWuybLFCKNCieQ9BcCg+IHGtL/OHUt0Hn764VakP6su1UK7TL2tKEVELI8av7qQ= X-Google-Smtp-Source: ABdhPJxTzo03WXho/kDgE487eyZBSWS557bgXE6i8BJrEaJ7nokAtmNmbuwNPgJNXzKh9mo55ZIVxinDsDr8sg== X-Received: by 2002:a25:2d24:: with SMTP id t36mr9323311ybt.426.1592603005326; Fri, 19 Jun 2020 14:43:25 -0700 (PDT) Date: Fri, 19 Jun 2020 23:42:55 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-7-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 06/16] Refactor ELF symbol table reading by adding a new symtab reader 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, gprocida@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::symtab_filter_builder This is a convenient way of building filters with a builder pattern and a fluent interface. Hence, filters can be expressed neatly, expressive and precise. When instantiated, via symtab::make_filter(), the filter_builder is preset with suitable defaults. The filter_builder is convertable to a symtab_filter by passing on the local filter copy and therefore serving the fluent interface. 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. * include/abg-symtab-reader.h (symtab_filter): New class. (symtab_filter_builder): Likewise. (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. * tests/test-symtab-reader.cc (default filter matches anything): New test case. (default filter built with filter_builder matches anything): Likewise. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- include/abg-symtab-reader.h | 371 +++++++++++++++++++++++++++++++++++- src/abg-symtab-reader.cc | 313 ++++++++++++++++++++++++++++++ tests/test-symtab-reader.cc | 23 +++ 3 files changed, 706 insertions(+), 1 deletion(-) diff --git a/include/abg-symtab-reader.h b/include/abg-symtab-reader.h index b61e6399fe93..86335617d46a 100644 --- a/include/abg-symtab-reader.h +++ b/include/abg-symtab-reader.h @@ -27,12 +27,381 @@ #ifndef __ABG_SYMTAB_READER_H__ #define __ABG_SYMTAB_READER_H__ +#include + +#include +#include + +#include "abg-cxx-compat.h" +#include "abg-ir.h" + namespace abigail { - namespace symtab_reader { +class symtab_filter_builder; + +/// 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: + // The symtab_filter_builder helps us to build filters efficiently, hence + // let's be nice and grant access to our internals. + friend class symtab_filter_builder; + + // Default constructor disabling all features. + symtab_filter() {} + + /// 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 + matches(const elf_symbol_sptr& symbol) const; + +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_; +}; + +/// Helper class to provide an attractive interface to build symtab_filters. +/// +/// When constructed, the helper instantiates a default symtab_filter and +/// allows modifications to it via builder pattern / fluent interface. +/// +/// When assigned to a symtab_filter instance, it converts by returning the +/// locally build symtab_filter instance. +/// +/// Example usage: +/// +/// const symtab_filter filter = +/// symtab_filter_builder().functions().kernel_symbols(); +/// +/// In that case we would filter for the conjunction of function symbols that +/// also appear in the ksymtab (i.e. kernel symbols). +class symtab_filter_builder +{ +public: + /// Enable inclusive / exclusive filtering for functions. + symtab_filter_builder& + functions(bool value = true) + { filter_.functions_ = value; return *this; } + + /// Enable inclusive / exclusive filtering for variables. + symtab_filter_builder& + variables(bool value = true) + { filter_.variables_ = value; return *this; } + + /// Enable inclusive / exclusive filtering for public symbols. + symtab_filter_builder& + public_symbols(bool value = true) + { filter_.public_symbols_ = value; return *this; } + + /// Enable inclusive / exclusive filtering for undefined symbols. + symtab_filter_builder& + undefined_symbols(bool value = true) + { filter_.undefined_symbols_ = value; return *this; } + + /// Enable inclusive / exclusive filtering for kernel symbols. + symtab_filter_builder& + kernel_symbols(bool value = true) + { filter_.kernel_symbols_ = value; return *this; } + + /// Convert seamlessly to a symtab_filter instance. + /// + /// We could possibly validate the filter constellations here. For now, we + /// just return the local filter instance. + operator symtab_filter() { return filter_; } + +private: + /// Local symtab_filter instance that we build and eventually pass on. + symtab_filter filter_; +}; + +/// 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 shared_ptr +class symtab; +typedef abg_compat::shared_ptr symtab_sptr; + +/// 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 symtab_sptr tab = symtab::load(elf_handle, env); +/// const symtab_filter filter = tab->make_filter() +/// .public_symbols() +/// .functions(); +/// +/// for (symtab::const_iterator I = tab.begin(filter), E = tab.end(); +/// I != E; ++I) +/// { +/// std::cout << (*I)->get_name() << "\n"; +/// } +/// +/// C++11 and later allows a more brief syntax for the same: +/// +/// for (const auto& symbol : filtered_symtab(*tab, filter)) +/// { +/// std::cout << symbol->get_name() << "\n"; +/// } +/// +/// This uses the filtered_symtab proxy object to capture the filter. +class symtab +{ +public: + typedef abg_compat::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(); } + + /// Obtain a suitable default filter for iterating this symtab object. + /// + /// The symtab_filter_build 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_builder with sensible populated defaults + symtab_filter_builder + 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()); } + + /// 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& + lookup_symbol(const std::string& name) const; + + /// 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& + lookup_symbol(GElf_Addr symbol_addr) const; + + /// 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. + static symtab_sptr + load(Elf* elf_handle, + ir::environment* env, + symbol_predicate is_suppressed = NULL); + + /// Construct a symtab object from existing name->symbol lookup maps. + /// They were possibly read from a different representation (XML maybe). + static symtab_sptr + 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 abg_compat::unordered_map > + name_symbol_map_type; + name_symbol_map_type name_symbol_map_; + + /// Lookup map name->symbol + typedef abg_compat::unordered_map + addr_symbol_map_type; + addr_symbol_map_type addr_symbol_map_; + + /// 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 + load_(Elf* elf_handle, ir::environment* env, symbol_predicate is_suppressed); + + /// 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 + 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 diff --git a/src/abg-symtab-reader.cc b/src/abg-symtab-reader.cc index 1f934d3a7609..c98b9174490c 100644 --- a/src/abg-symtab-reader.cc +++ b/src/abg-symtab-reader.cc @@ -1,5 +1,6 @@ // -*- Mode: C++ -*- // +// Copyright (C) 2013-2020 Red Hat, Inc. // Copyright (C) 2020 Google, Inc. // // This file is part of the GNU Application Binary Interface Generic @@ -24,7 +25,18 @@ /// /// This contains the definition of the symtab reader +#include +#include + +#include "abg-cxx-compat.h" +#include "abg-elf-helpers.h" +#include "abg-fwd.h" +#include "abg-internal.h" +#include "abg-tools-utils.h" + +ABG_BEGIN_EXPORT_DECLARATIONS #include "abg-symtab-reader.h" +ABG_END_EXPORT_DECLARATIONS namespace abigail { @@ -32,5 +44,306 @@ namespace abigail namespace symtab_reader { +/// symtab_filter implementations + +bool +symtab_filter::matches(const elf_symbol_sptr& 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 + +symtab_filter_builder +symtab::make_filter() const +{ + symtab_filter_builder builder; + builder.public_symbols(); + if (is_kernel_binary_) + builder.kernel_symbols(); + return builder; +} + +const elf_symbols& +symtab::lookup_symbol(const std::string& name) const +{ + static const elf_symbols empty_result; + const name_symbol_map_type::const_iterator it = name_symbol_map_.find(name); + if (it != name_symbol_map_.end()) + { + return it->second; + } + return empty_result; +} + +const elf_symbol_sptr& +symtab::lookup_symbol(GElf_Addr symbol_addr) const +{ + static const elf_symbol_sptr empty_result; + const addr_symbol_map_type::const_iterator 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; + +symtab_sptr +symtab::load(Elf* elf_handle, + ir::environment* env, + symbol_predicate is_suppressed) +{ + ABG_ASSERT(elf_handle); + ABG_ASSERT(env); + + symtab_sptr result(new symtab); + if (!result->load_(elf_handle, env, is_suppressed)) + return symtab_sptr(); + + return result; +} + +symtab_sptr +symtab::load(string_elf_symbols_map_sptr function_symbol_map, + string_elf_symbols_map_sptr variables_symbol_map) +{ + symtab_sptr result(new symtab); + if (!result->load_(function_symbol_map, variables_symbol_map)) + return symtab_sptr(); + + return result; +} + +symtab::symtab() : is_kernel_binary_(false), has_ksymtab_entries_(false) {} + +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); + abg_compat::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* name_str = + elf_strptr(elf_handle, symtab_sheader.sh_link, sym->st_name); + + // no name, no game + if (!name_str) + 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. + const std::string name = name_str; + 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 name_symbol_map_type::iterator 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 std::pair result = + addr_symbol_map_.insert( + std::make_pair(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 (abg_compat::unordered_set::const_iterator + it = exported_kernel_symbols.begin(), + en = exported_kernel_symbols.end(); + it != en; ++it) + { + const name_symbol_map_type::const_iterator r = + name_symbol_map_.find(*it); + if (r == name_symbol_map_.end()) + continue; + + for (elf_symbols::const_iterator sym_it = r->second.begin(), + sym_end = r->second.end(); + sym_it != sym_end; ++sym_it) + { + if ((*sym_it)->is_public()) + (*sym_it)->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; +} + +bool +symtab::load_(string_elf_symbols_map_sptr function_symbol_map, + string_elf_symbols_map_sptr variables_symbol_map) + +{ + if (function_symbol_map) + for (string_elf_symbols_map_type::const_iterator + it = function_symbol_map->begin(), + end = function_symbol_map->end(); + it != end; ++it) + { + symbols_.insert(symbols_.end(), it->second.begin(), it->second.end()); + ABG_ASSERT(name_symbol_map_.insert(*it).second); + } + + if (variables_symbol_map) + for (string_elf_symbols_map_type::const_iterator + it = variables_symbol_map->begin(), + end = variables_symbol_map->end(); + it != end; ++it) + { + symbols_.insert(symbols_.end(), it->second.begin(), it->second.end()); + ABG_ASSERT(name_symbol_map_.insert(*it).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/tests/test-symtab-reader.cc b/tests/test-symtab-reader.cc index c2e30d661017..383166c88875 100644 --- a/tests/test-symtab-reader.cc +++ b/tests/test-symtab-reader.cc @@ -28,3 +28,26 @@ #include "abg-symtab-reader.h" +namespace abigail +{ + +using symtab_reader::symtab_filter; +using symtab_reader::symtab_filter_builder; + +TEST_CASE("default symtab_filter matches anything", + "[symtab_reader, symtab_filter]") +{ + const symtab_filter filter; + const elf_symbol_sptr symbol; // not initialized! + CHECK(filter.matches(symbol)); +} + +TEST_CASE("default symtab_filter built with filter_builder matches anything", + "[symtab_reader, symtab_filter, symtab_filter_builder]") +{ + const symtab_filter filter = symtab_filter_builder(); + const elf_symbol_sptr symbol; // not initialized! + CHECK(filter.matches(symbol)); +} + +} // namespace abigail From patchwork Fri Jun 19 21:42:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39701 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 0A3693939C22; Fri, 19 Jun 2020 21:43:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A3693939C22 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592603011; bh=Np9iVD7rYrbKVF2uBgPT38kO5MecSZUhYN+azv8Qke4=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=bx7cCVSFqkBt+uTcnMRQ9Kv/x01ESXwXWGFSJdD4KS/GdiSOyDH3g39WcPt3U0xYd iR6RZxyRz4lCqhfO2NOdiGG3TMRoP8GQa+XYPaI1f7q7pYtPK363uD3wbiBkBnSiTJ +Ys8+J0ZKqn61kLAOJkxwMsoyKwxA6NFJndrzOLU= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by sourceware.org (Postfix) with ESMTPS id 2A9873898535 for ; Fri, 19 Jun 2020 21:43:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2A9873898535 Received: by mail-yb1-xb4a.google.com with SMTP id o140so11508605yba.16 for ; Fri, 19 Jun 2020 14:43:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Np9iVD7rYrbKVF2uBgPT38kO5MecSZUhYN+azv8Qke4=; b=kQ6xCdUKZwx7NtA2kkHSfWuS21sHnUKuonykXYenFQ5KWDL8FiYjCPr60PLTEHG9xD l13toKUA9bLu5wu5xUYa1asqo6ghapugCMz+GNO3y0U4JRRouxKpd/hBKSxeYu+CXE9t 52v0cO9kCeR51uFcnebPMCbweQyOkFJQ84szbiSg4prNk66BGwX2IM6rpjvaHvalyWk9 xJx649w0N1NOmttPpEWOtBr/0yVsEPvYboP89HpDWug4aXMNEB0LXykNP3o/rp7qwgeg 22VhTEIUgIBJAM6Tv7Ss12AXKrbeIdxuJMVtvhwXK8jbo3R3gz35aypKm6Otk3m7xY/r yMDQ== X-Gm-Message-State: AOAM531kHGSIlRWixMBJQnCs0EymQDZ0PJOuMinTqB8s9ZyzoUpj/6O+ z2q3pTGdnp7SSZJrSUeO7cCNTNI6YtvFTS4xp67xrvcU1qQKJYWlxgJqAU5KeSCIMvgJKhJI2xJ Q4DImg1eNDAk1MErid7e/UfxnlK+4uu/kTWnoiw9KHLBItaf1YdxeulcV/nKg/aCTffsQJDU= X-Google-Smtp-Source: ABdhPJz9uU6edlXrjrBCjbgfAXmK8FFbU9VAxf0IRt18zSBKzTh6mbExOsi+pAIHQjjrfXdwIpXFQutpgZz2YQ== X-Received: by 2002:a25:18d5:: with SMTP id 204mr5370135yby.209.1592603007586; Fri, 19 Jun 2020 14:43:27 -0700 (PDT) Date: Fri, 19 Jun 2020 23:42:56 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-8-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 07/16] Integrate new symtab reader into corpus and read_context To: libabigail@sourceware.org X-Spam-Status: No, score=-23.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, gprocida@google.com, kernel-team@android.com Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" While reading the corpus in the read_context, also load the new type symtab object side-by-side and set it accordingly in the resulting corpus. This is still side by side and passive code that gets active in the following changes. This is applicable for the dwarf reader as well as for the reader that consumes XML. * include/abg-corpus.h (corpus::set_symtab): New method declaration. (corpus::get_symtab): New method declaration. * include/abg-fwd.h (symtab_reader::symtab_sptr): New forward declaration. * src/abg-corpus-priv.h (corpus::priv::symtab_): New data member. * src/abg-corpus.cc (corpus::set_symtab): Likewise. (corpus::get_symtab): Likewise. * src/abg-dwarf-reader.cc (read_context::symtab_): New data member. (read_context::initialize): reset symtab_ as well (read_context::symtab): new method that loads a symtab on first access and returns it. (read_debug_info_into_corpus): also set the new symtab object on the current corpus. (read_corpus_from_elf): Also determine (i.e. load) the new symtab object and contribute to the load status. * src/abg-reader.cc (read_corpus_from_input): also set the new type symtab when reading from xml. * tests/test-symtab.cc: Add test assertions. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- include/abg-corpus.h | 6 ++++ include/abg-fwd.h | 8 ++++++ src/abg-corpus-priv.h | 2 ++ src/abg-corpus.cc | 9 ++++++ src/abg-dwarf-reader.cc | 27 ++++++++++++++++++ src/abg-reader.cc | 3 ++ tests/data/test-symtab/basic/no_debug_info.c | 2 +- tests/data/test-symtab/basic/no_debug_info.so | Bin 15360 -> 15544 bytes tests/test-symtab.cc | 15 ++++------ 9 files changed, 61 insertions(+), 11 deletions(-) diff --git a/include/abg-corpus.h b/include/abg-corpus.h index 410a9c2459e6..b94926996cde 100644 --- a/include/abg-corpus.h +++ b/include/abg-corpus.h @@ -169,6 +169,12 @@ public: bool operator==(const corpus&) const; + void + set_symtab(symtab_reader::symtab_sptr); + + const symtab_reader::symtab_sptr& + get_symtab() const; + void set_fun_symbol_map(string_elf_symbols_map_sptr); diff --git a/include/abg-fwd.h b/include/abg-fwd.h index f6e0c5b286a1..f6e3969a6f36 100644 --- a/include/abg-fwd.h +++ b/include/abg-fwd.h @@ -1331,6 +1331,14 @@ typedef vector suppressions_type; } // end namespace suppr +namespace symtab_reader +{ + +class symtab; +typedef abg_compat::shared_ptr symtab_sptr; + +} // end namespace symtab_reader + void dump(const decl_base_sptr, std::ostream&); diff --git a/src/abg-corpus-priv.h b/src/abg-corpus-priv.h index ee8c823964e7..5c1e915ad2f3 100644 --- a/src/abg-corpus-priv.h +++ b/src/abg-corpus-priv.h @@ -32,6 +32,7 @@ #include "abg-internal.h" #include "abg-regex.h" #include "abg-sptr-utils.h" +#include "abg-symtab-reader.h" namespace abigail { @@ -700,6 +701,7 @@ struct corpus::priv string_elf_symbols_map_sptr undefined_var_symbol_map; elf_symbols sorted_var_symbols; elf_symbols sorted_undefined_var_symbols; + symtab_reader::symtab_sptr symtab_; string_elf_symbols_map_sptr fun_symbol_map; string_elf_symbols_map_sptr undefined_fun_symbol_map; elf_symbols sorted_fun_symbols; diff --git a/src/abg-corpus.cc b/src/abg-corpus.cc index 9e90b99473d3..94702047dd82 100644 --- a/src/abg-corpus.cc +++ b/src/abg-corpus.cc @@ -38,6 +38,7 @@ ABG_BEGIN_EXPORT_DECLARATIONS #include "abg-ir.h" #include "abg-reader.h" #include "abg-sptr-utils.h" +#include "abg-symtab-reader.h" #include "abg-tools-utils.h" #include "abg-writer.h" @@ -905,6 +906,14 @@ corpus::operator==(const corpus& other) const && j == other.get_translation_units().end()); } +void +corpus::set_symtab(symtab_reader::symtab_sptr symtab) +{priv_->symtab_ = symtab;} + +const symtab_reader::symtab_sptr& +corpus::get_symtab() const +{ return priv_->symtab_; } + /// Setter of the function symbols map. /// /// @param map a shared pointer to the new function symbols map. diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 213638102230..d7b73adb4874 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -50,6 +50,7 @@ #include "abg-suppression-priv.h" #include "abg-corpus-priv.h" #include "abg-elf-helpers.h" + #include "abg-internal.h" // @@ -57,6 +58,7 @@ ABG_BEGIN_EXPORT_DECLARATIONS #include "abg-dwarf-reader.h" #include "abg-sptr-utils.h" +#include "abg-symtab-reader.h" #include "abg-tools-utils.h" ABG_END_EXPORT_DECLARATIONS @@ -2277,6 +2279,9 @@ public: bool drop_undefined_syms_; read_context(); +private: + mutable symtab_reader::symtab_sptr symtab_; + public: /// Constructor of read_context. @@ -2426,6 +2431,8 @@ public: dt_soname_.clear(); elf_architecture_.clear(); + symtab_.reset(); + clear_per_translation_unit_data(); memset(&offline_callbacks_, 0, sizeof(offline_callbacks_)); @@ -5577,6 +5584,22 @@ public: return symbol; } + const symtab_reader::symtab_sptr& + symtab() const + { + using namespace abg_compat::placeholders; + if (!symtab_) + symtab_ = symtab_reader::symtab::load( + elf_handle(), options_.env, + abg_compat::bind(&read_context::is_elf_symbol_suppressed, this, _1)); + if (!symtab_) + { + std::cerr << "Symbol table of '" << elf_path_ + << "' could not be loaded\n"; + } + return symtab_; + } + /// Getter for a pointer to the map that associates the address of /// an entry point of a function with the symbol of that function. /// @@ -15482,6 +15505,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() @@ -16738,6 +16762,9 @@ read_corpus_from_elf(read_context& ctxt, status& status) status |= STATUS_NO_SYMBOLS_FOUND; } + if (!ctxt.symtab() || !ctxt.symtab()->has_symbols()) + status |= STATUS_NO_SYMBOLS_FOUND; + if (// If no elf symbol was found ... status & STATUS_NO_SYMBOLS_FOUND // ... or if debug info was found but not the required alternate diff --git a/src/abg-reader.cc b/src/abg-reader.cc index eb74659f1d46..188c23d2e5cd 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -47,6 +47,7 @@ ABG_BEGIN_EXPORT_DECLARATIONS #include "abg-libxml-utils.h" #include "abg-reader.h" #include "abg-corpus.h" +#include "abg-symtab-reader.h" #ifdef WITH_ZIP_ARCHIVE #include "abg-libzip-utils.h" @@ -1973,6 +1974,8 @@ read_corpus_from_input(read_context& ctxt) // Note that it's possible that both fn_sym_db and var_sym_db // are nil, due to potential suppression specifications. That's // fine. + corp.set_symtab(symtab_reader::symtab::load(fn_sym_db, var_sym_db)); + if (fn_sym_db) { corp.set_fun_symbol_map(fn_sym_db); diff --git a/tests/data/test-symtab/basic/no_debug_info.c b/tests/data/test-symtab/basic/no_debug_info.c index 5bb380ba0db8..8ac09016eb4d 100644 --- a/tests/data/test-symtab/basic/no_debug_info.c +++ b/tests/data/test-symtab/basic/no_debug_info.c @@ -1 +1 @@ -// empty! +void exported_function(){} diff --git a/tests/data/test-symtab/basic/no_debug_info.so b/tests/data/test-symtab/basic/no_debug_info.so index 827c1eee3e4e8f326af7e360ea444627ee59bee6..0b2310196a2a3a67369f80eb29e9ecefc22dc704 100755 GIT binary patch delta 1147 zcmZWoOH31C5T3tV9tB!<%cHzPw**bm(Cq`-Vl{1*M`I!w5)LMqVl09tfFOpVCM?DW zhJ&qhFdTd|AsW4SASPgpk#I5|(39dxV>oy)f(G?Kg0tN&N}SF7-_HE=`e*)Mj?a%L z?3Q^iY*PsQV1N*mfh8HV<=OS>j$NNT<1l0~Rmw`HB*SdRXEwQVUGVEvX&Z5vSu2jN zj>ggf#Ek7W;t0FD|IOD}WzFr0h4_JvUAv{Vajf89D27U`EMg^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: 39702 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 86B963938C27; Fri, 19 Jun 2020 21:43:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 86B963938C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592603013; bh=hFGHv0btm38Lq30pU4uLSpCMW0IgYfht0LTMMnmTvFg=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=JGR79+EWd83EsX2JZ43DHbamc4MbMHrOJISH905ulA/uSX9xgaz/4WjxWUTxKFkOQ UbGwzepgfSPBNQLSl4I5bbhjCgnpM9WQpkWikcJq40igvb5X0Mn77LcjxVZv0hynZJ BEyUHEVZiSnAaoTGNzw0Z3IohIACmzkyzlLTJaDU= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by sourceware.org (Postfix) with ESMTPS id 4CDAA3939C21 for ; Fri, 19 Jun 2020 21:43:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4CDAA3939C21 Received: by mail-yb1-xb4a.google.com with SMTP id e82so11552577ybh.12 for ; Fri, 19 Jun 2020 14:43:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=hFGHv0btm38Lq30pU4uLSpCMW0IgYfht0LTMMnmTvFg=; b=Q6G8m+j7XHh41gXhQ0Vt4n2d2om+UEQZwKxKqJTIz+Zsj3uF6XF+nnvlJpwfx1HrRl L8DWpRAckwuANJTduVHyceHPTW2GYpsTAJILjo5hPmDeC6QIOxFAymNfNhlpWN7cG6CY Prjc/7gY+dIGDJEiIwfz6bVZ1kEOoH2VAQ8maHzOCgeDN02C9jM4SkDpp0525ex6IfcA ejkQoHPg/v35BymOd0rRbAZ2+SdtQBqmX5StiSkr47lQZ2bDgzePLHjU9hVH4+WCEpwF yKiYVVBnEfbe863OD1YYjg+Qboq5xhW0h7xOciK3qr+LCgt3ejt5qe56ml9yh1w/M/wS x4eg== X-Gm-Message-State: AOAM5321Kcs8XCwnQAH7G6NnDvuK63EsO9tGdFhKu+Y+d6EcNNSGTWXN 3WEwf7Ift7DqDXPt/RDcINJSVPTLB9BOechcfQyIZN6ty+nrohRjdl9kWaoXIqGyo19SBhLgbFg tqtuB05JnB0FfRACsTo2CvLY/FYBkhOqXcJz6sdyUyjFY2j2GJfFjqoAO5LhOir6zGGyB0J0= X-Google-Smtp-Source: ABdhPJzTNr+TWAUR9CxDeUMj31t5EV5SmTWvabb4N93D25lcw0HcDUT+NvjWje7p/B4xW35em04tz/R3Sb0nxg== X-Received: by 2002:a05:6902:50b:: with SMTP id x11mr10145167ybs.71.1592603009805; Fri, 19 Jun 2020 14:43:29 -0700 (PDT) Date: Fri, 19 Jun 2020 23:42:57 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-9-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 08/16] corpus: make get_(undefined_)?_(var|fun)_symbols use the new symtab To: libabigail@sourceware.org X-Spam-Status: No, score=-23.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, gprocida@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 aliases. * tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: update test data. Signed-off-by: Matthias Maennich Reviewed-by: Giuliano Procida --- src/abg-corpus-priv.h | 21 +- src/abg-corpus.cc | 242 +++++++----------- src/abg-writer.cc | 38 ++- .../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 5c1e915ad2f3..ad96f260aa89 100644 --- a/src/abg-corpus-priv.h +++ b/src/abg-corpus-priv.h @@ -699,13 +699,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 @@ -727,6 +723,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) @@ -746,6 +747,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 94702047dd82..6d4bedfd57b7 100644 --- a/src/abg-corpus.cc +++ b/src/abg-corpus.cc @@ -453,6 +453,88 @@ 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) + { + const symtab_reader::symtab_filter filter = + symtab_->make_filter().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) + { + const symtab_reader::symtab_filter filter = symtab_->make_filter() + .functions() + .undefined_symbols() + .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) + { + const symtab_reader::symtab_filter filter = + symtab_->make_filter().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) + { + const symtab_reader::symtab_filter filter = symtab_->make_filter() + .variables() + .undefined_symbols() + .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). /// @@ -988,104 +1070,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. /// @@ -1125,65 +1124,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 ce0bae2d5cfd..c5be11b26072 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -1693,26 +1693,42 @@ 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_suppressed()) + continue; - emitted = true; + if (sym.is_in_ksymtab() != s->is_in_ksymtab()) + continue; + + aliases.push_back(s->get_id_string()); } - return emitted; + if (!aliases.empty()) + { + out << " alias='"; + std::string separator; + for (std::vector::const_iterator it = aliases.begin(), + end = aliases.end(); + it != end; ++it) + { + out << separator << *it; + 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 755ea6dc433e..d5af7183095f 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 Fri Jun 19 21:42:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39703 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 F05E7388E813; Fri, 19 Jun 2020 21:43:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F05E7388E813 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592603016; bh=UX8Xvewkh7Z3Ax3SRLewZ/WvOFpayBKI4sNh3OPkJ/k=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=SKH+ZBoGZJHAeWaMHK2XGHFecB89l0RMM0/J1bFYCkQXC8Ae0mlv3NDMTON4+aU15 X9AugyWUwXsCpL9MGPnjo81AVBaMS6WNKQR+LHukyqHD1WB3j207L4J1OTHdpfi/na J9RmVQCBkL1hNWYA9dSTARMzcgdtDOxjAL7r9DAM= 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 73A4C388F057 for ; Fri, 19 Jun 2020 21:43:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 73A4C388F057 Received: by mail-qv1-xf49.google.com with SMTP id h4so7812859qvr.21 for ; Fri, 19 Jun 2020 14:43:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=UX8Xvewkh7Z3Ax3SRLewZ/WvOFpayBKI4sNh3OPkJ/k=; b=OZCxNXgv94A5yTtQJSW/OBEfEBHUZyjKneNn/7LJES5lGojCSRkk/JkmEun8BBsdU3 KkxS2aBM1+FcLDsZE62ZTos+46dHATL/xqxeyXeUyk8euw6n2PYa1hrddqrtqEpoaGuF mMp5uAldAOydorrMHcUAaEXvJHc79Em79qeUusnLhzTCiqSXcm1DYr4j+b6egzdFpjct v09okTtf8Sfe7qgmWYTlSm7E/kfzb6fNj5TRguUi1g/PXchYr2TP1MxDo0+Q5ps1nkxv opeCkMV9rWAw7a5vB5MGIIQWDIe9jQGqRtJuQGST0GxeHjm8HGow1UDsZ0R/m4996j32 DnKg== X-Gm-Message-State: AOAM533lXpbZZbIGOgXa8DvSDCMQIb+PAIQ5qzq5HN1zAsMnDCnBf4Hh EKElgogjbH4WXWyAmyNb1EL8bJz0qN4TXOeheB3lWrZm1lEnx5ElAcbLAnxSVZFDxQti96rXi9H 3UyjJoWH9zhfGqtMnacACdyU8Hrumt9N2K2yKxgvYyqa1AbSfkGbB+YKt9axGs9kmt1ioitg= X-Google-Smtp-Source: ABdhPJzm+JeCOFj2vRS2ovimJ/+goMjVAwEAceDZ/+pnmhWzAykfJ2jSOnx7vMUdnFJ5tXQA8V3XzsgKrr6+ew== X-Received: by 2002:a0c:b542:: with SMTP id w2mr11093221qvd.181.1592603012009; Fri, 19 Jun 2020 14:43:32 -0700 (PDT) Date: Fri, 19 Jun 2020 23:42:58 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-10-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 09/16] corpus: make get_unreferenced_(function|variable)_symbols use the new symtab To: libabigail@sourceware.org X-Spam-Status: No, score=-22.9 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, gprocida@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 | 261 ++++++++++++++++++++---------------------- 2 files changed, 131 insertions(+), 143 deletions(-) diff --git a/src/abg-corpus-priv.h b/src/abg-corpus-priv.h index ad96f260aa89..f2e895bf1e7d 100644 --- a/src/abg-corpus-priv.h +++ b/src/abg-corpus-priv.h @@ -702,8 +702,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 @@ -725,8 +723,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, @@ -738,9 +738,6 @@ public: pub_type_pretty_reprs_() {} - void - build_unreferenced_symbols_tables(); - type_maps& get_types(); @@ -753,12 +750,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 6d4bedfd57b7..0f5d51820891 100644 --- a/src/abg-corpus.cc +++ b/src/abg-corpus.cc @@ -317,132 +317,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() @@ -494,6 +368,66 @@ 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; + 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; + } + + symtab_reader::symtab_filter filter = + symtab_->make_filter().functions(); + for (symtab_reader::symtab::const_iterator iter = + symtab_->begin(filter); + iter != symtab_->end(); iter++) + { + const elf_symbol_sptr& symbol = *iter; + 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 (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(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 @@ -535,6 +469,67 @@ 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; + elf_symbol_sptr sym; + + for (vector::const_iterator f = vars.begin(); + f != vars.end(); ++f) + if ((sym = (*f)->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; + } + + symtab_reader::symtab_filter filter = + symtab_->make_filter().variables(); + for (symtab_reader::symtab::const_iterator iter = + symtab_->begin(filter); + iter != symtab_->end(); iter++) + { + const elf_symbol_sptr& symbol = *iter; + 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 (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(symbol); + } + } + } + } + return *unrefed_var_symbols; +} + + /// Getter of the set of pretty representation of types that are /// reachable from public interfaces (global functions and variables). /// @@ -1366,12 +1361,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. @@ -1384,12 +1374,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 Fri Jun 19 21:42:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39704 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 46D20389852E; Fri, 19 Jun 2020 21:43:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 46D20389852E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592603017; bh=XjBPJTOqn+i4IrybqcqcmecLSGS9G4R4yGHP46Cjolc=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Jk9u4NUIKHkjGDPU5mHov/iQig7Fy3aV52vR7hBim2Wfqg5lzfYpyTSrndEEnfjC7 ewJ3iLcpwi6AzQ850FbXNmQEPAA9ZzMkq50hnuHwBVjDHIuaMYdRlVAX4RJY7cWjXW NU+F5XlFj1lJbVej5uKXu8vdfvHoeeHqpPoSnT7M= 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 09B7A388F057 for ; Fri, 19 Jun 2020 21:43:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 09B7A388F057 Received: by mail-qt1-x84a.google.com with SMTP id o11so8151862qti.23 for ; Fri, 19 Jun 2020 14:43:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=XjBPJTOqn+i4IrybqcqcmecLSGS9G4R4yGHP46Cjolc=; b=i+iKfmEwEEm1v84gZCUOebZw495ZgLFiKdJ6mLZqOr2lfn3kInT9CDsPCbskFsPV9T K0XOt1CCUQM8bu9RbR8jUMf1C12fkT8cj5pzcS9sMpXaV8C1bHrHD2Iuk4x4+HufUjrn TqwpMUVTROe3KcYXxwczXT7TFVduT2TX+609sOXoE/P/gyhYpHJc4zCCMrkKcRw20EpY otWnKUf7pN7YQP2HWdEfRFL5Xge1Or3BbeM5nM87zdaOy9+6DXqOITNT4jLw403UQoZd iPXWLqpvJa02BglWRwtgH1y5gMnjJ8hbevmMIOLU98TER0EPe25Qu0oR++pXmwtE3sij Xfqw== X-Gm-Message-State: AOAM531BF6qbkOnc9OMN7XdcC+6euplsxLmNtd7qbQk6Q6oZ2BRLt9zv 0F5ppkHnGfGfs4r8xdsfrmRiA1QD7DADTVdAPWvfm7kGZB2H9/aLDs1QCUxm0uKt7VHYyoJqm3e Q6W+KZmJ9wo/Yo5lrsoo6ygTBmFipzSrMzXYq6kJsoTRR3HVzDhEH26WWxmIX+XK/BvRzWw4= X-Google-Smtp-Source: ABdhPJynRXuG4V+fk15+YQZijlBRzh4uLPsjfLeTNi5SFibxnLyoLWo2JF69txh1thRAuksDbtoePpNg0JgV/w== X-Received: by 2002:ad4:4b33:: with SMTP id s19mr10160710qvw.211.1592603014275; Fri, 19 Jun 2020 14:43:34 -0700 (PDT) Date: Fri, 19 Jun 2020 23:42:59 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-11-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 10/16] abg-reader: avoid using the (var|function)_symbol_map 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, gprocida@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 | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/abg-reader.cc b/src/abg-reader.cc index 188c23d2e5cd..313639fddff0 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -1150,8 +1150,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); @@ -2884,8 +2883,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; @@ -2904,20 +2902,13 @@ 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 (elf_symbols::const_iterator symbol = symbols.begin(); + symbol != symbols.end(); ++symbol) + if ((*symbol)->get_id_string() == sym_id) + return *symbol; } return nil; @@ -3168,8 +3159,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); @@ -3400,8 +3390,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 Fri Jun 19 21:43:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39705 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 8E505389852E; Fri, 19 Jun 2020 21:43:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E505389852E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592603019; bh=OC+BIycxlcFUwB4bOxd3rq5TaMXAW4XlB9hJNq3+gMk=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=RQPoSDgeDXvgztb+RYMaHtfGiX8Z6eef1ivqAgr38faG83FS7u2YsPRcDDJlFad0D +ikyozoR8uszr7/fGTh69A8WPLcr57ZGHqnPbpEqVskFXz5KykWm/BEahk9jNT11aj WGl1WHPC+2wH9/o3bpgBJeKL6mfEe3qqfmOcTI5k= 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 C7EF7388F057 for ; Fri, 19 Jun 2020 21:43:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C7EF7388F057 Received: by mail-qt1-x849.google.com with SMTP id o11so8151901qti.23 for ; Fri, 19 Jun 2020 14:43:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=OC+BIycxlcFUwB4bOxd3rq5TaMXAW4XlB9hJNq3+gMk=; b=ANY8X/+sra+Bjk5m7OcAFUTPHZ4BWWf/Lnf0Nu6PrynAWlKMTduJLr3U35hTr9ks3y f4+6ljOceXCEaW/kzp7mgtzIoW8ZljVfFnZ8Nv2x56XO7/gU9mUwoSKKm7yAbXZof1J0 AnzsDEeIgDJmIguk/v+O+Q/Ven42W5Z4q+7PiaYemOjaROwRKGp5Xpr8LLqP3XZhjQKI TzxB7EdU912rHOYAErX7P5Gp0Dxi5vPVStJsD80UjyN6oiRwSLq1z5CNKSBE1neZZA43 yD3p9xYz+MNURzDJU/eEBv4ooLhRFIdKCM/pUd3xO/iuWtgD8pyT8QDozkdYtvqifA3u v1xg== X-Gm-Message-State: AOAM533JtQ0N+TpJLbxCrmIdwrMD8ijwtLKC5iSOaMzAlNjpAZJKT6Ui TNcWa8ZAR5n2QtS5IW8729wDk/xfWETFmby/Jssyu0K23CczFg9CWlHiJ3GjWWGXMo50qy75MJj 6iVMRSyySbwiY+bUz3u4jE73dJ4ca/gwy00W5kt5owhaEk5R6LAK0WXRBygzV8ypC2FZtrio= X-Google-Smtp-Source: ABdhPJwXD6BxCF/6UNJnrs7If14LSAnaw6gle+wvsQsvVj2OXH/ICSRQQCR75/A1OzBh+KvakYGmRKrEWuVoYQ== X-Received: by 2002:a0c:e710:: with SMTP id d16mr11166352qvn.158.1592603016404; Fri, 19 Jun 2020 14:43:36 -0700 (PDT) Date: Fri, 19 Jun 2020 23:43:00 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-12-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 11/16] dwarf-reader: read_context: use new symtab in *_symbols_is_exported To: libabigail@sourceware.org X-Spam-Status: No, score=-22.3 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, gprocida@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 d7b73adb4874..87cf34b2e5b7 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -5515,11 +5515,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; @@ -5528,16 +5528,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(); } @@ -5555,11 +5547,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; @@ -5568,16 +5560,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 Fri Jun 19 21:43:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39707 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 314883939C22; Fri, 19 Jun 2020 21:43:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 314883939C22 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592603025; bh=a6a1hpuUEoIYtEJ4b28XLYhd/3fOiw9yxbk7tMqkrNY=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=UQ+GM2CwW5U9WqIOjvOkHLsS3rTwhm1zpNua1QkBBEI4kNuOyEP9apMY0GgwS1I5G JQMbDHGNJeKE701YjwT0DLj9ShI+SKfoPbXRdTfRIjKOpHp7PfIeXJxjcysxBTht25 Cg/I0Fl05D6CBuNvq9DNZNrBJWMDFcNjWfgkM8gY= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by sourceware.org (Postfix) with ESMTPS id 28AE23898535 for ; Fri, 19 Jun 2020 21:43:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 28AE23898535 Received: by mail-yb1-xb49.google.com with SMTP id a188so11567640ybg.20 for ; Fri, 19 Jun 2020 14:43:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=a6a1hpuUEoIYtEJ4b28XLYhd/3fOiw9yxbk7tMqkrNY=; b=AgEaG41evk2IfGE1T57DEB6E4qH+HEMz9M9a/yKNU1xXtjzTUm+uO0wL9Xkpq7cZMi kmROqME4rTn0sxLsAWo4EjIFeBnQoAEVxwDEMgU1rQOrGmnaE66ZuUk7CHbA3mS7aHFt BANtcY+Bis+a2qMhzeSiPkpXsoRAZ6s8TvpvNqoC6C/dEcdn8Ggqdwc4+0L4iW8KhHHb ctrn/wy3cEf8Ip6S4/MHZOnbuZzsMJTLUlQdgFjv+Zse45L6bx/oQSVkZ4c/qWB/S2eN KlqZid+Vq0wSP8py5l+skcadTcW5RbNudqRCBFU57J+fQPUlARXqL9ZVIfT6C8tmPDho LWYg== X-Gm-Message-State: AOAM531IJoCrN9Dy4yp5L10uZNNLWAFqq1ALNJjzxV3d0zAijpWd/wO6 Ygo1Tizw+N95ynpfF9+y4hGFy9GSnzAigS7NSwK6HqJZsLO1BYEoUNgy+yLyOOTPvU/B+nMUFmx mExKzoa862LZnDtrGsk6xa5leDg+wIOEU8phxPj/E3cEAG+lYg3YZaK4tgY6mJ5H1wATDw7A= X-Google-Smtp-Source: ABdhPJzE85HycRovQHLldoWLLAciLSAw+zOqKADEc1sVm4Bw8Xy43hVzRKi/ACTz8RuzXSDrT2bNZ9GhF0Aolw== X-Received: by 2002:a25:81c9:: with SMTP id n9mr9871927ybm.385.1592603018567; Fri, 19 Jun 2020 14:43:38 -0700 (PDT) Date: Fri, 19 Jun 2020 23:43:01 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-13-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 12/16] Switch kernel stuff over to new symtab and drop unused code 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, 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, gprocida@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 | 1194 +-------------------------------------- 1 file changed, 22 insertions(+), 1172 deletions(-) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 87cf34b2e5b7..2d39596f2712 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -2165,26 +2165,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 @@ -2267,10 +2247,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_; @@ -2369,15 +2345,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; @@ -2423,10 +2390,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(); @@ -5070,97 +5033,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. /// @@ -5256,7 +5128,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; @@ -5418,92 +5290,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 @@ -5603,20 +5389,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. /// @@ -5630,19 +5402,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. @@ -5707,130 +5466,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 @@ -5846,28 +5481,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. /// @@ -6092,364 +5705,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. /// @@ -6465,328 +5720,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. @@ -6829,11 +5762,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; @@ -6913,36 +5842,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. /// @@ -15375,34 +14274,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. @@ -15426,34 +14297,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. @@ -15497,22 +14340,29 @@ 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); + symtab_reader::symtab_filter filter = + ctxt.symtab()->make_filter().functions(); + + for (symtab_reader::symtab::const_iterator + it = ctxt.symtab()->begin(filter), + end = ctxt.symtab()->end(); + it != end; ++it) + { + (*exported_fn_symbols_map)[(*it)->get_name()].push_back(*it); + } + 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().variables(); + for (symtab_reader::symtab::const_iterator + it = ctxt.symtab()->begin(filter), + end = ctxt.symtab()->end(); + it != end; ++it) + { + (*exported_var_symbols_map)[(*it)->get_name()].push_back(*it); + } ctxt.current_corpus()->set_var_symbol_map(exported_var_symbols_map); } else From patchwork Fri Jun 19 21:43:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39706 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 DAE2B3898535; Fri, 19 Jun 2020 21:43:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAE2B3898535 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592603024; bh=T7v9DGn+4kMTFC9QTfAERwO5UIrRW/uTJSICd5ItlRY=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=wkNkcPIqgQxxRlxJp8th7VdPc9C1M5eWA0IOyY8jnYqYOjyCYE52iM0+8ewpDZBsA QftBMPowcuoHvE4AZXkLk0yXSJkMvXC4Yz27Acuj5EhjOfk2pvEkeTyqzUmIyZ1zZM AtK9V3rNAvvL9DwYYmO0dW+uVesQLZzpWgNHPCmM= 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 5E6903939C20 for ; Fri, 19 Jun 2020 21:43:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5E6903939C20 Received: by mail-qv1-xf49.google.com with SMTP id x16so7844837qvp.19 for ; Fri, 19 Jun 2020 14:43:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=T7v9DGn+4kMTFC9QTfAERwO5UIrRW/uTJSICd5ItlRY=; b=LWxGy290nTaaxMpjg3yHsJj7BxuiFjIkB9dKba7/I5saKxJ9gG0ctT4CCLw2kJxRkN LiionFoVpZCWW2zfboWQm5Kk0VpDGy1dZJmUKxzg50fYE0kKMRs+uEz0KyauzIM+J2SA YUYgyHr0v7GC8C5x1K3+3Nh9bDGvBn7wGOp6Gj2NNXOzh3lstlRY4j9T9D1kc2poIjHT F5ZByvKrrWO74eP6wkCR9DiTuKrhq/GLN2B3N6QhrIOeRLIKXsSdUnDW/44In/Vtvqfs ELirePl/00W29Nyncy0cZyG+pP8yPqWDoyIPdYzIV0hqTZXaitegbqy5De+kusVTTcf5 V4Dw== X-Gm-Message-State: AOAM533Ywo9svfQ0gbBTpoh7utuvTIEPe30W9dZaBI3m6NujipK2ZMrT fGvkb1nTG1IP3KumYmviJaG/ERB6dWCbOl22GdArV7yag1dId8Thxx+IfHGz8dQ8iJ+pCcaK3AS Vc2hFriUmobf6IQ3mIR4UFIvGI/WnMvkhyczS/bLMHaw59s76Cja1C63m1NeEVWjYucqnOj4= X-Google-Smtp-Source: ABdhPJyJ4NnRC2KmBHqi3v4oAp8KbgXQ1hZL5MCDeBUG3h+V/SzF69EIqMORPZbDyZUHQGWJmlEC0frwP5fJYg== X-Received: by 2002:ad4:56ac:: with SMTP id bd12mr11048473qvb.139.1592603020898; Fri, 19 Jun 2020 14:43:40 -0700 (PDT) Date: Fri, 19 Jun 2020 23:43:02 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-14-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 13/16] abg-elf-helpers: migrate ppc64 specific helpers 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, 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, gprocida@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 2d39596f2712..73069e844eba 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -2161,10 +2161,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 @@ -2344,7 +2340,6 @@ public: elf_handle_ = 0; elf_path_ = elf_path; symtab_section_ = 0; - opd_section_ = 0; cur_tu_die_ = 0; exported_decls_builder_ = 0; @@ -5020,19 +5015,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. /// @@ -5144,152 +5126,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 @@ -5599,13 +5435,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 // @@ -5768,24 +5606,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 @@ -5936,26 +5756,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 ed768d221d4f..6e2495af1ee0 100644 --- a/src/abg-elf-helpers.cc +++ b/src/abg-elf-helpers.cc @@ -863,6 +863,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. /// @@ -1027,5 +1174,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 647c92703dfa..2046648569a7 100644 --- a/src/abg-elf-helpers.h +++ b/src/abg-elf-helpers.h @@ -27,6 +27,7 @@ #include "config.h" +#include #include #include @@ -148,6 +149,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 // @@ -177,6 +182,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 Fri Jun 19 21:43:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39708 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 E2504393C897; Fri, 19 Jun 2020 21:43:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2504393C897 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592603025; bh=FPAbuvbYzhUig4pNLmMTTbu9tgbDVprStc93G76zDWE=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=xcZSBk7daoAKAM7CbNBABUWP0xsMJ7xwlvY/lSa2ntCwj+vqMFzspwmFhsej4wn3p XgutJSMvdiHSNVJyvMDCOqZhlKMB4beskTzM4kTxFIkon4SSGDBxeNTk9WKBkM0gkD 4GXV4KvTwYbZtEzT7mBJSVN+5OGyMAhCSlexXGWI= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by sourceware.org (Postfix) with ESMTPS id 87CF63939C22 for ; Fri, 19 Jun 2020 21:43:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 87CF63939C22 Received: by mail-yb1-xb4a.google.com with SMTP id e192so11501388ybf.17 for ; Fri, 19 Jun 2020 14:43:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=FPAbuvbYzhUig4pNLmMTTbu9tgbDVprStc93G76zDWE=; b=j+xtw08NW6ZKWirBYFJrHYvc3IACnucy/H6IOOG28pUPr8HgYKAfCw5mgDXIjLRMlL Uj8ZbEpEw1nptrCOpgWw/WBoVHxLrksfcGOYKjMp+h2J3I/Cg18YDglRmRqHTy38l7Aq hVZsBbEME416MSyeTPL5ySsks3jWpDyEDwGr7qbxAoMlb+bmqqdImVp2l81cQ9mbGObD p0Y/S15N46ojieRXysagNkFF3TOOh4vgGyoFHH4N5yIigazfY9N0YU6KQyxGdSyeIdoJ yaAFoc2OsDMOeXGUZY2iAySl2pCzEHH6EMHS+loe8PtdVCrBRqNOJ0WXMhfsKgZcbQmj AUwA== X-Gm-Message-State: AOAM533e0S1qSJh2AWfRObKXYtLCyW57Foq44Vs9pcvOe5FG7PnCLWZa 4phruWHdaN+sJfC+jpnhqNx58OKOa6CbtHil4bkAznrxM2RA+ukgHROpsQV7vaSFbssxZmBVlUs CglQxXIaFtxRGpH/HaPJL+08vTgLUB0XbakD4b0BcUkFgBnizbbTwlteXN1KKag6vTcuExfs= X-Google-Smtp-Source: ABdhPJyc9RxNhzom4NIk7Sa9bUpn2hjRKK/9R8D6SfpDQqVNiHI8La7vTaLgT5D74UgleM28Yc11/Y0Bi+5MrQ== X-Received: by 2002:a25:2e48:: with SMTP id b8mr8600560ybn.56.1592603022990; Fri, 19 Jun 2020 14:43:42 -0700 (PDT) Date: Fri, 19 Jun 2020 23:43:03 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-15-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 14/16] symtab_reader: add support for ppc64 ELFv1 binaries To: libabigail@sourceware.org X-Spam-Status: No, score=-22.9 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, gprocida@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 --- include/abg-symtab-reader.h | 8 ++++ src/abg-symtab-reader.cc | 93 +++++++++++++++++++++++++++++++++++-- 2 files changed, 98 insertions(+), 3 deletions(-) diff --git a/include/abg-symtab-reader.h b/include/abg-symtab-reader.h index 86335617d46a..06001b26ebeb 100644 --- a/include/abg-symtab-reader.h +++ b/include/abg-symtab-reader.h @@ -342,6 +342,9 @@ private: 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_; + /// Load the symtab representation from an Elf binary presented to us by an /// Elf* handle. /// @@ -366,6 +369,11 @@ private: 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. diff --git a/src/abg-symtab-reader.cc b/src/abg-symtab-reader.cc index c98b9174490c..aefc8d6dcd86 100644 --- a/src/abg-symtab-reader.cc +++ b/src/abg-symtab-reader.cc @@ -91,11 +91,16 @@ const elf_symbol_sptr& symtab::lookup_symbol(GElf_Addr symbol_addr) const { static const elf_symbol_sptr empty_result; - const addr_symbol_map_type::const_iterator it = + const addr_symbol_map_type::const_iterator addr_it = addr_symbol_map_.find(symbol_addr); - if (it != addr_symbol_map_.end()) + if (addr_it != addr_symbol_map_.end()) + return addr_it->second; + else { - return it->second; + const addr_symbol_map_type::const_iterator entry_it = + entry_addr_symbol_map_.find(symbol_addr); + if (entry_it != entry_addr_symbol_map_.end()) + return entry_it->second; } return empty_result; } @@ -172,6 +177,8 @@ symtab::load_(Elf* elf_handle, const bool is_kernel = elf_helpers::is_linux_kernel(elf_handle); abg_compat::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; @@ -277,6 +284,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 std::pair result = addr_symbol_map_.insert( std::make_pair(symbol_value, symbol_sptr)); @@ -345,5 +356,81 @@ 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_.insert( + std::make_pair(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 From patchwork Fri Jun 19 21:43:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39709 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 35E74393C88E; Fri, 19 Jun 2020 21:43:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35E74393C88E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592603030; bh=mmBGj4G88EUo/rxXX66+rZ447a8ev5ZQjNxFcq+8Z2E=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=bZztT5hRlodPJX0/Su1CYPj8Q3GK/Hgud0t4uSfxRrkcIgnbvGuQuIqknTOyhGmfo 6q+/nirGZkpOVJVebo66OJsXrRfYFLDSf7fsJteyqAGtBTLF/Zd2DSURzRf1FaSN2m 0aZrf5VESqDTYEB0sqC4XvwJnVY6VujxVBJvO5Rw= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by sourceware.org (Postfix) with ESMTPS id BF0E2393C895 for ; Fri, 19 Jun 2020 21:43:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BF0E2393C895 Received: by mail-yb1-xb4a.google.com with SMTP id j3so11662576yba.14 for ; Fri, 19 Jun 2020 14:43:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=mmBGj4G88EUo/rxXX66+rZ447a8ev5ZQjNxFcq+8Z2E=; b=oq6ylFpnSlX27rNQH2cpI9JL9Pjq6e73EkIUDZo3DmwgL7T79gAm8xebMvH41JFclJ 7g3uhCdMbqhF3YOCgTeZ6qjZDhQLh8IQPwQ0kxofBgd2iZMePCXe4dy4d/5y+6V30GmZ 07KoOE3ERNEWWGjgz6scqyrj7cfKrLAfFE4dCugSzhQ7FiJcG3gqVsJjZ5PC3zVfODnl FTbTWuF4wUJ0lpSn/lqFXwFK07bN/XeH23RGSFaccKX71PFSAMuYd+uxZsEEfS/BPHml 77YlCUUIv79rYwuxT4HNKMzSyOJNQ4kdgB9qF+V2m0+egHCSmThPqPotsJcVnbTxoGmP RGOg== X-Gm-Message-State: AOAM531efgQ5giwQVYrJCiAysVquWhQPp+iCDlu+2tAkEiyWwoXUUw4C h8xMfd55iJhsGElI7bCr6DluyOdM42ZMcBJT9Dy76SEwuPoprQzkv8iRtErHnByq/SAk29jqmuw vNFpzBctPQYMXUTXt/KDGkdilsrrH1Xv9GJEJHugS8lumOJ4BWU2hDh37LbWuESPNU4cH2Uo= X-Google-Smtp-Source: ABdhPJy2tsjpOVIDAJBhDO94F1EGH9HU483pea8bCX6qxfQvWZwaBw11f+eAYNUoWxUX05Qd9TfrkFWEx/CA8g== X-Received: by 2002:a25:2a0b:: with SMTP id q11mr8972047ybq.495.1592603025216; Fri, 19 Jun 2020 14:43:45 -0700 (PDT) Date: Fri, 19 Jun 2020 23:43:04 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-16-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 15/16] abg-corpus: remove symbol maps and their setters To: libabigail@sourceware.org X-Spam-Status: No, score=-22.9 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, gprocida@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 | 159 ++++++++---------- src/abg-dwarf-reader.cc | 48 ------ src/abg-reader.cc | 11 -- .../data/test-read-dwarf/PR25007-sdhci.ko.abi | 2 - tests/test-symtab.cc | 15 +- 7 files changed, 99 insertions(+), 181 deletions(-) diff --git a/include/abg-corpus.h b/include/abg-corpus.h index b94926996cde..f517986d8aca 100644 --- a/include/abg-corpus.h +++ b/include/abg-corpus.h @@ -175,27 +175,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; @@ -205,15 +187,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 f2e895bf1e7d..fcb6d7a66b8e 100644 --- a/src/abg-corpus-priv.h +++ b/src/abg-corpus-priv.h @@ -30,6 +30,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" @@ -697,11 +698,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 @@ -722,10 +719,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: @@ -747,18 +748,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 0f5d51820891..1f72904d137f 100644 --- a/src/abg-corpus.cc +++ b/src/abg-corpus.cc @@ -347,6 +347,22 @@ 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 (elf_symbols::const_iterator iter = get_sorted_fun_symbols().begin(), + end = get_sorted_fun_symbols().end(); + iter != end; ++iter) + { + (*fun_symbol_map)[(*iter)->get_name()].push_back(*iter); + } + } + return *fun_symbol_map; +} + /// Getter for a sorted vector of the function symbols undefined in /// this corpus. /// @@ -368,6 +384,25 @@ 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 (elf_symbols::const_iterator + iter = get_sorted_undefined_fun_symbols().begin(), + end = get_sorted_undefined_fun_symbols().end(); + iter != end; ++iter) + { + (*undefined_fun_symbol_map)[(*iter)->get_name()].push_back(*iter); + } + } + return *undefined_fun_symbol_map; +} + + + /// Return a list of symbols that are not referenced by any function of /// corpus::get_functions(). /// @@ -448,6 +483,22 @@ 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 (elf_symbols::const_iterator iter = get_sorted_var_symbols().begin(), + end = get_sorted_var_symbols().end(); + iter != end; ++iter) + { + (*var_symbol_map)[(*iter)->get_name()].push_back(*iter); + } + } + return *var_symbol_map; +} + /// Getter for a sorted vector of the variable symbols undefined in /// this corpus. /// @@ -469,6 +520,23 @@ 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 (elf_symbols::const_iterator + iter = get_sorted_undefined_var_symbols().begin(), + end = get_sorted_undefined_var_symbols().end(); + iter != end; ++iter) + { + (*undefined_var_symbol_map)[(*iter)->get_name()].push_back(*iter); + } + } + return *undefined_var_symbol_map; +} + /// Return a list of symbols that are not referenced by any variable of /// corpus::get_variables(). /// @@ -954,10 +1022,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()); } @@ -991,69 +1056,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. @@ -1063,7 +1071,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 @@ -1081,33 +1089,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. @@ -1117,7 +1104,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 73069e844eba..2b978c239243 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -14133,54 +14133,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); - symtab_reader::symtab_filter filter = - ctxt.symtab()->make_filter().functions(); - - for (symtab_reader::symtab::const_iterator - it = ctxt.symtab()->begin(filter), - end = ctxt.symtab()->end(); - it != end; ++it) - { - (*exported_fn_symbols_map)[(*it)->get_name()].push_back(*it); - } - - 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().variables(); - for (symtab_reader::symtab::const_iterator - it = ctxt.symtab()->begin(filter), - end = ctxt.symtab()->end(); - it != end; ++it) - { - (*exported_var_symbols_map)[(*it)->get_name()].push_back(*it); - } - 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 313639fddff0..fbdcce590bc3 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -1974,17 +1974,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 d5af7183095f..24c25c06d61c 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 905d8249a6e4..c144b1d080f6 100644 --- a/tests/test-symtab.cc +++ b/tests/test-symtab.cc @@ -104,17 +104,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) { @@ -122,8 +124,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) { @@ -131,10 +132,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 Fri Jun 19 21:43:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39710 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 9A0BF3938C29; Fri, 19 Jun 2020 21:43:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A0BF3938C29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592603032; bh=H25EQ3fWcr7dkOv+rxveDNl79cjgy+7KE8DdmW4pJHk=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Y4B4cy4M44lZrN/Ciob6OHPL6YYvRm4DoODOcbY3W6cL41jF1yf+kHGZEEHUB3Sn6 /MpIjhes2GHgtfvMWxEOlQUGBtXf9x3i/jX/hD/0ib3DGfTUTF+nm/KjpRSjfTuuyY GpNd20SNYlMHJxMWhf46IrVo0CzVjlw6gg/KR1mA= 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 3CD153898535 for ; Fri, 19 Jun 2020 21:43:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3CD153898535 Received: by mail-qk1-x749.google.com with SMTP id 204so8204113qki.20 for ; Fri, 19 Jun 2020 14:43:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=H25EQ3fWcr7dkOv+rxveDNl79cjgy+7KE8DdmW4pJHk=; b=NRBmzPaibThlOIE+JuU8xYLAMhA3KkghKKwSIOzLpkndjtSm5D/JK24zuvGMClBWA+ a2OFx/4xfM7g8xNMbL+STmKcNL0PWyW1bkt/pEm2k2Jx0Yd0t+6ZZ9z2EnbxSq9YYJet Z0FEbhsaKPNM0p2jEBxSAhfnUeiXvaaTct8MHOEY3zTwm+SsPoFW8VYZrwk1lELAP0iQ f5NRg0lTdBPa3ftnkGimOQd/KjdDZUG7mN9IV6HIXTAcVVG6MSfoKy9hlYu9VGnb0Hpa Aln1f5LgLN8K39SuBrrAgJPwRC5qlGWPs8CIp+GlHYuHYbaCjAclYZ4tvuO5Ygc4gAVp IsMw== X-Gm-Message-State: AOAM5331iKtYpMdd5BPV1Rcg7OlUA3/P0b44dSPPucA1fuArkR5x61L2 kxolJSU1iyV4xnTMeB/uHq7CYJearhIuFLkTkifO0REuH6rT22wMpUIqQfgJBFIcDVAFqTMKmKT T6gBsLFb4Pe/K9VNihqZXlMaGOAJCyasWzh6OQ5ZE5oGLnJkKIAW0XxFXnTL+4rZTGd7rIfk= X-Google-Smtp-Source: ABdhPJzV5zGxEnBl+1WYb2FBzcpedi/6UBRc7XzdgZBy+O5MuXvBC0y3H1Kkv0SU0J+VqJwJ5pMUAt647X+C/g== X-Received: by 2002:a0c:c249:: with SMTP id w9mr10828335qvh.149.1592603027600; Fri, 19 Jun 2020 14:43:47 -0700 (PDT) Date: Fri, 19 Jun 2020 23:43:05 +0200 In-Reply-To: <20200619214305.562-1-maennich@google.com> Message-Id: <20200619214305.562-17-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v1 16/16] dwarf reader: drop (now) unused code related symbol table reading 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, gprocida@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. Signed-off-by: Matthias Maennich Reviewed-by: Giuliano Procida --- include/abg-dwarf-reader.h | 6 - src/abg-dwarf-reader.cc | 656 +------------------------------------ src/abg-tools-utils.cc | 13 - tools/abidw.cc | 2 - 4 files changed, 12 insertions(+), 665 deletions(-) diff --git a/include/abg-dwarf-reader.h b/include/abg-dwarf-reader.h index d0329aed9ccf..3f062e04502d 100644 --- a/include/abg-dwarf-reader.h +++ b/include/abg-dwarf-reader.h @@ -195,12 +195,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 2b978c239243..b69fcc79cfd6 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -291,10 +291,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, @@ -2026,7 +2022,6 @@ public: environment* env; bool load_in_linux_kernel_mode; bool load_all_types; - bool ignore_symbol_table; bool show_stats; bool do_log; @@ -2034,7 +2029,6 @@ public: : env(), load_in_linux_kernel_mode(), load_all_types(), - ignore_symbol_table(), show_stats(), do_log() {} @@ -2230,19 +2224,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_; @@ -2378,13 +2359,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(); @@ -5044,88 +5018,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 @@ -5206,102 +5098,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 @@ -5317,232 +5113,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. /// @@ -5558,71 +5128,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 @@ -6494,46 +5999,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. @@ -13483,33 +12948,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. @@ -13581,23 +13019,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) { @@ -13658,15 +13082,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, @@ -13769,15 +13187,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, @@ -14028,23 +13440,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) { @@ -14074,29 +13472,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. @@ -15341,13 +14716,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 dfbec879de8d..9116a97a62e9 100644 --- a/src/abg-tools-utils.cc +++ b/src/abg-tools-utils.cc @@ -2563,12 +2563,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); @@ -2608,13 +2602,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 2cd848df9fb8..58072e7072c4 100644 --- a/tools/abidw.cc +++ b/tools/abidw.cc @@ -828,8 +828,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) {