MCPcopy Create free account
hub / github.com/N64Recomp/N64Recomp / from_elf_file

Method from_elf_file

src/elf.cpp:628–673  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

626}
627
628bool N64Recomp::Context::from_elf_file(const std::filesystem::path& elf_file_path, Context& out, const ElfParsingConfig& elf_config, bool for_dumping_context, DataSymbolMap& data_syms_out, bool& found_entrypoint_out) {
629 ELFIO::elfio elf_file;
630
631 if (!elf_file.load(elf_file_path.string())) {
632 fmt::print("Elf file not found\n");
633 return false;
634 }
635
636 if (elf_file.get_class() != ELFIO::ELFCLASS32) {
637 fmt::print("Incorrect elf class\n");
638 return false;
639 }
640
641 if (elf_file.get_encoding() != ELFIO::ELFDATA2MSB) {
642 fmt::print("Incorrect elf endianness\n");
643 return false;
644 }
645
646 setup_context_for_elf(out, elf_file);
647
648 // Read all of the sections in the elf and look for the symbol table section
649 ELFIO::section* mdebug_section = nullptr;
650 ELFIO::section* symtab_section = read_sections(out, mdebug_section, elf_config, elf_file);
651
652 // If no symbol table was found then exit
653 if (symtab_section == nullptr) {
654 return false;
655 }
656
657 // Read all of the symbols in the elf and look for the entrypoint function
658 found_entrypoint_out = read_symbols(out, elf_file, symtab_section, elf_config, for_dumping_context, data_syms_out);
659
660 // Process an mdebug section for static symbols. The presence of an mdebug section in the input is optional.
661 if (elf_config.use_mdebug) {
662 if (mdebug_section == nullptr) {
663 fmt::print("\"use_mdebug\" set to true in config, but no mdebug section is present in the elf!\n");
664 return false;
665 }
666 if (!N64Recomp::MDebug::parse_mdebug(elf_config, mdebug_section->get_data(), static_cast<uint32_t>(mdebug_section->get_offset()), out, data_syms_out)) {
667 fmt::print("Failed to parse mdebug section\n");
668 return false;
669 }
670 }
671
672 return true;
673}

Callers

nothing calls this directly

Calls 3

setup_context_for_elfFunction · 0.85
read_sectionsFunction · 0.85
read_symbolsFunction · 0.85

Tested by

no test coverage detected