public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] limit repeated DIE comparisons
@ 2022-06-09 11:06 Giuliano Procida
  2022-06-09 11:17 ` [PATCH v2] " Giuliano Procida
  0 siblings, 1 reply; 3+ messages in thread
From: Giuliano Procida @ 2022-06-09 11:06 UTC (permalink / raw)
  To: libabigail; +Cc: dodji, kernel-team, gprocida, maennich

Exponential explosion of DIE comparison has been possible since the
limit of at most 5 pending struct/union DIE comparison pairs was
lifted.

This commit adds two things to control this (with a negligible chance of
falsely finding that two DIEs are equivalent when they are not).

- DIE self-comparisons immediately return true
- once a DIE pair has been compared 10000 times, always return true

	* src/abg-dwarf-reader.cc (read_context): Add mutable
	die_comparison_visits_ member.
	(compare_dies): Return true if this is a self-comparison.
	Return true if we have visited this comparison 10000 times.

Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 src/abg-dwarf-reader.cc | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index 7bf2375d..11436bb0 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -2094,6 +2094,9 @@ public:
   /// A map that associates a function type representations to
   /// function types, inside a translation unit.
   mutable istring_fn_type_map_type per_tu_repr_to_fn_type_maps_;
+  mutable std::unordered_map<std::pair<Dwarf_Off, Dwarf_Off>,
+			     size_t,
+			     dwarf_offset_pair_hash> die_comparison_visits_;
 
   die_class_or_union_map_type	die_wip_classes_map_;
   die_class_or_union_map_type	alternate_die_wip_classes_map_;
@@ -10216,6 +10219,13 @@ compare_dies(const read_context& ctxt,
 
   Dwarf_Off l_offset = dwarf_dieoffset(const_cast<Dwarf_Die*>(l)),
     r_offset = dwarf_dieoffset(const_cast<Dwarf_Die*>(r));
+
+  if (l_offset == r_offset)
+    return true;
+  auto& visit = ctxt.die_comparison_visits_[std::make_pair(l_offset, r_offset)];
+  if (++visit == 10000)
+    return true;
+
   Dwarf_Off l_canonical_die_offset = 0, r_canonical_die_offset = 0;
   const die_source l_die_source = ctxt.get_die_source(l);
   const die_source r_die_source = ctxt.get_die_source(r);
-- 
2.36.1.255.ge46751e96f-goog


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-09 16:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-09 11:06 [PATCH] limit repeated DIE comparisons Giuliano Procida
2022-06-09 11:17 ` [PATCH v2] " Giuliano Procida
2022-06-09 16:14   ` Dodji Seketeli

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).