From 91205be0316e8f98c083c74bc3bfb0d0eae95a51 Mon Sep 17 00:00:00 2001 From: MS Date: Thu, 17 Oct 2024 23:17:00 -0400 Subject: [PATCH] Handle duplicate thunks in BETA10 (#1113) --- tools/isledecomp/isledecomp/compare/core.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tools/isledecomp/isledecomp/compare/core.py b/tools/isledecomp/isledecomp/compare/core.py index f2aebdcf..66e923d3 100644 --- a/tools/isledecomp/isledecomp/compare/core.py +++ b/tools/isledecomp/isledecomp/compare/core.py @@ -428,11 +428,6 @@ def _match_thunks(self): points at a function we have already matched, we can find the matching thunk in recomp because it points to the same place.""" - # Turn this one inside out for easy lookup - recomp_thunks = { - func_addr: thunk_addr for (thunk_addr, func_addr) in self.recomp_bin.thunks - } - # Mark all recomp thunks first. This allows us to use their name # when we sanitize the asm. for recomp_thunk, recomp_addr in self.recomp_bin.thunks: @@ -442,17 +437,29 @@ def _match_thunks(self): self._db.create_recomp_thunk(recomp_thunk, recomp_func.name) + # Thunks may be non-unique, so use a list as dict value when + # inverting the list of tuples from self.recomp_bin. + recomp_thunks = {} + for thunk_addr, func_addr in self.recomp_bin.thunks: + recomp_thunks.setdefault(func_addr, []).append(thunk_addr) + + # Now match the thunks from orig where we can. for orig_thunk, orig_addr in self.orig_bin.thunks: orig_func = self._db.get_by_orig(orig_addr) if orig_func is None: continue # Check whether the thunk destination is a matched symbol - recomp_thunk = recomp_thunks.get(orig_func.recomp_addr) - if recomp_thunk is None: + if orig_func.recomp_addr not in recomp_thunks: self._db.create_orig_thunk(orig_thunk, orig_func.name) continue + # If there are multiple thunks, they are already in v.addr order. + # Pop the earliest one and match it. + recomp_thunk = recomp_thunks[orig_func.recomp_addr].pop(0) + if len(recomp_thunks[orig_func.recomp_addr]) == 0: + del recomp_thunks[orig_func.recomp_addr] + self._db.set_function_pair(orig_thunk, recomp_thunk) # Don't compare thunk functions for now. The comparison isn't