From patchwork Wed Sep 9 08:50:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 40385 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 57753386EC70; Wed, 9 Sep 2020 08:51:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57753386EC70 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599641461; bh=tqu2LF9l2HO5UPTLDMusMxbxNhbRCz+mNpGQrkkKY6w=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:Cc:From; b=CfP3oSw1oHTkmnxj4YCLzSO5RZKQx4hODZ0SmTutB6u2O4QwPvdvqvJ39YqavkmpR x2DhcVNGovQ6Hxe6fNX1T8+ga/AoSYOMHXcST2VvetVz30hwIezPOJRNBxT6qT+4L6 OMMEsTcTl7kWop/5vKwttaiz//GBI5ozY13ExL/w= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 3BF0C3846034 for ; Wed, 9 Sep 2020 08:50:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3BF0C3846034 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-326-O5tVic9wPoGnrqBJ6IczcA-1; Wed, 09 Sep 2020 04:50:50 -0400 X-MC-Unique: O5tVic9wPoGnrqBJ6IczcA-1 Received: by mail-wm1-f69.google.com with SMTP id a7so539809wmc.2 for ; Wed, 09 Sep 2020 01:50:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:organization:date:message-id :user-agent:mime-version; bh=tqu2LF9l2HO5UPTLDMusMxbxNhbRCz+mNpGQrkkKY6w=; b=ixaW8CyUUJnx1B6Z/9RPRRXyNqcztmmZ4+8f0VXEjcC4KAFR33Z5Fp/FcJm73bwJxz 4c0S4tgFqTvsBD2N9ynY9mJX3jBGWMV7xuEo4rYNbaQZGC2U1xqEeZkdwMJfxFfHB+N1 sckmdVk+AOpFd5wGKWUScptaKC+dBPMFU5TE/Y0EyP2PO0InFwhRrs6uMtkqbMgFfrMf YD+F41B9G3Dds0wW9VWEwd1rOuR+TrV6FiU4+Aoy3vbzCcwEV+pr5q5PCbcxIixAKlrZ Sc2ScTVkUWTjwSc2RnPnJ9qLhbiebm1kcO4aNi3YHuYjRgAe9OrwClF5BKSQvJpTMEek D8GA== X-Gm-Message-State: AOAM5314lhim9kxdrR1i8qOfQWuABuJstq5ywX+DMlWDVc4o0PiGx2Fz 7OJciY1eZdlTOPm6y7oMDvmvii6HPs4PR00qwToHVNQ0RNd/xjlMFZKHJ61LLLQcIRg/PXKwv+i LECw8ENVvkZMcHb4GKT6d X-Received: by 2002:a05:6000:d0:: with SMTP id q16mr2863315wrx.24.1599641448036; Wed, 09 Sep 2020 01:50:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbB1v8V6tNHSsC5vULYuZi9EXGdGqpS8c8e3uLNnOsE5HeInZFRcZ8oL9qwfdmIoKeruThQw== X-Received: by 2002:a05:6000:d0:: with SMTP id q16mr2863276wrx.24.1599641447535; Wed, 09 Sep 2020 01:50:47 -0700 (PDT) Received: from localhost (91-166-131-130.subs.proxad.net. [91.166.131.130]) by smtp.gmail.com with ESMTPSA id t4sm3011971wrr.26.2020.09.09.01.50.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Sep 2020 01:50:46 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id 3BCB218009D8; Wed, 9 Sep 2020 10:50:42 +0200 (CEST) To: libabigail@sourceware.org Subject: [PATCH 2/2] writer: Avoid using dynamic hashing in type maps Organization: Red Hat / France X-Operating-System: Red Hat Enterprise Linux Workstation 7.8 Beta X-URL: http://www.redhat.com Date: Wed, 09 Sep 2020 10:50:42 +0200 Message-ID: <877dt3tjtp.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP 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: Dodji Seketeli via Libabigail From: Dodji Seketeli Reply-To: Dodji Seketeli Cc: Matthias Maennich Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" Hello, This patch the second of a series of two which intends to improve type equality handling, particularly in the abixml writer, for the small number of types that are not canonicalized. When using type maps the hash used for a given type T is usually the pointer value of the canonical type of T. In the rare cases where T doesn't have a canonical type, we were using a 'dynamic hash' computed by recursively walking the components of T and progressively building a hash that way. The dynamic hashing code hasn't been updated in a while and would need some overhaul to support hashing with schemes like MD5 or maybe sha even. It might be useful for various use cases that have been proposed by some users over the years but nobody was motivated enough to implement it. In the mean time, rather than trying to come up with a fully beefed up dynamic hashing code, we'd rather just return a constant number for non canonicalized types. In practise that amounts to forcing the code of the maps to always use structural comparison for those non canonicalized types. Note that the amount of non-canonicalized types should be fairly small. For now, the only non-canonicalized types should be declaration-only types and those are quite fast to compare anyway. This patch thus introduces a new hashing scheme for maps in the writer which just uses a numerical constant as the hash for non-canonicalized types. * include/abg-fwd.h (hash_as_canonical_type_or_constant): Declare ... * src/abg-ir.cc (hash_as_canonical_type_or_constant): ... new function. * src/abg-writer.cc (type_hasher::operator()): Use the new hash_as_canonical_type_or_constant. * tests/data/test-read-dwarf/test16-pr18904.so.abi: Adjust. Signed-off-by: Dodji Seketeli --- include/abg-fwd.h | 3 + src/abg-ir.cc | 39 +++ src/abg-writer.cc | 2 +- tests/data/test-read-dwarf/test16-pr18904.so.abi | 302 +++++++++++------------ 4 files changed, 194 insertions(+), 152 deletions(-) diff --git a/include/abg-fwd.h b/include/abg-fwd.h index 4b09929..a2caf9b 100644 --- a/include/abg-fwd.h +++ b/include/abg-fwd.h @@ -1333,6 +1333,9 @@ hash_type_or_decl(const type_or_decl_base *); size_t hash_type_or_decl(const type_or_decl_base_sptr &); +size_t +hash_as_canonical_type_or_constant(const type_base* t); + bool function_decl_is_less_than(const function_decl&f, const function_decl &s); diff --git a/src/abg-ir.cc b/src/abg-ir.cc index d98d4bd..088eebb 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -23085,6 +23085,45 @@ size_t hash_type_or_decl(const type_or_decl_base_sptr& tod) {return hash_type_or_decl(tod.get());} +/// Hash a type by either returning the pointer value of its canonical +/// type or by returning a constant if the type doesn't have a +/// canonical type. +/// +/// @param t the type to consider. +/// +/// @return the hash value. +size_t +hash_as_canonical_type_or_constant(const type_base *t) +{ + type_base *canonical_type = 0; + + if (t) + canonical_type = t->get_naked_canonical_type(); + + if (!canonical_type) + { + // If the type doesn't have a canonical type, maybe it's because + // it's a declaration-only type? If that's the case, let's try + // to get the canonical type of the definition of this + // declaration. + decl_base *decl = is_decl(t); + if (decl + && decl->get_is_declaration_only() + && decl->get_naked_definition_of_declaration()) + { + type_base *definition = + is_type(decl->get_naked_definition_of_declaration()); + ABG_ASSERT(definition); + canonical_type = definition->get_naked_canonical_type(); + } + } + + if (canonical_type) + return reinterpret_cast(canonical_type); + + return 0xDEADBABE; +} + /// Test if the pretty representation of a given @ref function_decl is /// lexicographically less then the pretty representation of another /// @ref function_decl. diff --git a/src/abg-writer.cc b/src/abg-writer.cc index 4c751c2..59060e1 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -136,7 +136,7 @@ struct type_hasher { size_t operator()(const type_base* t) const - {return hash_type(t);} + {return hash_as_canonical_type_or_constant(t);} }; // end struct type_hasher /// A convenience typedef for a map that associates a pointer to type diff --git a/tests/data/test-read-dwarf/test16-pr18904.so.abi b/tests/data/test-read-dwarf/test16-pr18904.so.abi index 0075a6e..377d322 100644 --- a/tests/data/test-read-dwarf/test16-pr18904.so.abi +++ b/tests/data/test-read-dwarf/test16-pr18904.so.abi @@ -35191,7 +35191,7 @@ - + @@ -35201,7 +35201,7 @@ - + @@ -36488,13 +36488,13 @@ - + - + - + @@ -36624,14 +36624,14 @@ - + - + @@ -36641,7 +36641,7 @@ - + @@ -36680,9 +36680,9 @@ - - - + + + @@ -36710,7 +36710,7 @@ - + @@ -36718,13 +36718,13 @@ - + - + @@ -36732,7 +36732,7 @@ - + @@ -36740,23 +36740,23 @@ - + - + - + - + - + - + @@ -36805,53 +36805,53 @@ - + - + - + - + - + - + - + - - + + - - - + + + - - + + - + @@ -36863,92 +36863,92 @@ - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - - - + + + - + - + - + - + - + - + - + - + - + - + - + - + - - + + @@ -36961,19 +36961,19 @@ - + - + - + @@ -36984,7 +36984,7 @@ - + @@ -36998,7 +36998,7 @@ - + @@ -37012,7 +37012,7 @@ - + @@ -37026,7 +37026,7 @@ - + @@ -37040,7 +37040,7 @@ - + @@ -37054,7 +37054,7 @@ - + @@ -37068,7 +37068,7 @@ - + @@ -37082,7 +37082,7 @@ - + @@ -37098,19 +37098,19 @@ - + - + - + - + - + @@ -37135,37 +37135,37 @@ - - + + - - + + - + - + - - + + - + @@ -37195,26 +37195,26 @@ - - + + - + - + - + - + - + - + @@ -37268,13 +37268,13 @@ - + - + - + @@ -37295,13 +37295,13 @@ - + - + @@ -37333,35 +37333,35 @@ - - + + - + - + - + - + @@ -37374,13 +37374,13 @@ - + - + - + @@ -37401,13 +37401,13 @@ - + - + @@ -37439,35 +37439,35 @@ - - + + - + - + - + - + @@ -38096,71 +38096,71 @@ - + - - + + - + - + - - + + - - + + - + - - - - + + + + - - - - - + + + + + - - + + - + - - + + - - + + - - + +