From 7df3ffe733a50aeea03d6af71ad8743b1b8eb6a8 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Wed, 26 Nov 2025 22:21:42 -0700 Subject: [PATCH] Skip and warn on REL relocations with invalid source Resolves #124 --- src/cmd/dol.rs | 53 +++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/cmd/dol.rs b/src/cmd/dol.rs index 653f1e2..ff65fc2 100644 --- a/src/cmd/dol.rs +++ b/src/cmd/dol.rs @@ -629,17 +629,17 @@ fn update_symbols( .filter(|(_, r)| r.module_id == obj.module_id) { if source_module_id == obj.module_id { - // Skip if already resolved - let (_, source_section) = - obj.sections.get_elf_index(rel_reloc.section as SectionIndex).ok_or_else(|| { - anyhow!( - "Failed to locate REL section {} in module ID {}: source module {}, {:?}", - rel_reloc.section, - obj.module_id, - source_module_id, - rel_reloc - ) - })?; + let Some((_, source_section)) = + obj.sections.get_elf_index(rel_reloc.section as SectionIndex) + else { + log::warn!( + "Missing relocation module {}, section {}; skipping", + obj.module_id, + rel_reloc.section + ); + continue; + }; + if source_section.relocations.contains(rel_reloc.address) { continue; } @@ -710,15 +710,16 @@ fn create_relocations( // Resolve all relocations in this module for rel_reloc in take(&mut obj.unresolved_relocations) { // Skip if already resolved - let (_, source_section) = - obj.sections.get_elf_index(rel_reloc.section as SectionIndex).ok_or_else(|| { - anyhow!( - "Failed to locate REL section {} in module ID {}: {:?}", - rel_reloc.section, - obj.module_id, - rel_reloc - ) - })?; + let Some((_, source_section)) = + obj.sections.get_elf_index(rel_reloc.section as SectionIndex) + else { + log::warn!( + "Missing relocation module {}, section {}; skipping", + obj.module_id, + rel_reloc.section + ); + continue; + }; if source_section.relocations.contains(rel_reloc.address) { continue; } @@ -775,8 +776,16 @@ fn create_relocations( Some(rel_reloc.module_id) }, }; - let (_, source_section) = - obj.sections.get_elf_index_mut(rel_reloc.section as SectionIndex).unwrap(); + let Some((_, source_section)) = + obj.sections.get_elf_index_mut(rel_reloc.section as SectionIndex) + else { + log::warn!( + "Missing relocation module {}, section {}; skipping", + obj.module_id, + rel_reloc.section + ); + continue; + }; source_section.relocations.insert(rel_reloc.address, reloc)?; }