From patchwork Tue Oct 1 15:27:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 98214 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 3F6D13861003 for ; Tue, 1 Oct 2024 15:27:49 +0000 (GMT) X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id D446C3858CD9 for ; Tue, 1 Oct 2024 15:27:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D446C3858CD9 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D446C3858CD9 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727796462; cv=none; b=WDECTiWRix93VWtK0kCQ6RRgXiy4JGs1UFlSqcja1aYC5SAHwbZCbuRu/yGjYMUNkMk6u98aot+NYDv8nw33DYOONj3tSYu44gBJsRw+jOQQI+GRwaVTkmD4eeDdOL9pC9ZlExSv5T0sZPlbsuhm3gFnxTZxM3Q0UKsU0JNu2ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727796462; c=relaxed/simple; bh=XO4Nn6QhdqSdK1/0O9wstwLbixs2NpWr22D7/wIuZ9c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DBCL8ks/mBvqWJx9/ej345vySybin9tGLI1CeXCMUhmaOmkl61thVL9L9fzwjDpuWcaBMbdffzZ+WFTviv91w0TcUa8e3gtXnACIHZjpJSOi9nAS58q8SGWoxO0ouEgrudgwUUNMltqRYItOrYpfpb0ClmpH/AAWE4rWPB6QiE4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727796459; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=h4bTgdyFjXvm3KYESf97Wkd00aU8pW2cf/OuZoTtE/E=; b=QCpT2/a0q7Be2D5mhXVIe7Lh0KXW0u1CMcQcW89psMMbuo78k2OXJQVkWgBiZixa/7hnoE pFzxhhHN18ZxCZ0OFY1VJ7Hn/Te7TMBctQ+2iM7kZC9KWF/b3uaQDXrXx019cYocInvIN5 usN76J8fc9bll2GFBHz3Uuh0Nh2wNGI= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-332-m2lHomDyPFmMvA7p7jmRZQ-1; Tue, 01 Oct 2024 11:27:38 -0400 X-MC-Unique: m2lHomDyPFmMvA7p7jmRZQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7a9bb56da15so744269885a.1 for ; Tue, 01 Oct 2024 08:27:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727796458; x=1728401258; h=mime-version:user-agent:message-id:date:organization:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=h4bTgdyFjXvm3KYESf97Wkd00aU8pW2cf/OuZoTtE/E=; b=LQkDpHQeqxRoaCqBFAVU5fCAOc46cPL3kkNL63HxMJwkEbU8HfAi6gA4vVJT1/4wTZ 7+z3JNDSl8bHZUCbAM7vV2wb1BTaaukZFKo/zbkTtSGc6G7OYN7QSdLqMip+yqbi3h9u T9CPhtmZC89nME1I5bBS/def07hC4AR72ZOdaHPQdyt1XU9i+pLqVBy0LaTB7jJmgnkI JChCKGmvC3uamC5n/AV2I9uOJRLQKkhKYgYTc0fYhrTzlamkRld2tgsB4RNYMDZkoZ5x saMxPhQYESMZmW6H//9zY9fCkVktNCS1HfPYXvSbC47RKU+bzzjkHmFhKcQl41XhvbaU biJA== X-Gm-Message-State: AOJu0YynwoU5cdltCtA/kzZb+qktRKziRWZxqKPhOu53EmvMmp4VqE98 4sGkwkY7luftnX5I7GHKCH7K6mscwTTNXBCz06zAbISFDt61OUS2zk7Z5RnZidX5Uffmes1NtcV 7hqoyq64ckFkLZyC/mAjZY4W1KGqYaifAsqD87oOW5LJILa7xc0fSeUtnsRTCGIp+zcJ1bpggqx GDIsLGsxQCiswBYh0p1c8P2EA97KHvpxhIz0J/yw== X-Received: by 2002:a05:620a:1926:b0:7ac:b89f:5308 with SMTP id af79cd13be357-7ae626acf0bmr10459685a.7.1727796457680; Tue, 01 Oct 2024 08:27:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHevcPejdeGckPsR61iXzmb8ml4Ep96HUVrqWnKhj4ylT/76SJ8RYmw+MWUKS07sJ5WcNY4Q== X-Received: by 2002:a05:620a:1926:b0:7ac:b89f:5308 with SMTP id af79cd13be357-7ae626acf0bmr10454685a.7.1727796456969; Tue, 01 Oct 2024 08:27:36 -0700 (PDT) Received: from localhost (88-120-130-27.subs.proxad.net. [88.120.130.27]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7ae377d4f64sm522176385a.29.2024.10.01.08.27.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 08:27:36 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id 52B88507A61B; Tue, 1 Oct 2024 17:27:34 +0200 (CEST) From: Dodji Seketeli To: libabigail@sourceware.org Subject: [PATCH, applied] reader: Drop the hash values coming from older ABIXML files Organization: Red Hat / France X-Operating-System: AlmaLinux 9.4 X-URL: http://www.redhat.com Date: Tue, 01 Oct 2024 17:27:34 +0200 Message-ID: <87ldz7j121.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 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_NONE, TXREP 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.30 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libabigail-bounces~patchwork=sourceware.org@sourceware.org Hello, When the default minor ABIXML version is bumped, make it so that the reader drops the hash values embedded in the ABIXML file. In that case, a new hash value is computed before type canonicalization. This ensures that we can easily change the format of the hash when needed. * src/abg-reader.cc (reader::m_drop_hash_value): Define new data member. (reader::maybe_drop_hash_values): Define new function. (reader::read_hash_and_stash): Make the static function read_hash_and_stash a member function of reader. Make it so that if m_drop_hash_value is define, then no hash value is read from the XML node. (read_type_hash_and_cti): Move declaration of static function before the new reader::read_hash_and_stash. (reader::read_corpus): Call the new maybe_drop_hash_values. (build_function_decl, build_type_decl, build_qualified_type_decl) (build_pointer_type_def, build_reference_type_def) (build_ptr_to_mbr_type, build_function_type, build_subrange_type) (build_array_type_def, build_enum_type_decl, build_typedef_decl) (build_class_decl, build_union_decl): Adjust call to read_hash_and_stash to reader::read_hash_and_stash. Signed-off-by: Dodji Seketeli --- src/abg-reader.cc | 121 ++++++++++++++++++++++++++++------------------ 1 file changed, 75 insertions(+), 46 deletions(-) diff --git a/src/abg-reader.cc b/src/abg-reader.cc index c926d63a..664d844c 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -122,6 +122,8 @@ resolve_symbol_aliases(string_elf_symbols_map_sptr& fn_syms, string_elf_symbols_map_sptr& var_syms, string_strings_map_type& non_resolved_fn_sym_aliases, string_strings_map_type& non_resolved_var_sym_aliases); +static bool +read_type_hash_and_cti(xmlNodePtr, uint64_t& hash, uint64_t& cti); /// The ABIXML reader object. /// @@ -175,6 +177,7 @@ private: deque > m_decls_stack; bool m_tracking_non_reachable_types; bool m_drop_undefined_syms; + bool m_drop_hash_value; #ifdef WITH_SHOW_TYPE_USE_IN_ABILINT unordered_map> m_artifact_used_by_map; @@ -189,7 +192,8 @@ public: m_reader(reader), m_corp_node(), m_tracking_non_reachable_types(), - m_drop_undefined_syms() + m_drop_undefined_syms(), + m_drop_hash_value() { } @@ -1158,6 +1162,8 @@ public: handle_version_attribute(xml_reader, corp); + maybe_drop_hash_values(); + xml::xml_char_sptr path_str = XML_READER_GET_ATTRIBUTE(xml_reader, "path"); string path; @@ -1408,6 +1414,61 @@ public: status = STATUS_OK; return corpus(); } + + /// Test if the reader should drop the hash values coming from the + /// ABIXML on the floor. + /// + /// If the minor version number of the ABIXML document is older than + /// the current minor abixml version of the document being read, + /// then the hash values are dropped and new ones are going to be + /// computed by ir::hash_and_canonicalize_types. + void + maybe_drop_hash_values() + { + string current_major, current_minor; + abigail::abigail_get_abixml_version(current_major, current_minor); + + if (current_major.empty() || current_minor.empty()) + return; + + ir::corpus& corp = *corpus(); + bool drop_hash_values_from_abixml = false; + if (current_major > corp.get_format_major_version_number() + || current_minor > corp.get_format_minor_version_number()) + drop_hash_values_from_abixml = true; + + if (drop_hash_values_from_abixml) + m_drop_hash_value = true; + } + + /// Read the hash value from an XML node and set it onto an IR node. + /// + /// @param node the XML node to read the hash value from. + /// + /// @param ir_node output parameter. The IR node to set the hash + /// value read from @p node onto. + void + read_hash_and_stash(const xmlNodePtr node, + const type_or_decl_base_sptr& ir_node) + { + uint64_t hash = 0, cti = 0; + if (!m_drop_hash_value + && read_type_hash_and_cti(node, hash, cti)) + { + ir_node->priv_->force_set_hash_value(hash); + type_base_sptr type; + if (function_decl_sptr fn = is_function_decl(ir_node)) + type = fn->get_type(); + else + type = is_type(ir_node); + + if (type) + { + type->type_or_decl_base::priv_->force_set_hash_value(hash); + type->priv_->canonical_type_index = cti; + } + } + } };// end class reader typedef shared_ptr reader_sptr; @@ -1441,10 +1502,6 @@ static bool read_elf_symbol_type(xmlNodePtr, elf_symbol::type&); static bool read_elf_symbol_binding(xmlNodePtr, elf_symbol::binding&); static bool read_elf_symbol_visibility(xmlNodePtr, elf_symbol::visibility&); -static bool read_type_hash_and_cti(xmlNodePtr, uint64_t& hash, - uint64_t& cti); -static void read_hash_and_stash(const xmlNodePtr, - const type_or_decl_base_sptr&); static namespace_decl_sptr build_namespace_decl(reader&, const xmlNodePtr, bool); @@ -3204,34 +3261,6 @@ read_type_hash_and_cti(xmlNodePtr node, uint64_t& hash, uint64_t& cti) return false; } -/// Read the hash value from an XML node and set it onto an IR node. -/// -/// @param node the XML node to read the hash value from. -/// -/// @param ir_node output parameter. The IR node to set the hash -/// value read from @p node onto. -static void -read_hash_and_stash(const xmlNodePtr node, - const type_or_decl_base_sptr& ir_node) -{ - uint64_t hash = 0, cti = 0; - if (read_type_hash_and_cti(node, hash, cti)) - { - ir_node->priv_->force_set_hash_value(hash); - type_base_sptr type; - if (function_decl_sptr fn = is_function_decl(ir_node)) - type = fn->get_type(); - else - type = is_type(ir_node); - - if (type) - { - type->type_or_decl_base::priv_->force_set_hash_value(hash); - type->priv_->canonical_type_index = cti; - } - } -} - #ifdef WITH_DEBUG_SELF_COMPARISON /// Associate a type-id string with the type that was constructed from /// it. @@ -3885,7 +3914,7 @@ build_function_decl(reader& rdr, ABG_ASSERT(fn_type); - read_hash_and_stash(node, fn_type); + rdr.read_hash_and_stash(node, fn_type); fn_type->set_is_artificial(true); @@ -4314,7 +4343,7 @@ build_type_decl(reader& rdr, decl->set_is_anonymous(is_anonymous); decl->set_is_declaration_only(is_decl_only); // Read the stash from the XML node and stash it into the IR node. - read_hash_and_stash(node, decl); + rdr.read_hash_and_stash(node, decl); if (rdr.push_and_key_type_decl(decl, node, add_to_current_scope)) { @@ -4415,7 +4444,7 @@ build_qualified_type_decl(reader& rdr, RECORD_ARTIFACT_AS_USED_BY(rdr, underlying_type, decl); } // Read the stash from the XML node and stash it into the IR node. - read_hash_and_stash(node, decl); + rdr.read_hash_and_stash(node, decl); rdr.map_xml_node_to_decl(node, decl); @@ -4505,7 +4534,7 @@ build_pointer_type_def(reader& rdr, rdr.map_xml_node_to_decl(node, t); // Read the stash from the XML node and stash it into the IR node. - read_hash_and_stash(node, t); + rdr.read_hash_and_stash(node, t); RECORD_ARTIFACT_AS_USED_BY(rdr, pointed_to_type, t); return t; @@ -4597,7 +4626,7 @@ build_reference_type_def(reader& rdr, rdr.map_xml_node_to_decl(node, t); // Read the stash from the XML node and stash it into the IR node. - read_hash_and_stash(node, t); + rdr.read_hash_and_stash(node, t); RECORD_ARTIFACT_AS_USED_BY(rdr, pointed_to_type, t); @@ -4694,7 +4723,7 @@ build_ptr_to_mbr_type(reader& rdr, loc)); // Read the stash from the XML node and stash it into the IR node. - read_hash_and_stash(node, result); + rdr.read_hash_and_stash(node, result); if (rdr.push_and_key_type_decl(result, node, add_to_current_scope)) rdr.map_xml_node_to_decl(node, result); @@ -4759,7 +4788,7 @@ build_function_type(reader& rdr, parms, size, align)); // Read the stash from the XML node and stash it into the IR node. - read_hash_and_stash(node, fn_type); + rdr.read_hash_and_stash(node, fn_type); rdr.get_translation_unit()->bind_function_type_life_time(fn_type); rdr.key_type_decl(fn_type, id); @@ -4935,7 +4964,7 @@ build_subrange_type(reader& rdr, p->set_size_in_bits(size_in_bits); // Read the stash from the XML node and stash it into the IR node. - read_hash_and_stash(node, p); + rdr.read_hash_and_stash(node, p); if (rdr.push_and_key_type_decl(p, node, add_to_current_scope)) rdr.map_xml_node_to_decl(node, p); @@ -5056,7 +5085,7 @@ build_array_type_def(reader& rdr, array_type_def_sptr ar_type(new array_type_def(type, subranges, loc)); // Read the stash from the XML node and stash it into the IR node. - read_hash_and_stash(node, ar_type); + rdr.read_hash_and_stash(node, ar_type); maybe_set_artificial_location(rdr, node, ar_type); if (rdr.push_and_key_type_decl(ar_type, node, add_to_current_scope)) @@ -5250,7 +5279,7 @@ build_enum_type_decl(reader& rdr, t->set_is_artificial(is_artificial); t->set_is_declaration_only(is_decl_only); // Read the stash from the XML node and stash it into the IR node. - read_hash_and_stash(node, t); + rdr.read_hash_and_stash(node, t); if (rdr.push_and_key_type_decl(t, node, add_to_current_scope)) { @@ -5328,7 +5357,7 @@ build_typedef_decl(reader& rdr, maybe_set_artificial_location(rdr, node, t); // Read the hash from the XML node and stash it into the IR node. - read_hash_and_stash(node, t); + rdr.read_hash_and_stash(node, t); rdr.push_and_key_type_decl(t, node, add_to_current_scope); rdr.map_xml_node_to_decl(node, t); @@ -5521,7 +5550,7 @@ build_class_decl(reader& rdr, decl->set_is_artificial(is_artificial); // Read the stash from the XML node and stash it into the IR node. - read_hash_and_stash(node, decl); + rdr.read_hash_and_stash(node, decl); string def_id; bool is_def_of_decl = false; @@ -5946,7 +5975,7 @@ build_union_decl(reader& rdr, } // Read the stash from the XML node and stash it into the IR node. - read_hash_and_stash(node, decl); + rdr.read_hash_and_stash(node, decl); maybe_set_artificial_location(rdr, node, decl); decl->set_is_artificial(is_artificial);