From patchwork Thu Oct 27 14:09:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 59520 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 6B9D6385114A for ; Thu, 27 Oct 2022 14:09:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B9D6385114A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666879784; bh=iALWuRRVj6a5H4DnjlRVUEx7UcxM+wf0ytAK4xNi8gs=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:Cc:From; b=PjufIHwaIOTkhl2HmSiLCjxdxW31FZNan2ahSBTfsS6SjatTWsBEOjdei4GEDvV0u +6O1f666WPqoCFP86jX93+RpMj/dl9h56r5CFV0cVHEZ86ZNh4Qenem+fQ/bJZouPx z5F92eXhjXHsvo2OiLm8CcxP1NPUeeOOd/qZc7xQ= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-ej1-x649.google.com (mail-ej1-x649.google.com [IPv6:2a00:1450:4864:20::649]) by sourceware.org (Postfix) with ESMTPS id 7CA2E3851521 for ; Thu, 27 Oct 2022 14:09:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7CA2E3851521 Received: by mail-ej1-x649.google.com with SMTP id xc12-20020a170907074c00b007416699ea14so1089669ejb.19 for ; Thu, 27 Oct 2022 07:09:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=iALWuRRVj6a5H4DnjlRVUEx7UcxM+wf0ytAK4xNi8gs=; b=yIV2QBzm6PS9mv2jqtYmgpmH1WmEaabnT8a/6a40lCIbco0j04NlPUiV4vv3pu2uPp 7y7B0Vm5RikYg0l2gXGOA5FtFruYDZN6PkgwvHS//6uhdp/yUXQxEwGBPUlklaViIbjg aaWlusEgC8K1VbhqI+t9vE1B5TlsAm61sIfHR+5XQzoBXcbFsbbXtEdKOsDcqz23xG19 akQNF9lM5t/Pc9utuRW/QHbZpKtL89oIGP8r6AJTGDE+IUWxtArDiG1Awn8bFGckBoio 8t1HrOVE0cnx9vVUaZwbOAl0nib7qMFV1dJC1MPsO0bwBuMkDAAbyvOUe29bDvYh+zOi s1tA== X-Gm-Message-State: ACrzQf1VahbKLE95gh/E8nqK7wHaMzovAXHIu4jPGGarTYCAMtizuZ03 YVO2g0ngaTVt28FlJ08iYYPppeN6xuLQ+U2hOXJdtHPIS9b0UyNf9u05g0OhEXQVoeY9fv/c6K3 EuKZkbhDhcJO0HqwKmkdhoO/fmKwgMwCBedVTm8LaWTZ0uQ0nZIg/RlVxc4PUINCxbHrLs4Q= X-Google-Smtp-Source: AMsMyM5vqXusrJaTxLFPfTqoVA1DYDs0zEckE7OayXRBc5X3y/VcH9Zm9wAb+ysx9dn9JPpCvC2gI7F3Pc+d+Q== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:209:2877:1753:4fed:abea]) (user=gprocida job=sendgmr) by 2002:a17:907:1b09:b0:7ac:db30:2cf0 with SMTP id mp9-20020a1709071b0900b007acdb302cf0mr11077971ejc.679.1666879777463; Thu, 27 Oct 2022 07:09:37 -0700 (PDT) Date: Thu, 27 Oct 2022 15:09:28 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Message-ID: <20221027140928.1480353-1-gprocida@google.com> Subject: [PATCH] Narrow Linux symbol CRCs to 32 bits To: libabigail@sourceware.org X-Spam-Status: No, score=-21.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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Giuliano Procida via Libabigail From: Giuliano Procida Reply-To: Giuliano Procida Cc: maennich@google.com, vvvvvv@google.com, sidnayyar@google.com, dodji@seketeli.org, kernel-team@android.com Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" MODVERSIONS CRCs are 32-bit hashes of strings representing C type elements or typed symbols. The hash is calculated using a 32-bit CRC, hence the name. The kernel module loading code (implicitly) truncates any provided CRC value to 32 bits before comparing it with anything. When support was added to libabigail, values up to 64 bits wide were supported. Recently, Linux kernel builds have now started generating ELF CRC symbols with 64-bit values (where the low 32 bits are the CRC). Together this has resulted in incorrect CRCs in ABIs. This change resolves the problem by narrowing libabigail's concept of Linux CRC to 32 bits. No tests are affected. * include/abg-ir.h (elf_symbol::elf_symbol): Change CRC type from optional to optional. (elf_symbol::create): Likewise. (elf_symbol::get_crc): Likewise. (elf_symbol::set_crc): Likewise. * src/abg-ir.cc (elf_symbol::priv) Change CRC type from optional to optional. (elf_symbol::priv::priv): Likewise. (elf_symbol::elf_symbol): Likewise. (elf_symbol::create): Likewise. (elf_symbol::get_crc): Likewise. (elf_symbol::set_crc): Likewise. * src/abg-reporter-priv.cc (maybe_report_diff_for_symbol): Change CRC type from optional to optional. * src/abg-symtab-reader.cc (symtab::load_): Change crc_values value type from uint64_t to uint32_t. Signed-off-by: Giuliano Procida --- include/abg-ir.h | 8 ++++---- src/abg-ir.cc | 12 ++++++------ src/abg-reporter-priv.cc | 4 ++-- src/abg-symtab-reader.cc | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/abg-ir.h b/include/abg-ir.h index 4892f0e2..546603f4 100644 --- a/include/abg-ir.h +++ b/include/abg-ir.h @@ -940,7 +940,7 @@ private: const version& ve, visibility vi, bool is_in_ksymtab = false, - const abg_compat::optional& crc = {}, + const abg_compat::optional& crc = {}, const abg_compat::optional& ns = {}, bool is_suppressed = false); @@ -966,7 +966,7 @@ public: const version& ve, visibility vi, bool is_in_ksymtab = false, - const abg_compat::optional& crc = {}, + const abg_compat::optional& crc = {}, const abg_compat::optional& ns = {}, bool is_suppressed = false); @@ -1039,11 +1039,11 @@ public: void set_is_in_ksymtab(bool is_in_ksymtab); - const abg_compat::optional& + const abg_compat::optional& get_crc() const; void - set_crc(const abg_compat::optional& crc); + set_crc(const abg_compat::optional& crc); const abg_compat::optional& get_namespace() const; diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 5193934a..a043a532 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -1788,7 +1788,7 @@ struct elf_symbol::priv // STT_COMMON definition of that name that has the largest size. bool is_common_; bool is_in_ksymtab_; - abg_compat::optional crc_; + abg_compat::optional crc_; abg_compat::optional namespace_; bool is_suppressed_; elf_symbol_wptr main_symbol_; @@ -1822,7 +1822,7 @@ struct elf_symbol::priv const elf_symbol::version& ve, elf_symbol::visibility vi, bool is_in_ksymtab, - const abg_compat::optional& crc, + const abg_compat::optional& crc, const abg_compat::optional& ns, bool is_suppressed) : env_(e), @@ -1896,7 +1896,7 @@ elf_symbol::elf_symbol(const environment* e, const version& ve, visibility vi, bool is_in_ksymtab, - const abg_compat::optional& crc, + const abg_compat::optional& crc, const abg_compat::optional& ns, bool is_suppressed) : priv_(new priv(e, @@ -1971,7 +1971,7 @@ elf_symbol::create(const environment* e, const version& ve, visibility vi, bool is_in_ksymtab, - const abg_compat::optional& crc, + const abg_compat::optional& crc, const abg_compat::optional& ns, bool is_suppressed) { @@ -2208,7 +2208,7 @@ elf_symbol::set_is_in_ksymtab(bool is_in_ksymtab) /// Getter of the 'crc' property. /// /// @return the CRC (modversions) value for Linux Kernel symbols, if any -const abg_compat::optional& +const abg_compat::optional& elf_symbol::get_crc() const {return priv_->crc_;} @@ -2216,7 +2216,7 @@ elf_symbol::get_crc() const /// /// @param crc the new CRC (modversions) value for Linux Kernel symbols void -elf_symbol::set_crc(const abg_compat::optional& crc) +elf_symbol::set_crc(const abg_compat::optional& crc) {priv_->crc_ = crc;} /// Getter of the 'namespace' property. diff --git a/src/abg-reporter-priv.cc b/src/abg-reporter-priv.cc index 2ecf8016..70839085 100644 --- a/src/abg-reporter-priv.cc +++ b/src/abg-reporter-priv.cc @@ -1149,8 +1149,8 @@ maybe_report_diff_for_symbol(const elf_symbol_sptr& symbol1, << "\n"; } - const abg_compat::optional& crc1 = symbol1->get_crc(); - const abg_compat::optional& crc2 = symbol2->get_crc(); + const abg_compat::optional& crc1 = symbol1->get_crc(); + const abg_compat::optional& crc2 = symbol2->get_crc(); if (crc1 != crc2) { const std::string none = "(none)"; diff --git a/src/abg-symtab-reader.cc b/src/abg-symtab-reader.cc index 606c96a2..8a566f8d 100644 --- a/src/abg-symtab-reader.cc +++ b/src/abg-symtab-reader.cc @@ -265,7 +265,7 @@ symtab::load_(Elf* elf_handle, const bool is_kernel = elf_helpers::is_linux_kernel(elf_handle); std::unordered_set exported_kernel_symbols; - std::unordered_map crc_values; + std::unordered_map crc_values; std::unordered_map namespaces; for (size_t i = 0; i < number_syms; ++i)