Remove some unused code and document which Context fields are actually required for recompilation

This commit is contained in:
Mr-Wiseguy 2024-07-08 22:20:19 -04:00
parent ff5797a2aa
commit 07f2569647
2 changed files with 13 additions and 34 deletions

View file

@ -64,12 +64,13 @@ namespace N64Recomp {
uint32_t rom_addr = 0; uint32_t rom_addr = 0;
uint32_t ram_addr = 0; uint32_t ram_addr = 0;
uint32_t size = 0; uint32_t size = 0;
std::vector<uint32_t> function_addrs; uint32_t bss_size = 0; // not populated when using a symbol toml
std::vector<uint32_t> function_addrs; // only used by the CLI (to find the size of static functions)
std::vector<Reloc> relocs; std::vector<Reloc> relocs;
std::string name; std::string name;
uint16_t bss_section_index = (uint16_t)-1; uint16_t bss_section_index = (uint16_t)-1;
bool executable = false; bool executable = false;
bool relocatable = false; bool relocatable = false; // TODO is this needed? relocs being non-empty should be an equivalent check.
bool has_mips32_relocs = false; bool has_mips32_relocs = false;
}; };
@ -91,14 +92,18 @@ namespace N64Recomp {
std::vector<Section> sections; std::vector<Section> sections;
std::vector<Function> functions; std::vector<Function> functions;
std::unordered_map<uint32_t, std::vector<size_t>> functions_by_vram; std::unordered_map<uint32_t, std::vector<size_t>> functions_by_vram;
// The target ROM being recompiled, TODO move this outside of the context to avoid making a copy for mod contexts.
// Used for reading relocations and for the output binary feature.
std::vector<uint8_t> rom;
//// Only used by the CLI, TODO move these to a struct in the internal headers.
// A mapping of function name to index in the functions vector // A mapping of function name to index in the functions vector
std::unordered_map<std::string, size_t> functions_by_name; std::unordered_map<std::string, size_t> functions_by_name;
std::vector<uint8_t> rom;
// A list of the list of each function (by index in `functions`) in a given section // A list of the list of each function (by index in `functions`) in a given section
std::vector<std::vector<size_t>> section_functions; std::vector<std::vector<size_t>> section_functions;
// The section names that were specified as relocatable // The section names that were specified as relocatable (only used for elf files)
std::unordered_set<std::string> relocatable_sections; std::unordered_set<std::string> relocatable_sections; //
// Functions with manual size overrides // Functions with manual size overrides (only used for elf files)
std::unordered_map<std::string, size_t> manually_sized_funcs; std::unordered_map<std::string, size_t> manually_sized_funcs;
//// Reference symbols (used for populating relocations for patches) //// Reference symbols (used for populating relocations for patches)
@ -110,7 +115,6 @@ namespace N64Recomp {
std::vector<std::string> reference_symbol_names; std::vector<std::string> reference_symbol_names;
// Mapping of symbol name to reference symbol index. // Mapping of symbol name to reference symbol index.
std::unordered_map<std::string, size_t> reference_symbols_by_name; std::unordered_map<std::string, size_t> reference_symbols_by_name;
int executable_section_count;
// Imports sections and function symbols from a provided context into this context's reference sections and reference functions. // Imports sections and function symbols from a provided context into this context's reference sections and reference functions.
void import_reference_context(const Context& reference_context); void import_reference_context(const Context& reference_context);

View file

@ -1059,7 +1059,6 @@ ELFIO::section* read_sections(N64Recomp::Context& context, const N64Recomp::Conf
// Check if this section is marked as executable, which means it has code in it // Check if this section is marked as executable, which means it has code in it
if (section->get_flags() & ELFIO::SHF_EXECINSTR) { if (section->get_flags() & ELFIO::SHF_EXECINSTR) {
section_out.executable = true; section_out.executable = true;
context.executable_section_count++;
} }
section_out.name = section_name; section_out.name = section_name;
} }
@ -1081,6 +1080,7 @@ ELFIO::section* read_sections(N64Recomp::Context& context, const N64Recomp::Conf
auto bss_find = bss_sections_by_name.find(section_out.name); auto bss_find = bss_sections_by_name.find(section_out.name);
if (bss_find != bss_sections_by_name.end()) { if (bss_find != bss_sections_by_name.end()) {
section_out.bss_section_index = bss_find->second->get_index(); section_out.bss_section_index = bss_find->second->get_index();
section_out.bss_size = bss_find->second->get_size();
} }
if (!context.reference_symbols.empty() || section_out.relocatable) { if (!context.reference_symbols.empty() || section_out.relocatable) {
@ -1271,27 +1271,6 @@ for_each_if(Iterator begin, Iterator end, Pred p, Operation op) {
} }
} }
void analyze_sections(N64Recomp::Context& context, const ELFIO::elfio& elf_file) {
std::vector<N64Recomp::Section*> executable_sections{};
executable_sections.reserve(context.executable_section_count);
for_each_if(context.sections.begin(), context.sections.end(),
[](const N64Recomp::Section& section) {
return section.executable && section.rom_addr >= 0x1000;
},
[&](N64Recomp::Section& section) {
executable_sections.push_back(&section);
}
);
std::sort(executable_sections.begin(), executable_sections.end(),
[](const N64Recomp::Section* a, const N64Recomp::Section* b) {
return a->ram_addr < b->ram_addr;
}
);
}
bool read_list_file(const std::filesystem::path& filename, std::vector<std::string>& entries_out) { bool read_list_file(const std::filesystem::path& filename, std::vector<std::string>& entries_out) {
std::ifstream input_file{ filename }; std::ifstream input_file{ filename };
if (!input_file.good()) { if (!input_file.good()) {
@ -1490,7 +1469,6 @@ static void setup_context_for_elf(N64Recomp::Context& context, const ELFIO::elfi
context.functions_by_vram.reserve(context.functions.capacity()); context.functions_by_vram.reserve(context.functions.capacity());
context.functions_by_name.reserve(context.functions.capacity()); context.functions_by_name.reserve(context.functions.capacity());
context.rom.reserve(8 * 1024 * 1024); context.rom.reserve(8 * 1024 * 1024);
context.executable_section_count = 0;
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
@ -1580,9 +1558,6 @@ int main(int argc, char** argv) {
// Read all of the sections in the elf and look for the symbol table section // Read all of the sections in the elf and look for the symbol table section
ELFIO::section* symtab_section = read_sections(context, config, elf_file); ELFIO::section* symtab_section = read_sections(context, config, elf_file);
// Search the sections to see if any are overlays or TLB-mapped
analyze_sections(context, elf_file);
// If no symbol table was found then exit // If no symbol table was found then exit
if (symtab_section == nullptr) { if (symtab_section == nullptr) {
exit_failure("No symbol table section found\n"); exit_failure("No symbol table section found\n");