From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <3uGEHYwgKCrcdmolZfaXdlldib.ZljifYXYfdXfiplroZbtXob.lod@flex--gprocida.bounces.google.com> Received: from mail-ej1-x64a.google.com (mail-ej1-x64a.google.com [IPv6:2a00:1450:4864:20::64a]) by sourceware.org (Postfix) with ESMTPS id 53B153852742 for ; Thu, 25 Aug 2022 11:49:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 53B153852742 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=flex--gprocida.bounces.google.com Received: by mail-ej1-x64a.google.com with SMTP id mp41-20020a1709071b2900b0073d84b11981so4004100ejc.23 for ; Thu, 25 Aug 2022 04:49:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=gifOBxPiTz6wTBuxf3A2FytLOjr1o2CPp6ahHDbZNlY=; b=a3fX3U/nL96IJlAXRC/D2+yaNlcJOXGeAwb6NGpcvkdX5VKP13+fNfe9VDsMXMOAYr /27GqfXRBE+BVnl+P6IZ9OPWD06STWZueN1EnuM3P+DnnQYW70VNLR0pZ0VG+UG+9zmz 0hdiQxH7xjWPK/PvJ2m+JbC6dihzE3yoJ5GQYjwvkshws2oObbjfYxricm0aGABDHV3G QRTbYDDMK1gSnVMPvzs3BzDAqRrry3njhs+3Jl4rDF3nKZwWWRdfobixo6QG6inFDy9n 68VMdkrCb7Eo9E5GkhGlOf1rZseRZ8u6NlbVHgGNM/bzYrb5ULGqfKmpnrq11JWuycZ0 R0Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=gifOBxPiTz6wTBuxf3A2FytLOjr1o2CPp6ahHDbZNlY=; b=dAHB77bZ43mqSkbny4fIpt2WNsL5uwKGL39ItvK4/SbLiLaTP8gZOw4qRiXf3TEmt5 WAnLRFsjuROMeUGZDqMWM5p/7owjFBYQLRyTSQiG+R75A8mVkNnxOjhhY2CgDgBRBlFM czzbzje9i6LJin2F1gHeNAHqkzcCzUPUPgt9KQzRhIe+h147xspWZuY/yEmrS3dPso4G FH7RCca0CHhZ3qMJKBkMq7Wxs89iNbgRcAx3wX9UJM8OSgR9IgTzHB/0GhIcTP4X1n8i altaZ2FoNmQ7TxH4e9l/OQryerLeSVJhoM8QTDBIAW08JnSM2Um+hXp15LCm6If/Qxjc /3QQ== X-Gm-Message-State: ACgBeo3x03iNO77so61PQCPtj8c4L+CDDhWw+1eFOfsfmQ9GGZ+FYeNX V7BLiz5J4lJ4etidDP4pxFp7inZ1jD6+jRoD9HfSKcZ7gvBvM1eUdLQSLnH3E2hCa6bVRFXi/Ev lr8qD83WOb3yLzLV98V/kBdnOWJzpwEqVFxHsaA2FamJDElK/h2kCNLWcPQSOn/nQ9dsVPTE= X-Google-Smtp-Source: AA6agR5wFp8xNIvnUizivKcwm3NTnxOX4uhXpKQF87HawjKm2iUviO24uAdZ1Yn1Uyc2DrX/tNNPxfgp+eJGoQ== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:209:e2f1:457f:d595:4f88]) (user=gprocida job=sendgmr) by 2002:a05:6402:1041:b0:446:b290:ea94 with SMTP id e1-20020a056402104100b00446b290ea94mr2819144edu.389.1661428152153; Thu, 25 Aug 2022 04:49:12 -0700 (PDT) Date: Thu, 25 Aug 2022 12:48:56 +0100 In-Reply-To: <20220825114856.3137373-1-gprocida@google.com> Message-Id: <20220825114856.3137373-4-gprocida@google.com> Mime-Version: 1.0 References: <20220825114856.3137373-1-gprocida@google.com> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog Subject: [PATCH 3/3] abidw: resolve declaration-only enums the same as classes From: Giuliano Procida To: libabigail@sourceware.org Cc: dodji@seketeli.org, kernel-team@android.com, gprocida@google.com, maennich@google.com, sidnayyar@google.com, vvvvvv@google.com Content-Type: text/plain; charset="UTF-8" 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,T_SCC_BODY_TEXT_LINE,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 List-Id: The logic for resolving declaration-only enums and classes was almost the same. However, the class code had a couple of extra improvements that were missing from the enum code. One of these caused resolution failures with Linux kernel ABIs, resulting in duplicate (declared / defined) enums in ABI XML. This change adds the improvements to the enum resolution code. * src/abg-dwarf-reader.cc (read_context::resolve_declaration_only_enums): Use an ordered map to ensure TUs are always considered in the same order and so improve ABI XML stability. Given multiple possible definitions for a enum declaration, check to see if they are equal and resolve the declaration to the first definition if so. Signed-off-by: Giuliano Procida --- src/abg-dwarf-reader.cc | 42 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index b5e60e35..df50ef7d 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -4460,7 +4460,13 @@ public: if (!enums) continue; - unordered_map per_tu_enum_map; + // This is a map that associates the translation unit path to + // the enum (that potentially defines the declarations that + // we consider) that are defined in that translation unit. It + // should stay ordered by using the TU path as key to ensure + // stability of the order of enum definitions in ABIXML + // output. + map per_tu_enum_map; for (type_base_wptrs_type::const_iterator c = enums->begin(); c != enums->end(); ++c) @@ -4497,13 +4503,45 @@ public: { string tu_path = (*j)->get_translation_unit()->get_absolute_path(); - unordered_map::const_iterator e = + map::const_iterator e = per_tu_enum_map.find(tu_path); if (e != per_tu_enum_map.end()) (*j)->set_definition_of_declaration(e->second); else if (per_tu_enum_map.size() == 1) (*j)->set_definition_of_declaration (per_tu_enum_map.begin()->second); + else + { + // We are in case where there are more than + // one definition for the declaration. Let's + // see if they are all equal. If they are, + // then the declaration resolves to the + // definition. Otherwise, we are in the case + // 3/ described above. + map::const_iterator it; + enum_type_decl_sptr first_enum = + per_tu_enum_map.begin()->second; + bool all_enum_definitions_are_equal = true; + for (it = per_tu_enum_map.begin(); + it != per_tu_enum_map.end(); + ++it) + { + if (it == per_tu_enum_map.begin()) + continue; + else + { + if (!compare_before_canonicalisation(it->second, + first_enum)) + { + all_enum_definitions_are_equal = false; + break; + } + } + } + if (all_enum_definitions_are_equal) + (*j)->set_definition_of_declaration(first_enum); + } } } resolved_enums.push_back(i->first); -- 2.37.1.595.g718a3a8f04-goog