dump symbols in deterministic order (sorted by addr, name) (#179)
Some checks failed
validate / blaze/ubuntu-22.04 (arm64, Debug) (push) Has been cancelled
validate / blaze/ubuntu-22.04 (arm64, Release) (push) Has been cancelled
validate / macos-14 (arm64, Debug) (push) Has been cancelled
validate / macos-14 (arm64, Release) (push) Has been cancelled
validate / macos-15-intel (x64, Debug) (push) Has been cancelled
validate / macos-15-intel (x64, Release) (push) Has been cancelled
validate / ubuntu-latest (x64, Debug) (push) Has been cancelled
validate / ubuntu-latest (x64, Release) (push) Has been cancelled
validate / windows-latest (x64, Debug) (push) Has been cancelled
validate / windows-latest (x64, Release) (push) Has been cancelled

* add sorting

* also sort absolute symbols

* remove swap file

* use std::sort rather than std::ranges::sort
This commit is contained in:
Garrett Smith 2026-05-26 22:21:25 -07:00 committed by GitHub
parent 70a894aad8
commit ffb39cdad1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,3 +1,4 @@
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <unordered_set>
@ -194,30 +195,41 @@ void dump_context(const N64Recomp::Context& context, const std::unordered_map<ui
// Dump relocs into the function context file.
if (!section.relocs.empty()) {
fmt::print(func_context_file, "relocs = [\n");
std::vector<std::reference_wrapper<const N64Recomp::Reloc>> sorted_relocs;
for (const N64Recomp::Reloc& reloc : section.relocs) {
if (reloc.target_section == section_index || reloc.target_section == section.bss_section_index) {
// TODO allow emitting MIPS32 relocs for specific sections via a toml option for TLB mapping support.
if (reloc.type == N64Recomp::RelocType::R_MIPS_HI16 || reloc.type == N64Recomp::RelocType::R_MIPS_LO16 || reloc.type == N64Recomp::RelocType::R_MIPS_26) {
fmt::print(func_context_file, " {{ type = \"{}\", vram = 0x{:08X}, target_vram = 0x{:08X} }},\n",
reloc_names[static_cast<int>(reloc.type)], reloc.address, reloc.target_section_offset + section.ram_addr);
sorted_relocs.push_back(reloc);
}
}
}
std::sort(sorted_relocs.begin(), sorted_relocs.end(), [](auto& a, auto& b) {
return a.get().address < b.get().address;
});
fmt::print(func_context_file, "relocs = [\n");
for (const N64Recomp::Reloc& reloc : sorted_relocs) {
fmt::print(func_context_file, " {{ type = \"{}\", vram = 0x{:08X}, target_vram = 0x{:08X} }},\n",
reloc_names[static_cast<int>(reloc.type)], reloc.address, reloc.target_section_offset + section.ram_addr);
}
fmt::print(func_context_file, "]\n\n");
}
// Dump functions into the function context file.
fmt::print(func_context_file, "functions = [\n");
std::vector<std::reference_wrapper<const N64Recomp::Function>> sorted_funcs;
for (const size_t& function_index : section_funcs) {
const N64Recomp::Function& func = context.functions[function_index];
sorted_funcs.push_back(context.functions[function_index]);
}
std::sort(sorted_funcs.begin(), sorted_funcs.end(), [](auto& a, auto& b) {
return std::tie(a.get().vram, a.get().name) < std::tie(b.get().vram, b.get().name);
});
fmt::print(func_context_file, "functions = [\n");
for (const N64Recomp::Function& func : sorted_funcs) {
fmt::print(func_context_file, " {{ name = \"{}\", vram = 0x{:08X}, size = 0x{:X} }},\n",
func.name, func.vram, func.words.size() * sizeof(func.words[0]));
}
fmt::print(func_context_file, "]\n\n");
}
@ -226,12 +238,18 @@ void dump_context(const N64Recomp::Context& context, const std::unordered_map<ui
print_section(data_context_file, section.name, section.rom_addr, section.ram_addr, section.size);
// Dump other symbols into the data context file.
fmt::print(data_context_file, "symbols = [\n");
std::vector<std::reference_wrapper<const N64Recomp::DataSymbol>> sorted_symbols;
for (const N64Recomp::DataSymbol& cur_sym : find_syms_it->second) {
sorted_symbols.push_back(cur_sym);
}
std::sort(sorted_symbols.begin(), sorted_symbols.end(), [](auto& a, auto& b) {
return std::tie(a.get().vram, a.get().name) < std::tie(b.get().vram, b.get().name);
});
fmt::print(data_context_file, "symbols = [\n");
for (const N64Recomp::DataSymbol& cur_sym : sorted_symbols) {
fmt::print(data_context_file, " {{ name = \"{}\", vram = 0x{:08X} }},\n", cur_sym.name, cur_sym.vram);
}
fmt::print(data_context_file, "]\n\n");
}
}
@ -240,12 +258,19 @@ void dump_context(const N64Recomp::Context& context, const std::unordered_map<ui
if (find_abs_syms_it != data_syms.end() && !find_abs_syms_it->second.empty()) {
// Dump absolute symbols into the data context file.
print_section(data_context_file, "ABSOLUTE_SYMS", (uint32_t)-1, 0, 0);
fmt::print(data_context_file, "symbols = [\n");
std::vector<std::reference_wrapper<const N64Recomp::DataSymbol>> sorted_symbols;
for (const N64Recomp::DataSymbol& cur_sym : find_abs_syms_it->second) {
sorted_symbols.push_back(cur_sym);
}
std::sort(sorted_symbols.begin(), sorted_symbols.end(), [](auto& a, auto& b) {
return std::tie(a.get().vram, a.get().name) < std::tie(b.get().vram, b.get().name);
});
fmt::print(data_context_file, "symbols = [\n");
for (const N64Recomp::DataSymbol& cur_sym : sorted_symbols) {
fmt::print(data_context_file, " {{ name = \"{}\", vram = 0x{:08X} }},\n", cur_sym.name, cur_sym.vram);
}
fmt::print(data_context_file, "]\n\n");
}
}