From 9aeeb6fcd2a8a1519480ae84047786971b82c31f Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Wed, 1 May 2024 00:00:00 +0000 Subject: [PATCH] read: support section targets in RelocationMap (#675) These are commonly used for DWARF sections in Mach-O. --- src/read/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/read/mod.rs b/src/read/mod.rs index 128b9fe4..31077fe1 100644 --- a/src/read/mod.rs +++ b/src/read/mod.rs @@ -781,6 +781,16 @@ impl RelocationMap { .read_error("Relocation with invalid symbol")?; entry.addend = symbol.address().wrapping_add(entry.addend); } + RelocationTarget::Section(section_idx) => { + let section = file + .section_by_index(section_idx) + .read_error("Relocation with invalid section")?; + // DWARF parsers expect references to DWARF sections to be section offsets, + // not addresses. Addresses are useful for everything else. + if section.kind() != SectionKind::Debug { + entry.addend = section.address().wrapping_add(entry.addend); + } + } _ => { return Err(Error("Unsupported relocation target")); }