public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: Giuliano Procida <gprocida@google.com>
To: libabigail@sourceware.org
Cc: dodji@seketeli.org, kernel-team@android.com, gprocida@google.com,
	 maennich@google.com, sidnayyar@google.com, vvvvvv@google.com
Subject: [PATCH 3/3] abidw: resolve declaration-only enums the same as classes
Date: Thu, 25 Aug 2022 12:48:56 +0100	[thread overview]
Message-ID: <20220825114856.3137373-4-gprocida@google.com> (raw)
In-Reply-To: <20220825114856.3137373-1-gprocida@google.com>

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 <gprocida@google.com>
---
 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<string, enum_type_decl_sptr> 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<string, enum_type_decl_sptr> 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<string, enum_type_decl_sptr>::const_iterator e =
+		    map<string, enum_type_decl_sptr>::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<string,
+			    enum_type_decl_sptr>::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


  parent reply	other threads:[~2022-08-25 11:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-25 11:48 [PATCH 0/3] Improve resolution of declaration-only enums Giuliano Procida
2022-08-25 11:48 ` [PATCH 1/3] abidw: fix --stats output for resolved classes and enums Giuliano Procida
2022-08-29 11:19   ` Dodji Seketeli
2022-08-25 11:48 ` [PATCH 2/3] abidw: remove always true test in resolve_declaration_only_classes Giuliano Procida
2022-08-29 11:19   ` Dodji Seketeli
2022-08-25 11:48 ` Giuliano Procida [this message]
2022-08-29 11:20   ` [PATCH 3/3] abidw: resolve declaration-only enums the same as classes Dodji Seketeli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220825114856.3137373-4-gprocida@google.com \
    --to=gprocida@google.com \
    --cc=dodji@seketeli.org \
    --cc=kernel-team@android.com \
    --cc=libabigail@sourceware.org \
    --cc=maennich@google.com \
    --cc=sidnayyar@google.com \
    --cc=vvvvvv@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).