From 5f16261c91fcb4e9d346e4f3005bae97d8a8e2c3 Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Wed, 11 Sep 2024 23:49:48 -0400 Subject: [PATCH] Prevent emitting duplicate reference symbol defines in offline mod recompilation --- OfflineModRecomp/main.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/OfflineModRecomp/main.cpp b/OfflineModRecomp/main.cpp index a566ba4..b686dc5 100644 --- a/OfflineModRecomp/main.cpp +++ b/OfflineModRecomp/main.cpp @@ -147,12 +147,19 @@ int main(int argc, const char** argv) { // Use reloc list to write reference symbol function pointer array and defines (i.e. `#define func_80102468 reference_symbol_funcs[0]`) output_file << "// Array of pointers to functions from the original ROM with defines to alias their names.\n"; + std::unordered_set written_reference_symbols{}; size_t num_reference_symbols = 0; for (const auto& section : mod_context.sections) { for (const auto& reloc : section.relocs) { if (reloc.type == N64Recomp::RelocType::R_MIPS_26 && reloc.reference_symbol && mod_context.is_regular_reference_section(reloc.target_section)) { const auto& sym = mod_context.get_reference_symbol(reloc.target_section, reloc.symbol_index); - output_file << "#define " << sym.name << " reference_symbol_funcs[" << num_reference_symbols << "]\n"; + + // Prevent writing multiple of the same define. This means there are duplicate symbols in the array if a function is called more than once, + // but only the first of each set of duplicates is referenced. This is acceptable, since offline mod recompilation is mainly meant for debug purposes. + if (!written_reference_symbols.contains(sym.name)) { + output_file << "#define " << sym.name << " reference_symbol_funcs[" << num_reference_symbols << "]\n"; + written_reference_symbols.emplace(sym.name); + } num_reference_symbols++; } }