| 207 | }; |
| 208 | |
| 209 | std::optional<size_t> get_segment(const std::vector<SegmentEntry>& segments, ELFIO::Elf_Xword section_size, ELFIO::Elf64_Off section_offset) { |
| 210 | // A linear search is safest even if the segment list is sorted, as there may be overlapping segments |
| 211 | for (size_t i = 0; i < segments.size(); i++) { |
| 212 | const auto& segment = segments[i]; |
| 213 | |
| 214 | // Check that the section's data in the elf file is within bounds of the segment's data |
| 215 | if (section_offset >= segment.data_offset && section_offset + section_size <= segment.data_offset + segment.memory_size) { |
| 216 | return i; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | return std::nullopt; |
| 221 | } |
| 222 | |
| 223 | ELFIO::section* read_sections(N64Recomp::Context& context, ELFIO::section*& mdebug_section_out, const N64Recomp::ElfParsingConfig& elf_config, const ELFIO::elfio& elf_file) { |
| 224 | ELFIO::section* symtab_section = nullptr; |