From patchwork Fri May 15 17:47:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 39272 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 1E03D3887006; Fri, 15 May 2020 17:48:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E03D3887006 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1589564880; bh=x9tZD1DpTJvgUWkGWdTJBSZDQ1ObtC2bJU3r8kaFV6E=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:Cc:From; b=kKuqIFfVIHyf42cdyji4lAp1BQ4e5SwHdY3MfD51crqUCwJzmABMzCujp6vTHeRS5 E+CTkGCl9mHQOA0cnt8ZZPX7sN305iynU9PFOc+Uu8moRtriCN0rVxHA65wwq7Ezap CsEm20Ya/oEFUVWHVVt2IeKYdtriJesg0EpS4OVI= 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 65AB8385DC1C for ; Fri, 15 May 2020 17:47:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 65AB8385DC1C Received: by mail-qk1-x749.google.com with SMTP id r124so3043159qkf.1 for ; Fri, 15 May 2020 10:47: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:message-id:mime-version:subject:from:to:cc; bh=x9tZD1DpTJvgUWkGWdTJBSZDQ1ObtC2bJU3r8kaFV6E=; b=iia4pl3uAE0XOglxu5jjjGpblvoZ6MLHYhbgj/QYhRHpV8t9EyUCZG2HSfOoX5Q0vP 1n6uhVA0Vb7FozUHua8caPMt7CPNPo7o52AU+5KWIeR6e3MtL5dCdvA0jL7/mWwyXOaO owZs/rl1aApKSYEnqp8dOoTD4mq3DXFdm1yA3/s0sczCr0YupLjIG6sv8YNWON+UrVSs K8PVkrQ1r0yt4ZN6nSA6j+uoErxDojIDVPVUEVYZXXit6BJgEpfe5DE7kjjl2YNO4Oy3 jCpzalQnpv2+jG8CyI+nPoSi13JKa2WCdmU52wdwwvEr4gZIJQwQ9HwAKAcXUtmI8UKe jP8A== X-Gm-Message-State: AOAM531cx+KNHREH53u+IiG1PxEYOfbQT8P96Hr7dddCV5kVUeThBWrB I2LqMi0rK5rqvPDnkcGKOAfOJSlHtPXFCcqhNuNrSE+lalGmsYXrdKKMzXWDjB6I3q4VumV0bDi 1r0mb4b05KxDDKnwGI49PT7if/qYBVEwmy5zWVAs9c11J8r/ZcFuDveVwN/SEltGjvHYzasw= X-Google-Smtp-Source: ABdhPJzJ5E6rvq0WKSSl3NJqr5H+0UvFctDPHSZ5gMgp6gNmv6i6L7+l1j3qzJpDRV9ybOlE/P8W8B3jS7JOBQ== X-Received: by 2002:a0c:f1d1:: with SMTP id u17mr4727896qvl.146.1589564867693; Fri, 15 May 2020 10:47:47 -0700 (PDT) Date: Fri, 15 May 2020 18:47:40 +0100 Message-Id: <20200515174740.36885-1-gprocida@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.26.2.761.g0e0b3e54be-goog Subject: [PATCH] abg-dwarf-reader.cc: Simplify WIP type handling. To: libabigail@sourceware.org, maennich@google.com X-Spam-Status: No, score=-24.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: Giuliano Procida via Libabigail From: Giuliano Procida Reply-To: Giuliano Procida Cc: kernel-team@android.com, gprocida@google.com Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" The DWARF reader tracks incompletely declared class/union and function types using 6 maps. Supporting incompletely declared enum types in the same way would require 3 additional maps and more duplicated code. This commit folds together much of the duplicated WIP type handling. This comes at the price of a tiny bit of extra dynamic casting to copy member access specifiers in a couple of places. There are no behavioural changes. * src/abg-dwarf-reader.cc (die_type_map_type): Add new convenience typedef. (read_context): Replace *wip_classes_map_ and *wip_function_map_ members with *die_wip_types_map_ ones, replace die_wip_classes_map and die_wip_function_types_map getters with die_wip_types_map ones, replace is_wip_class_die_offset and is_wip_function_type_die_offset with is_wip_type_die_offset and simplify lookup. (read_context::initialize): Clear *die_wip_types_map_ instead of *wip_classes_map_ *wip_function_map_. (read_context::lookup_type_from_die_offset): Fold together class/union and function conditionals. (read_context::add_or_update_class_type): Replace uses of die_wip_classes_map with die_wip_types_map. Do an extra dynamic cast to be able to fetch member access specifiers in the case the WIP class is a member. (read_context::add_or_update_union_type): Mutatis mutandis. (read_context::build_function_type): Replace uses of die_wip_function_types_map with die_wip_types_map. Simplify removal from the map. (read_context::maybe_canonicalize_type): Replace use is_wip_function_type_die_offset with is_wip_type_die_offset. Signed-off-by: Giuliano Procida --- src/abg-dwarf-reader.cc | 191 +++++++++++++--------------------------- 1 file changed, 59 insertions(+), 132 deletions(-) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 5024deb3..41c40603 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -129,6 +129,10 @@ typedef vector dwarf_offsets_type; /// die and which value is the corresponding artefact. typedef unordered_map die_artefact_map_type; +/// Convenience typedef for a map which key is the offset of a dwarf +/// die and which value is the corresponding type_base. +typedef unordered_map die_type_map_type; + /// Convenience typedef for a map which key is the offset of a dwarf /// die, (given by dwarf_dieoffset()) and which value is the /// corresponding class_decl. @@ -2270,12 +2274,9 @@ public: /// function types, inside a translation unit. mutable istring_fn_type_map_type per_tu_repr_to_fn_type_maps_; - die_class_or_union_map_type die_wip_classes_map_; - die_class_or_union_map_type alternate_die_wip_classes_map_; - die_class_or_union_map_type type_unit_die_wip_classes_map_; - die_function_type_map_type die_wip_function_types_map_; - die_function_type_map_type alternate_die_wip_function_types_map_; - die_function_type_map_type type_unit_die_wip_function_types_map_; + die_type_map_type die_wip_types_map_; + die_type_map_type alternate_die_wip_types_map_; + die_type_map_type type_unit_die_wip_types_map_; die_function_decl_map_type die_function_with_no_symbol_map_; vector types_to_canonicalize_; vector alt_types_to_canonicalize_; @@ -2447,12 +2448,9 @@ public: type_die_artefact_maps_.clear(); canonical_type_die_offsets_.clear(); canonical_decl_die_offsets_.clear(); - die_wip_classes_map_.clear(); - alternate_die_wip_classes_map_.clear(); - type_unit_die_wip_classes_map_.clear(); - die_wip_function_types_map_.clear(); - alternate_die_wip_function_types_map_.clear(); - type_unit_die_wip_function_types_map_.clear(); + die_wip_types_map_.clear(); + alternate_die_wip_types_map_.clear(); + type_unit_die_wip_types_map_.clear(); die_function_with_no_symbol_map_.clear(); types_to_canonicalize_.clear(); alt_types_to_canonicalize_.clear(); @@ -4280,21 +4278,9 @@ public: if (!result) { - // Maybe we are looking for a class type being constructed? - const die_class_or_union_map_type& m = die_wip_classes_map(source); - die_class_or_union_map_type::const_iterator i = m.find(die_offset); - - if (i != m.end()) - result = i->second; - } - - if (!result) - { - // Maybe we are looking for a function type being constructed? - const die_function_type_map_type& m = - die_wip_function_types_map(source); - die_function_type_map_type::const_iterator i = m.find(die_offset); - + // Maybe we are looking for a type being constructed? + const die_type_map_type& m = die_wip_types_map(source); + die_type_map_type::const_iterator i = m.find(die_offset); if (i != m.end()) result = i->second; } @@ -4310,70 +4296,34 @@ public: /// /// @return the map that associates a DIE to the class that is being /// built. - const die_class_or_union_map_type& - die_wip_classes_map(die_source source) const - {return const_cast(this)->die_wip_classes_map(source);} + const die_type_map_type& + die_wip_types_map(die_source source) const + {return const_cast(this)->die_wip_types_map(source);} - /// Getter of a map that associates a die that represents a - /// class/struct with the declaration of the class, while the class - /// is being constructed. + /// Getter of a map that associates a die that represents a type + /// with the declaration of the type, while the type is being + /// constructed. /// /// @param source where the DIE comes from. /// - /// @return the map that associates a DIE to the class that is being + /// @return the map that associates a DIE to the type that is being /// built. - die_class_or_union_map_type& - die_wip_classes_map(die_source source) + die_type_map_type& + die_wip_types_map(die_source source) { switch (source) { case PRIMARY_DEBUG_INFO_DIE_SOURCE: break; case ALT_DEBUG_INFO_DIE_SOURCE: - return alternate_die_wip_classes_map_; + return alternate_die_wip_types_map_; case TYPE_UNIT_DIE_SOURCE: - return type_unit_die_wip_classes_map_; + return type_unit_die_wip_types_map_; case NO_DEBUG_INFO_DIE_SOURCE: case NUMBER_OF_DIE_SOURCES: ABG_ASSERT_NOT_REACHED; } - return die_wip_classes_map_; - } - - /// Getter for a map that associates a die (that represents a - /// function type) whith a function type, while the function type is - /// being constructed (WIP == work in progress). - /// - /// @param source where the DIE comes from.n - /// - /// @return the map of wip function types. - const die_function_type_map_type& - die_wip_function_types_map(die_source source) const - {return const_cast(this)->die_wip_function_types_map(source);} - - /// Getter for a map that associates a die (that represents a - /// function type) whith a function type, while the function type is - /// being constructed (WIP == work in progress). - /// - /// @param source where DIEs of the map come from. - /// - /// @return the map of wip function types. - die_function_type_map_type& - die_wip_function_types_map(die_source source) - { - switch (source) - { - case PRIMARY_DEBUG_INFO_DIE_SOURCE: - break; - case ALT_DEBUG_INFO_DIE_SOURCE: - return alternate_die_wip_function_types_map_; - case TYPE_UNIT_DIE_SOURCE: - return type_unit_die_wip_function_types_map_; - case NO_DEBUG_INFO_DIE_SOURCE: - case NUMBER_OF_DIE_SOURCES: - ABG_ASSERT_NOT_REACHED; - } - return die_wip_function_types_map_; + return die_wip_types_map_; } /// Getter for a map that associates a die with a function decl @@ -4387,40 +4337,20 @@ public: die_function_decl_with_no_symbol_map() {return die_function_with_no_symbol_map_;} - /// Return true iff a given offset is for the DIE of a class that is - /// being built, but that is not fully built yet. WIP == "work in - /// progress". - /// - /// @param offset the DIE offset to consider. - /// - /// @param source where the DIE of the map come from. - /// - /// @return true iff @p offset is the offset of the DIE of a class - /// that is being currently built. - bool - is_wip_class_die_offset(Dwarf_Off offset, die_source source) const - { - die_class_or_union_map_type::const_iterator i = - die_wip_classes_map(source).find(offset); - return (i != die_wip_classes_map(source).end()); - } - - /// Return true iff a given offset is for the DIE of a function type - /// that is being built at the moment, but is not fully built yet. - /// WIP == work in progress. + /// Return true iff a given offset is for the DIE of a type that is + /// being built at the moment, but is not fully built yet. WIP == + /// work in progress. /// /// @param offset DIE offset to consider. /// /// @param source where the DIE comes from. /// - /// @return true iff @p offset is the offset of the DIE of a - /// function type that is being currently built. + /// @return true iff @p offset is the offset of the DIE of a type + /// that is being currently built. bool - is_wip_function_type_die_offset(Dwarf_Off offset, die_source source) const + is_wip_type_die_offset(Dwarf_Off offset, die_source source) const { - die_function_type_map_type::const_iterator i = - die_wip_function_types_map(source).find(offset); - return (i != die_wip_function_types_map(source).end()); + return die_wip_types_map(source).count(offset); } /// Getter for the map of declaration-only classes that are to be @@ -13779,9 +13709,9 @@ add_or_update_class_type(read_context& ctxt, return result; { - die_class_or_union_map_type::const_iterator i = - ctxt.die_wip_classes_map(source).find(dwarf_dieoffset(die)); - if (i != ctxt.die_wip_classes_map(source).end()) + die_type_map_type::const_iterator i = + ctxt.die_wip_types_map(source).find(dwarf_dieoffset(die)); + if (i != ctxt.die_wip_types_map(source).end()) { class_decl_sptr class_type = is_class_type(i->second); ABG_ASSERT(class_type); @@ -13907,7 +13837,7 @@ add_or_update_class_type(read_context& ctxt, // here. return result; - ctxt.die_wip_classes_map(source)[dwarf_dieoffset(die)] = result; + ctxt.die_wip_types_map(source)[dwarf_dieoffset(die)] = result; scope_decl_sptr scop = dynamic_pointer_cast(res); @@ -14090,14 +14020,15 @@ add_or_update_class_type(read_context& ctxt, ctxt.scope_stack().pop(); { - die_class_or_union_map_type::const_iterator i = - ctxt.die_wip_classes_map(source).find(dwarf_dieoffset(die)); - if (i != ctxt.die_wip_classes_map(source).end()) + die_type_map_type::const_iterator i = + ctxt.die_wip_types_map(source).find(dwarf_dieoffset(die)); + if (i != ctxt.die_wip_types_map(source).end()) { - if (is_member_type(i->second)) - set_member_access_specifier(res, - get_member_access_specifier(i->second)); - ctxt.die_wip_classes_map(source).erase(i); + const type_base_sptr& type = i->second; + const decl_base* decl = is_decl(type.get()); + if (is_member_type(type) && decl) + set_member_access_specifier(res, get_member_access_specifier(*decl)); + ctxt.die_wip_types_map(source).erase(i); } } @@ -14144,9 +14075,9 @@ add_or_update_union_type(read_context& ctxt, die_source source; ABG_ASSERT(ctxt.get_die_source(die, source)); { - die_class_or_union_map_type::const_iterator i = - ctxt.die_wip_classes_map(source).find(dwarf_dieoffset(die)); - if (i != ctxt.die_wip_classes_map(source).end()) + die_type_map_type::const_iterator i = + ctxt.die_wip_types_map(source).find(dwarf_dieoffset(die)); + if (i != ctxt.die_wip_types_map(source).end()) { union_decl_sptr u = is_union_type(i->second); ABG_ASSERT(u); @@ -14244,7 +14175,7 @@ add_or_update_union_type(read_context& ctxt, if (!has_child) return result; - ctxt.die_wip_classes_map(source)[dwarf_dieoffset(die)] = result; + ctxt.die_wip_types_map(source)[dwarf_dieoffset(die)] = result; scope_decl_sptr scop = dynamic_pointer_cast(result); @@ -14326,14 +14257,16 @@ add_or_update_union_type(read_context& ctxt, ctxt.scope_stack().pop(); { - die_class_or_union_map_type::const_iterator i = - ctxt.die_wip_classes_map(source).find(dwarf_dieoffset(die)); - if (i != ctxt.die_wip_classes_map(source).end()) + die_type_map_type::const_iterator i = + ctxt.die_wip_types_map(source).find(dwarf_dieoffset(die)); + if (i != ctxt.die_wip_types_map(source).end()) { - if (is_member_type(i->second)) + const type_base_sptr& type = i->second; + const decl_base* decl = is_decl(type.get()); + if (is_member_type(type) && decl) set_member_access_specifier(result, - get_member_access_specifier(i->second)); - ctxt.die_wip_classes_map(source).erase(i); + get_member_access_specifier(*decl)); + ctxt.die_wip_types_map(source).erase(i); } } @@ -14796,7 +14729,7 @@ build_function_type(read_context& ctxt, : new function_type(ctxt.env(), tu->get_address_size(), /*alignment=*/0)); ctxt.associate_die_to_type(die, result, where_offset); - ctxt.die_wip_function_types_map(source)[dwarf_dieoffset(die)] = result; + ctxt.die_wip_types_map(source)[dwarf_dieoffset(die)] = result; ctxt.associate_die_repr_to_fn_type_per_tu(die, result); type_base_sptr return_type; @@ -14872,13 +14805,7 @@ build_function_type(read_context& ctxt, tu->bind_function_type_life_time(result); - { - die_function_type_map_type::const_iterator i = - ctxt.die_wip_function_types_map(source). - find(dwarf_dieoffset(die)); - if (i != ctxt.die_wip_function_types_map(source).end()) - ctxt.die_wip_function_types_map(source).erase(i); - } + ctxt.die_wip_types_map(source).erase(dwarf_dieoffset(die)); maybe_canonicalize_type(result, ctxt); return result; @@ -16259,7 +16186,7 @@ maybe_canonicalize_type(const Dwarf_Die *die, read_context& ctxt) // maybe_strip_qualification) after they are initially built. ctxt.schedule_type_for_late_canonicalization(die); else if ((is_function_type(t) - && ctxt.is_wip_function_type_die_offset(die_offset, source)) + && ctxt.is_wip_type_die_offset(die_offset, source)) || type_has_non_canonicalized_subtype(t)) ctxt.schedule_type_for_late_canonicalization(die); else