From patchwork Fri Sep 10 11:23:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 44919 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 503AD385841B for ; Fri, 10 Sep 2021 11:23:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 503AD385841B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1631273016; bh=xhKbMzF1RwB/Xr2k0wQg4vS2fqiEI5UzY8+1xN8UCyc=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=nNnlO7en5PR/ofBQ0Ib0m7G+HwcVNXLkPNBGZNA0wzzpr+GHBzFy51bHMXf/qssvr lKs163hjn2dQSCIMxNF+mBZZhH9R0iwuUpVhGXd9IZd8/VA+tUuZ2HnH1tc/uDLanp K0UWb3EkyTnEW06Px95F/FTwoeo8GWCOSVpJ9pSQ= 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 3B8173858403 for ; Fri, 10 Sep 2021 11:23:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3B8173858403 Received: by mail-qt1-x849.google.com with SMTP id q19-20020ac87353000000b0029a09eca2afso4930251qtp.21 for ; Fri, 10 Sep 2021 04:23:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xhKbMzF1RwB/Xr2k0wQg4vS2fqiEI5UzY8+1xN8UCyc=; b=cM5sVJ5L4/8cqVkoO5T/gEc314SxtOCknwFBLbXHzNJcA3iKzcdEMIMYTiazzSPuTL 69b+c6p4B9bjcs2COkAe/cTPhyl08CWfU1JStfOxc7XzdhUXblj1PetBOgMkjIOi70Nn 0/axks/PWJ6cl6XyxQyEQe1TEkQJvTpTYifN567A+IwkPu6/6aVETE+BDUHOyW5LVdmx RVb8xVA4rZBj0dXJ6BQ2j3bRgtobMJJOSUlrSrmD/cXB0hnqM/CHNDlYtuNkc+u5WYH2 VepT+roeJq9Rx8tAyVjYKPVFY6qEw8+04THhwUpYYemSq+Gjtia0mu4OsszQuZ32mjVz 39MA== X-Gm-Message-State: AOAM532fa7KS2rXc6e2NR/gCAIsmei49gOocKD2PNuGzSajJAdW7hz1/ vg3lTN7i+wKYic2rKvebY+m7OjOusa55jQHt7q2qqjUyPAQ5eouAImCgGWrIP3xkCXw43DPI8HS QZxms1z8Y6vWuN7LhOIORZgi5bzNHhcqoPYdHC8tNn5TAyEisqu5xoH2WAn+YrwU8ua+hnU8= X-Google-Smtp-Source: ABdhPJy1ThPQkprNOW4FaojLxqCnGEi4dHGf6uZG0Y6cBPkyPDBXvn2/ZGbzIlJeFmrFCPszsuhnqpWHiCvgtw== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:210:fe2b:14b7:895d:9020]) (user=gprocida job=sendgmr) by 2002:a0c:c490:: with SMTP id u16mr7862099qvi.26.1631273011738; Fri, 10 Sep 2021 04:23:31 -0700 (PDT) Date: Fri, 10 Sep 2021 12:23:22 +0100 In-Reply-To: <20210910112325.806676-1-gprocida@google.com> Message-Id: <20210910112325.806676-2-gprocida@google.com> Mime-Version: 1.0 References: <20210910112325.806676-1-gprocida@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH 1/4] abg-writer: get_id_for_type: refactor insertion and look-up To: libabigail@sourceware.org X-Spam-Status: No, score=-21.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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, kernel-team@android.com Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" The insertion and look-up in get_id_for_type can be refactored. This avoids an extra round of hashing and equality tests in the case of a newly inserted type. * src/abg-writer.cc (get_id_for_type): Fold together the look-up and insertion logic by always attempting to insert a dummy value. Signed-off-by: Giuliano Procida --- src/abg-writer.cc | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/abg-writer.cc b/src/abg-writer.cc index 9f48dc92..d23f4fd6 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -421,30 +421,35 @@ public: if (c == 0) c = const_cast(t); - type_ptr_map::const_iterator it = m_type_id_map.find(c); - if (it != m_type_id_map.end()) - return it->second; + auto insertion = m_type_id_map.emplace(c, interned_string()); + interned_string& id = insertion.first->second; - switch (m_type_id_style) - { - case SEQUENCE_TYPE_ID_STYLE: - { - interned_string id = get_id_manager().get_id_with_prefix("type-id-"); - return m_type_id_map[c] = id; - } - case HASH_TYPE_ID_STYLE: + if (insertion.second) + switch (m_type_id_style) { - interned_string pretty = c->get_cached_pretty_representation(true); - size_t hash = hashing::fnv_hash(pretty); - while (!m_used_type_id_hashes.insert(hash).second) - ++hash; - std::ostringstream os; - os << std::hex << std::setfill('0') << std::setw(8) << hash; - return m_type_id_map[c] = c->get_environment()->intern(os.str()); + case SEQUENCE_TYPE_ID_STYLE: + { + id = get_id_manager().get_id_with_prefix("type-id-"); + break; + } + case HASH_TYPE_ID_STYLE: + { + interned_string pretty = c->get_cached_pretty_representation(true); + size_t hash = hashing::fnv_hash(pretty); + while (!m_used_type_id_hashes.insert(hash).second) + ++hash; + std::ostringstream os; + os << std::hex << std::setfill('0') << std::setw(8) << hash; + id = c->get_environment()->intern(os.str()); + break; + } + default: { + ABG_ASSERT_NOT_REACHED; + break; + } } - } - ABG_ASSERT_NOT_REACHED; - return interned_string(); + + return id; } string From patchwork Fri Sep 10 11:23:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 44921 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 54154384A896 for ; Fri, 10 Sep 2021 11:23:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 54154384A896 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1631273021; bh=jSjTt9DROI8DBTjePeuuoAWfHdLTvhoik79YhJPTrNo=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=wGLXikx4xdcbTxNdHDCLFlpwXzHVypkG5IcrlYWXAglfGV+Vf748sUYxcondjfw+a i6uHJmFSvpF+yQ4T+42v7DWrGFD0PfcstSRegzaYxXpoFFZCBW3bl8AOPDMwoyaOqP SJ8L01Exy1qd5Rn1FDkCzaa/5aWEOzEDzbvlxyo4= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by sourceware.org (Postfix) with ESMTPS id 1BAF83858C39 for ; Fri, 10 Sep 2021 11:23:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1BAF83858C39 Received: by mail-qk1-x74a.google.com with SMTP id h10-20020a05620a284a00b003d30e8c8cb5so4418796qkp.11 for ; Fri, 10 Sep 2021 04:23:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=jSjTt9DROI8DBTjePeuuoAWfHdLTvhoik79YhJPTrNo=; b=Wpn0DXNX11cW1uEsGbWSOqqKYa7wVSkhCGEjeP446msXEm6LKiebCTcHRj6O9M4b+j yZUcdQrMqGixbK2Uhj3i3VLdOyXk1WZWDru8pl101oaUPRygICrBXwNduahOQIeDSYW/ 4GmruCIAlrz7NoPjyVN6JKvPFqZPxE7xQ2V2goG56Bkeq28yZJcLKIMOv0/UsPLqeLXu hDQS4lQHPf2NQKgRnSbCjwJQoHKVZ/goeN60D0E/3wb9okCVz8dDUWXnZ0iud5NqWbua sIsweu0jCKsMXlQLOaCk+Yjp2r6x5bE67dzQAXRewtvmOeK1Oq7EIXmlzxH7KdLrN8nz rB2g== X-Gm-Message-State: AOAM531oo/72TeJouZf24eXhsVsMpVMv2dbPsdlOeWFkKzWMfa5I3d+s C78aRKl1NnxQi1gGo+cTarssWy7ot1Y2Px3Tb6X7wKSTao10Z+qO3+lU7SAea2nsDk+XihUvWKB 6aOC9nhLSSECk1bDYyRPeTFkKrUgvvhmRI75WEuFkXSkSRwdO4fkNE3dfyGDDKeHx0Wo/tQA= X-Google-Smtp-Source: ABdhPJzTVtiPMKVihLLsSEimUdJs2ELjzgm58/S3kVkwes7OGpawz2SCdn2qeiCu6JyN7DZMaSjuAnGqb59CCg== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:210:fe2b:14b7:895d:9020]) (user=gprocida job=sendgmr) by 2002:a0c:c290:: with SMTP id b16mr7806769qvi.65.1631273013750; Fri, 10 Sep 2021 04:23:33 -0700 (PDT) Date: Fri, 10 Sep 2021 12:23:23 +0100 In-Reply-To: <20210910112325.806676-1-gprocida@google.com> Message-Id: <20210910112325.806676-3-gprocida@google.com> Mime-Version: 1.0 References: <20210910112325.806676-1-gprocida@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH 2/4] abg-writer: refactor recording of unemitted types 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, kernel-team@android.com Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" The code fragment if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last)) referenced_types_to_emit.insert(*i); appears 5 times. This commit inlines the insertion into the helper function which is also renamed. * src/abg-writer.cc (referenced_type_should_be_emitted): Replaced by record_unemitted_type. (record_unemitted_type): Replacement function that also takes care of inserting the type into the set. (write_translation_unit): Replace calls to referenced_type_should_be_emitted and inserts with calls to record_unemitted_type. Signed-off-by: Giuliano Procida --- src/abg-writer.cc | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/abg-writer.cc b/src/abg-writer.cc index d23f4fd6..795ca685 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -2248,10 +2248,12 @@ write_canonical_types_of_scope(const scope_decl &scope, } /// Test if a type referenced in a given translation unit should be -/// emitted or not. +/// emitted and record it if so. /// /// This is a subroutine of @ref write_translation_unit. /// +/// @param types the set of types to update. +/// /// @param t the type to consider. /// /// @param ctxt the write context to consider. @@ -2260,20 +2262,18 @@ write_canonical_types_of_scope(const scope_decl &scope, /// /// @param tu_is_last true if @p tu is the last translation unit being /// emitted. -/// -/// @return true iff @p t is to be emitted. -static bool -referenced_type_should_be_emitted(const type_base *t, - const write_context& ctxt, - const translation_unit& tu, - bool tu_is_last) +static void +record_unemitted_type(type_ptr_set_type& types, + const type_base *t, + const write_context& ctxt, + const translation_unit& tu, + bool tu_is_last) { if ((tu_is_last || t->get_translation_unit()->get_absolute_path() == tu.get_absolute_path()) && !ctxt.type_is_emitted(t) && !ctxt.decl_only_type_is_emitted(t)) - return true; - return false; + types.insert(t); } /// Serialize a translation unit to an output stream. @@ -2389,22 +2389,19 @@ write_translation_unit(write_context& ctxt, ctxt.get_referenced_types().begin(); i != ctxt.get_referenced_types().end(); ++i) - if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last)) - referenced_types_to_emit.insert(*i); + record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last); for (fn_type_ptr_set_type::const_iterator i = ctxt.get_referenced_function_types().begin(); i != ctxt.get_referenced_function_types().end(); ++i) - if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last)) - referenced_types_to_emit.insert(*i); + record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last); for (type_ptr_set_type::const_iterator i = ctxt.get_referenced_non_canonical_types().begin(); i != ctxt.get_referenced_non_canonical_types().end(); ++i) - if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last)) - referenced_types_to_emit.insert(*i); + record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last); // Ok, now let's emit the referenced type for good. while (!referenced_types_to_emit.empty()) @@ -2459,15 +2456,13 @@ write_translation_unit(write_context& ctxt, ctxt.get_referenced_types().begin(); i != ctxt.get_referenced_types().end(); ++i) - if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last)) - referenced_types_to_emit.insert(*i); + record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last); for (type_ptr_set_type::const_iterator i = ctxt.get_referenced_non_canonical_types().begin(); i != ctxt.get_referenced_non_canonical_types().end(); ++i) - if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last)) - referenced_types_to_emit.insert(*i); + record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last); } // Now handle all function types that were not only referenced by From patchwork Fri Sep 10 11:23:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 44922 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 D100A384B058 for ; Fri, 10 Sep 2021 11:23:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D100A384B058 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1631273023; bh=ER1TOFUJ5OFEYlck3D6dMrV5/bpq+Qz2ApAvpwitnyU=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=yY8/mCreB2tolZoKpJQ8dTd1STpIbnCQvcAAAxc0uzKULY68IpSNu3aFbC5jRFPFm CbxjI0kzwrqkkE/29g+z13Yl0mvEm0n0VccvBGkAkXaRwTsNuXi0+t0hV7qcnZ3Wfj BYz1Kgk++D4NdT0F68oa6nD0eMpSc2Ijehh93dp4= 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 22CB4384A88A for ; Fri, 10 Sep 2021 11:23:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 22CB4384A88A Received: by mail-qt1-x849.google.com with SMTP id x28-20020ac8701c000000b0029f4b940566so4909315qtm.19 for ; Fri, 10 Sep 2021 04:23:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ER1TOFUJ5OFEYlck3D6dMrV5/bpq+Qz2ApAvpwitnyU=; b=e+kjKBufq7ft0m9ODFmuA6RVtMKJWRz/pzJdsjwsJNBoW2vCRw2y5o+pGi1W8wWva5 ESAQF4IEfGjXtXbEO5u4BcZbrbz68bMSMNuk8NU7F/dUUvimvoXWQ8rZ+0vd5atfugS2 5+B51PAxgMfLhjhl6qBmhzRE6zrTEDjAeHmaEprjNRZOM/j3Wc2XVUb9kBEj6+kamC3W Ev1eVlF36L01AQ0ZNqkg0cdIu0g2H13TOmHo40TKZCDHSSHJCd3D92RgA2wmqdIVdFX1 bEpM3SfF3REaknriO4YPdclJUcAG/XJNY1PLTGNqs6V2tF0HppNbn+q6cCLK2K18vYDd FIdg== X-Gm-Message-State: AOAM531dXeiKj6PpAjPHhjDOQp7A1YJA/kJ+bK7FFLqUEIvYFCPUJ0cJ XptMCNLbWzQ8F6+uy2ASIeSKt6jWJIYQ0NHVcE3shanTJuCSDSnQ+3+bRJR9SmF3SYzxIjlFnUg XfaGjzxMrrdBq9VZGsGNCh1uLmxA84xZKnhv5pz294SFgJ/g4PtaVq0kRPAdaHONVzg3eTOw= X-Google-Smtp-Source: ABdhPJy9x3niRsAQdfneN6TcqrDS/rplyIsySb/8RsW1gm4T9lcMHoCR79qWvDaI2HJwFNa3/kMWg4Tl4D2k9g== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:210:fe2b:14b7:895d:9020]) (user=gprocida job=sendgmr) by 2002:a05:6214:11e5:: with SMTP id e5mr7892672qvu.55.1631273015693; Fri, 10 Sep 2021 04:23:35 -0700 (PDT) Date: Fri, 10 Sep 2021 12:23:24 +0100 In-Reply-To: <20210910112325.806676-1-gprocida@google.com> Message-Id: <20210910112325.806676-4-gprocida@google.com> Mime-Version: 1.0 References: <20210910112325.806676-1-gprocida@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH 3/4] abg-writer: allow debugging of equality / hash issues To: libabigail@sourceware.org X-Spam-Status: No, score=-21.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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, kernel-team@android.com Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" Inconsistenencies between equality and hash values can and have caused hard-to-debug issues. There are quite a few unordered sets and maps in the XML writer that use deep_ptr_eq_functor and type_hasher. New ./configure option: --enable-debug-equality-hash-consistency A simple way of tracking down potential issues is to check for inconsistencies any time a type is looked up or inserted into a container. * src/abg-writer.cc (get_id_for_type): Add a debugging stanza that, before a type is looked up or inserted, asserts that if it is equal to an existing mapped type then their hash values must be the same. Signed-off-by: Giuliano Procida --- configure.ac | 16 ++++++++ src/abg-writer.cc | 102 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 98 insertions(+), 20 deletions(-) diff --git a/configure.ac b/configure.ac index 735cc9de..8870a7e7 100644 --- a/configure.ac +++ b/configure.ac @@ -72,6 +72,12 @@ AC_ARG_ENABLE(debug-self-comparison, ENABLE_DEBUG_SELF_COMPARISON=$enableval, ENABLE_DEBUG_SELF_COMPARISON=no) +AC_ARG_ENABLE(debug-equality-hash-consistency, + AS_HELP_STRING([--enable-debug-equality-hash-consistency=yes|no], + [enable debugging of equality / hash value consistency in unordered maps (default is no)]), + ENABLE_DEBUG_EQUALITY_HASH_CONSISTENCY=$enableval, + ENABLE_DEBUG_EQUALITY_HASH_CONSISTENCY=no) + AC_ARG_ENABLE(deb, AS_HELP_STRING([--enable-deb=yes|no|auto], [enable the support of deb in abipkgdiff (default is auto)]), @@ -313,6 +319,16 @@ fi AM_CONDITIONAL(ENABLE_DEBUG_SELF_COMPARISON, test x$ENABLE_DEBUG_SELF_COMPARISON = xyes) +dnl enable the debugging of equality / hash value consistency in the abidw XML writer +if test x$ENABLE_DEBUG_EQUALITY_HASH_CONSISTENCY = xyes; then + AC_DEFINE([WITH_DEBUG_EQUALITY_HASH_CONSISTENCY], 1, [compile equality / hash value consistency checks]) + AC_MSG_NOTICE([support of debugging equality / hash value consistency is enabled]) +else + AC_MSG_NOTICE([support of debugging equality / hash value consistency is disabled]) +fi + +AM_CONDITIONAL(ENABLE_DEBUG_EQUALITY_HASH_CONSISTENCY, test x$ENABLE_DEBUG_EQUALITY_HASH_CONSISTENCY = xyes) + dnl Check for the dpkg program if test x$ENABLE_DEB = xauto -o x$ENABLE_DEB = xyes; then AC_CHECK_PROG(HAS_DPKG, dpkg, yes, no) diff --git a/src/abg-writer.cc b/src/abg-writer.cc index 795ca685..cf664720 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -115,6 +115,41 @@ struct type_hasher {return hash_type(t);} }; // end struct type_hasher +template +static void check_set_equality_hash_consistency( + const T& haystack, const typename T::key_type& needle) +{ +#ifdef WITH_DEBUG_EQUALITY_HASH_CONSISTENCY + abigail::diff_utils::deep_ptr_eq_functor eq; + type_hasher hasher; + const auto needle_hash = hasher(needle); + for (const auto& key : haystack) + ABG_ASSERT(!eq(needle, key) || needle_hash == hasher(key)); +#else + (void) haystack; + (void) needle; +#endif +} + +template +static void check_map_equality_hash_consistency( + const T& haystack, const typename T::key_type& needle) +{ +#ifdef WITH_DEBUG_EQUALITY_HASH_CONSISTENCY + abigail::diff_utils::deep_ptr_eq_functor eq; + type_hasher hasher; + const auto needle_hash = hasher(needle); + for (const auto& key_value : haystack) + { + const auto& key = key_value.first; + ABG_ASSERT(!eq(key, needle) || needle_hash == hasher(key)); + } +#else + (void) haystack; + (void) needle; +#endif +} + /// A convenience typedef for a map that associates a pointer to type /// to a string. The pointer to type is hashed as fast as possible. typedef unordered_map(t); + check_map_equality_hash_consistency(m_type_id_map, c); auto insertion = m_type_id_map.emplace(c, interned_string()); interned_string& id = insertion.first->second; @@ -544,14 +580,25 @@ public: { // If the type is a function type, record it in a dedicated data // structure. - if (function_type* f = is_function_type(t.get())) - m_referenced_fn_types_set.insert(f); - else if (!t->get_naked_canonical_type()) - // If the type doesn't have a canonical type, record it in a - // dedicated data structure. - m_referenced_non_canonical_types_set.insert(t.get()); + type_base* t_ptr = t.get(); + if (function_type* f = is_function_type(t_ptr)) + { + check_set_equality_hash_consistency(m_referenced_fn_types_set, f); + m_referenced_fn_types_set.insert(f); + } + else if (!t_ptr->get_naked_canonical_type()) + { + // If the type doesn't have a canonical type, record it in a + // dedicated data structure. + check_set_equality_hash_consistency( + m_referenced_non_canonical_types_set, t_ptr); + m_referenced_non_canonical_types_set.insert(t_ptr); + } else - m_referenced_types_set.insert(t.get()); + { + check_set_equality_hash_consistency(m_referenced_types_set, t_ptr); + m_referenced_types_set.insert(t_ptr); + } } /// Test if a given type has been referenced by a pointer, a @@ -564,15 +611,26 @@ public: bool type_is_referenced(const type_base_sptr& t) { - if (function_type *f = is_function_type(t.get())) - return (m_referenced_fn_types_set.find(f) - != m_referenced_fn_types_set.end()); - else if (!t->get_naked_canonical_type()) - return (m_referenced_non_canonical_types_set.find(t.get()) - != m_referenced_non_canonical_types_set.end()); + type_base* t_ptr = t.get(); + if (function_type *f = is_function_type(t_ptr)) + { + check_set_equality_hash_consistency(m_referenced_fn_types_set, f); + return (m_referenced_fn_types_set.find(f) + != m_referenced_fn_types_set.end()); + } + else if (!t_ptr->get_naked_canonical_type()) + { + check_set_equality_hash_consistency( + m_referenced_non_canonical_types_set, t_ptr); + return (m_referenced_non_canonical_types_set.find(t_ptr) + != m_referenced_non_canonical_types_set.end()); + } else - return m_referenced_types_set.find - (t.get()) != m_referenced_types_set.end(); + { + check_set_equality_hash_consistency(m_referenced_types_set, t_ptr); + return (m_referenced_types_set.find(t_ptr) + != m_referenced_types_set.end()); + } } /// A comparison functor to compare pointers to @ref type_base. @@ -727,6 +785,7 @@ public: type_base *c = t->get_naked_canonical_type(); if (c == 0) c = const_cast(t); + check_set_equality_hash_consistency(m_emitted_type_set, c); m_emitted_type_set.insert(c); } @@ -739,6 +798,7 @@ public: bool type_is_emitted(const type_base *t) const { + check_set_equality_hash_consistency(m_emitted_type_set, t); return m_emitted_type_set.find(t) != m_emitted_type_set.end(); } @@ -792,6 +852,7 @@ public: { class_or_union* cl = is_class_or_union_type(t); ABG_ASSERT(cl && cl->get_is_declaration_only()); + check_set_equality_hash_consistency(m_emitted_decl_only_set, t); m_emitted_decl_only_set.insert(t); } @@ -814,10 +875,8 @@ public: bool decl_only_type_is_emitted(const type_base* t) const { - type_ptr_set_type::const_iterator i = m_emitted_decl_only_set.find(t); - if (i == m_emitted_decl_only_set.end()) - return false; - return true; + check_set_equality_hash_consistency(m_emitted_decl_only_set, t); + return m_emitted_decl_only_set.find(t) != m_emitted_decl_only_set.end(); } /// Test if a declaration-only class has been emitted. @@ -2273,7 +2332,10 @@ record_unemitted_type(type_ptr_set_type& types, == tu.get_absolute_path()) && !ctxt.type_is_emitted(t) && !ctxt.decl_only_type_is_emitted(t)) - types.insert(t); + { + check_set_equality_hash_consistency(types, t); + types.insert(t); + } } /// Serialize a translation unit to an output stream. From patchwork Fri Sep 10 11:23:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 44923 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 9282F385782D for ; Fri, 10 Sep 2021 11:23:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9282F385782D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1631273026; bh=z6id3APP/iqrHuzUzcjZXOHnYweJygyPP3UyQiTJmJQ=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=BLTKR7h6t1LlYokrswO3dMWllT5AZb/l6QSlkheKao2+AKIsbk0js9Mou47i1o2lS cMUJC7fMYxdG7EKEdYxHHZJclm1fbOTj3LBuePUoeeg0sDgI6SgZIBGM8uD4aDoFWU tbuh2/x2v+szHCCqh2muGMSgLVuesHSTuQDsOEHA= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by sourceware.org (Postfix) with ESMTPS id 08B8F3858404 for ; Fri, 10 Sep 2021 11:23:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 08B8F3858404 Received: by mail-qk1-x74a.google.com with SMTP id h7-20020a37b707000000b003fa4d25d9d0so4371215qkf.17 for ; Fri, 10 Sep 2021 04:23:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=z6id3APP/iqrHuzUzcjZXOHnYweJygyPP3UyQiTJmJQ=; b=DPmrefPPkMbuCMBDIjCb4KYLhsbNnfE0j8w1HcjsvJjwDXCWXUohDxta5hwctvcAXb KAjZD3ix2/xBz7krIW4KFKsN82CblikkT4G0Z4ZRwFkmd22BtQCOhFqo59P16Iwoz4mB w6n48v5fCDuTOOjXqMj3O/RmOKNuEaymCSVQvwaL+NmEuCxssGZENKavtKVQjsYzt8C/ WRrnO2OnBlh9SPqy9FOBk2PjCGFPLF2iF1mNUtFrPnAbmdVpRVeQ4wu3HmMzQb6TJUTb wDdw/niTxmVYP0nbSz9gs7Y0gSwnXNp90bgz5OqOn3yJGR2G7eGoH178Qitxa77x/jbl Yj/w== X-Gm-Message-State: AOAM531xR9rF0pLRVINJmsWa5eoCtgQVRymPGld2qSNCJKPizufGkPpd ISlWiWOFaYGspGoOLCWU4zNggs6SBAkBJxo7xsUxaExtcUh67jVUsm4HomburM/2khgMaZRDxub s/BpNA/t1Pybp/dKO9XK7pgmx0op3SoUL+sKmywWcevMxfrUZ1xrXDTCmcFlpOxPXPPJcGwg= X-Google-Smtp-Source: ABdhPJyS+nJo6MDJHIkIsipstQqZIMO165eaKCS7ApGPDapfZLevBxoGeLILC9gMxytrKODJBbCOdbtf53Oo4g== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:210:fe2b:14b7:895d:9020]) (user=gprocida job=sendgmr) by 2002:ad4:4623:: with SMTP id x3mr6058969qvv.17.1631273017650; Fri, 10 Sep 2021 04:23:37 -0700 (PDT) Date: Fri, 10 Sep 2021 12:23:25 +0100 In-Reply-To: <20210910112325.806676-1-gprocida@google.com> Message-Id: <20210910112325.806676-5-gprocida@google.com> Mime-Version: 1.0 References: <20210910112325.806676-1-gprocida@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH 4/4] RFC: abg-writer: add a missing check for emitted declarations 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, kernel-team@android.com Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" Before writing out extra referenced types, the function write_translation_unit does not check if this was an already emitted declaration-only type. This may actually be intentional, given the following comment. // We allow several *declarations* of the same class in the corpus, // but only one definition. * src/abg-writer.cc (write_translation_unit): Also check if an an extra referenced type is declaration-only and already emitted. Signed-off-by: Giuliano Procida --- src/abg-writer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abg-writer.cc b/src/abg-writer.cc index cf664720..abd5a45a 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -2484,7 +2484,7 @@ write_translation_unit(write_context& ctxt, // We handle types which have declarations *and* function // types here. type_base_sptr t(*i, noop_deleter()); - if (!ctxt.type_is_emitted(t)) + if (!ctxt.type_is_emitted(t) && !ctxt.decl_only_type_is_emitted(t)) { if (decl_base* d = get_type_declaration(*i)) {