From 7e04b95d71c8e40e7bf10af46707286cbcd17261 Mon Sep 17 00:00:00 2001 From: LittleCube Date: Mon, 23 Dec 2024 23:00:07 -0500 Subject: [PATCH] fix --dump-context arg, fix entrypoint detection --- src/elf.cpp | 20 +++++--------------- src/main.cpp | 15 ++++++++++----- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/elf.cpp b/src/elf.cpp index f37754a..a91f07f 100644 --- a/src/elf.cpp +++ b/src/elf.cpp @@ -59,18 +59,6 @@ bool read_symbols(N64Recomp::Context& context, const ELFIO::elfio& elf_file, ELF } if (section_index < context.sections.size()) { - // Check if this symbol is the entrypoint - if (elf_config.has_entrypoint && (uint32_t) value == (uint32_t) elf_config.entrypoint_address && (type == ELFIO::STT_FUNC || type == ELFIO::STT_NOTYPE)) { - if (found_entrypoint_func) { - fmt::print(stderr, "Ambiguous entrypoint: {}\n", name); - return false; - } - found_entrypoint_func = true; - fmt::print("Found entrypoint, original name: {}\n", name); - size = 0x50; // dummy size for entrypoints, should cover them all - name = "recomp_entrypoint"; - } - // Check if this symbol has a size override auto size_find = elf_config.manually_sized_funcs.find(name); if (size_find != elf_config.manually_sized_funcs.end()) { @@ -105,15 +93,17 @@ bool read_symbols(N64Recomp::Context& context, const ELFIO::elfio& elf_file, ELF auto section_offset = value - elf_file.sections[section_index]->get_address(); const uint32_t* words = reinterpret_cast(elf_file.sections[section_index]->get_data() + section_offset); uint32_t vram = static_cast(value); - uint32_t num_instructions = (type == ELFIO::STT_FUNC || type == ELFIO::STT_NOTYPE) ? size / 4 : 0; + uint32_t num_instructions = type == ELFIO::STT_FUNC ? size / 4 : 0; uint32_t rom_address = static_cast(section_offset + section.rom_addr); section.function_addrs.push_back(vram); context.functions_by_vram[vram].push_back(context.functions.size()); // Find the entrypoint by rom address in case it doesn't have vram as its value - if (elf_config.has_entrypoint && rom_address == 0x1000 && type == ELFIO::STT_FUNC) { - vram = elf_config.entrypoint_address; + if (rom_address == 0x1000 && type == ELFIO::STT_FUNC) { + if (elf_config.has_entrypoint) { + vram = elf_config.entrypoint_address; + } found_entrypoint_func = true; name = "recomp_entrypoint"; if (size == 0) { diff --git a/src/main.cpp b/src/main.cpp index bceba31..608a721 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -272,12 +272,17 @@ int main(int argc, char** argv) { std::exit(EXIT_FAILURE); }; - // TODO expose a way to dump the context from the command line. - bool dumping_context = argc > 2; + bool dumping_context; - if (argc > 3) { - fmt::print("Usage: {} [config file] (should-dump)\n", argv[0]); - std::exit(EXIT_SUCCESS); + if (argc >= 3) { + if (strncmp(argv[2], "--dump-context", 14) == 0) { + dumping_context = true; + } else { + fmt::print("Usage: {} [config file] (should-dump)\n", argv[0]); + std::exit(EXIT_SUCCESS); + } + } else { + dumping_context = false; } const char* config_path = argv[1];