diff --git a/include/n64recomp.h b/include/n64recomp.h index 42f0ffd..e92e415 100644 --- a/include/n64recomp.h +++ b/include/n64recomp.h @@ -64,12 +64,13 @@ namespace N64Recomp { uint32_t rom_addr = 0; uint32_t ram_addr = 0; uint32_t size = 0; - std::vector function_addrs; + uint32_t bss_size = 0; // not populated when using a symbol toml + std::vector function_addrs; // only used by the CLI (to find the size of static functions) std::vector relocs; std::string name; uint16_t bss_section_index = (uint16_t)-1; 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; }; @@ -91,14 +92,18 @@ namespace N64Recomp { std::vector
sections; std::vector functions; std::unordered_map> functions_by_vram; - // A mapping of function name to index in the functions vector - std::unordered_map functions_by_name; + // 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 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 + std::unordered_map functions_by_name; // A list of the list of each function (by index in `functions`) in a given section std::vector> section_functions; - // The section names that were specified as relocatable - std::unordered_set relocatable_sections; - // Functions with manual size overrides + // The section names that were specified as relocatable (only used for elf files) + std::unordered_set relocatable_sections; // + // Functions with manual size overrides (only used for elf files) std::unordered_map manually_sized_funcs; //// Reference symbols (used for populating relocations for patches) @@ -110,7 +115,6 @@ namespace N64Recomp { std::vector reference_symbol_names; // Mapping of symbol name to reference symbol index. std::unordered_map 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. void import_reference_context(const Context& reference_context); diff --git a/src/main.cpp b/src/main.cpp index b74ddc7..f0a2fd9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 if (section->get_flags() & ELFIO::SHF_EXECINSTR) { section_out.executable = true; - context.executable_section_count++; } 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); if (bss_find != bss_sections_by_name.end()) { 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) { @@ -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 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(§ion); - } - ); - - 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& entries_out) { std::ifstream input_file{ filename }; 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_name.reserve(context.functions.capacity()); context.rom.reserve(8 * 1024 * 1024); - context.executable_section_count = 0; } 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 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 (symtab_section == nullptr) { exit_failure("No symbol table section found\n");