Repository: gimli-rs/object
Pull request #674 (2024-04-29 10:06:22)

readobj/macho: fix section index


Patch:
diff --git a/crates/examples/src/readobj/macho.rs b/crates/examples/src/readobj/macho.rs
index e2cd7c3..456b77e 100644
--- a/crates/examples/src/readobj/macho.rs
+++ b/crates/examples/src/readobj/macho.rs
@@ -609,8 +609,8 @@ fn print_segment<S: Segment>(
         }
         if let Some(sections) = segment.sections(endian, section_data).print_err(p) {
             for section in sections {
-                print_section(p, endian, data, section, state);
                 state.section_index += 1;
+                print_section(p, endian, data, section, state);
             }
         }
     });
diff --git a/src/read/macho/file.rs b/src/read/macho/file.rs
index c845c55..765c090 100644
--- a/src/read/macho/file.rs
+++ b/src/read/macho/file.rs
@@ -44,7 +44,7 @@ where
     pub(super) header_offset: u64,
     pub(super) header: &'data Mach,
     pub(super) segments: Vec<MachOSegmentInternal<'data, Mach, R>>,
-    pub(super) sections: Vec<MachOSectionInternal<'data, Mach>>,
+    pub(super) sections: Vec<MachOSectionInternal<'data, Mach, R>>,
     pub(super) symbols: SymbolTable<'data, Mach, R>,
 }
 
@@ -65,11 +65,10 @@ where
         if let Ok(mut commands) = header.load_commands(endian, data, 0) {
             while let Ok(Some(command)) = commands.next() {
                 if let Some((segment, section_data)) = Mach::Segment::from_command(command)? {
-                    let segment_index = segments.len();
                     segments.push(MachOSegmentInternal { segment, data });
                     for section in segment.sections(endian, section_data)? {
                         let index = SectionIndex(sections.len() + 1);
-                        sections.push(MachOSectionInternal::parse(index, segment_index, section));
+                        sections.push(MachOSectionInternal::parse(index, section, data));
                     }
                 } else if let Some(symtab) = command.symtab()? {
                     symbols = symtab.symbols(endian, data)?;
@@ -110,6 +109,7 @@ where
                 if let Some((segment, section_data)) = Mach::Segment::from_command(command)? {
                     // Each segment can be stored in a different subcache. Get the segment's
                     // address and look it up in the cache mappings, to find the correct cache data.
+                    // This was observed for the arm64e __LINKEDIT segment in macOS 12.0.1.
                     let addr = segment.vmaddr(endian).into();
                     let (data, _offset) = image
                         .cache
@@ -118,12 +118,11 @@ where
                     if segment.name() == macho::SEG_LINKEDIT.as_bytes() {
                         linkedit_data = Some(data);
                     }
-                    let segment_index = segments.len();
                     segments.push(MachOSegmentInternal { segment, data });
 
                     for section in segment.sections(endian, section_data)? {
                         let index = SectionIndex(sections.len() + 1);
-                        sections.push(MachOSectionInternal::parse(index, segment_index, section));
+                        sections.push(MachOSectionInternal::parse(index, section, data));
                     }
                 } else if let Some(st) = command.symtab()? {
                     symtab = Some(st);
@@ -154,7 +153,7 @@ where
     pub(super) fn section_internal(
         &self,
         index: SectionIndex,
-    ) -> Result<&MachOSectionInternal<'data, Mach>> {
+    ) -> Result<&MachOSectionInternal<'data, Mach, R>> {
         index
             .0
             .checked_sub(1)
@@ -162,15 +161,6 @@ where
             .read_error("Invalid Mach-O section index")
     }
 
-    pub(super) fn segment_internal(
-        &self,
-        index: usize,
-    ) -> Result<&MachOSegmentInternal<'data, Mach, R>> {
-        self.segments
-            .get(index)
-            .read_error("Invalid Mach-O segment index")
-    }
-
     /// Returns the endianness.
     pub fn endian(&self) -> Mach::Endian {
         self.endian
diff --git a/src/read/macho/section.rs b/src/read/macho/section.rs
index 16c199c..4492c85 100644
--- a/src/read/macho/section.rs
+++ b/src/read/macho/section.rs
@@ -25,7 +25,7 @@ where
     R: ReadRef<'data>,
 {
     pub(super) file: &'file MachOFile<'data, Mach, R>,
-    pub(super) iter: slice::Iter<'file, MachOSectionInternal<'data, Mach>>,
+    pub(super) iter: slice::Iter<'file, MachOSectionInternal<'data, Mach, R>>,
 }
 
 impl<'data, 'file, Mach, R> fmt::Debug for MachOSectionIterator<'data, 'file, Mach, R>
@@ -71,7 +71,7 @@ where
     R: ReadRef<'data>,
 {
     pub(super) file: &'file MachOFile<'data, Mach, R>,
-    pub(super) internal: MachOSectionInternal<'data, Mach>,
+    pub(super) internal: MachOSectionInternal<'data, Mach, R>,
 }
 
 impl<'data, 'file, Mach, R> MachOSection<'data, 'file, Mach, R>
@@ -80,11 +80,9 @@ where
     R: ReadRef<'data>,
 {
     fn bytes(&self) -> Result<&'data [u8]> {
-        let segment_index = self.internal.segment_index;
-        let segment = self.file.segment_internal(segment_index)?;
         self.internal
             .section
-            .data(self.file.endian, segment.data)
+            .data(self.file.endian, self.internal.data)
             .read_error("Invalid Mach-O section size or offset")
     }
 }
@@ -193,7 +191,7 @@ where
             relocations: self
                 .internal
                 .section
-                .relocations(self.file.endian, self.file.data)
+                .relocations(self.file.endian, self.internal.data)
                 .unwrap_or(&[])
                 .iter(),
         }
@@ -211,19 +209,19 @@ where
 }
 
 #[derive(Debug, Clone, Copy)]
-pub(super) struct MachOSectionInternal<'data, Mach: MachHeader> {
+pub(super) struct MachOSectionInternal<'data, Mach: MachHeader, R: ReadRef<'data>> {
     pub index: SectionIndex,
-    pub segment_index: usize,
     pub kind: SectionKind,
     pub section: &'data Mach::Section,
+    /// The data for the file that contains the section data.
+    ///
+    /// This is required for dyld caches, where this may be a different subcache
+    /// from the file containing the Mach-O load commands.
+    pub data: R,
 }
 
-impl<'data, Mach: MachHeader> MachOSectionInternal<'data, Mach> {
-    pub(super) fn parse(
-        index: SectionIndex,
-        segment_index: usize,
-        section: &'data Mach::Section,
-    ) -> Self {
+impl<'data, Mach: MachHeader, R: ReadRef<'data>> MachOSectionInternal<'data, Mach, R> {
+    pub(super) fn parse(index: SectionIndex, section: &'data Mach::Section, data: R) -> Self {
         // TODO: we don't validate flags, should we?
         let kind = match (section.segment_name(), section.name()) {
             (b"__TEXT", b"__text") => SectionKind::Text,
@@ -246,9 +244,9 @@ impl<'data, Mach: MachHeader> MachOSectionInternal<'data, Mach> {
         };
         MachOSectionInternal {
             index,
-            segment_index,
             kind,
             section,
+            data,
         }
     }
 }
diff --git a/src/read/macho/segment.rs b/src/read/macho/segment.rs
index c889ad2..b78a5dd 100644
--- a/src/read/macho/segment.rs
+++ b/src/read/macho/segment.rs
@@ -69,7 +69,7 @@ where
     fn bytes(&self) -> Result<&'data [u8]> {
         self.internal
             .segment
-            .data(self.file.endian, self.file.data)
+            .data(self.file.endian, self.internal.data)
             .read_error("Invalid Mach-O segment size or offset")
     }
 }
@@ -149,8 +149,12 @@ where
 
 #[derive(Debug, Clone, Copy)]
 pub(super) struct MachOSegmentInternal<'data, Mach: MachHeader, R: ReadRef<'data>> {
-    pub data: R,
     pub segment: &'data Mach::Segment,
+    /// The data for the file that contains the segment data.
+    ///
+    /// This is required for dyld caches, where this may be a different subcache
+    /// from the file containing the Mach-O load commands.
+    pub data: R,
 }
 
 /// A trait for generic access to [`macho::SegmentCommand32`] and [`macho::SegmentCommand64`].


Test patch:
diff --git a/crates/examples/testfiles/macho/base-aarch64-debug.o.readobj b/crates/examples/testfiles/macho/base-aarch64-debug.o.readobj
index 8ab0bd8..6c37941 100644
--- a/crates/examples/testfiles/macho/base-aarch64-debug.o.readobj
+++ b/crates/examples/testfiles/macho/base-aarch64-debug.o.readobj
@@ -28,7 +28,7 @@ SegmentCommand {
     NumberOfSections: 11
     Flags: 0x0
     Section {
-        Index: 0
+        Index: 1
         SectionName: "__text"
         SegmentName: "__TEXT"
         Address: 0x0
@@ -67,7 +67,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 1
+        Index: 2
         SectionName: "__cstring"
         SegmentName: "__TEXT"
         Address: 0x34
@@ -79,7 +79,7 @@ SegmentCommand {
         Flags: S_CSTRING_LITERALS (0x2)
     }
     Section {
-        Index: 2
+        Index: 3
         SectionName: "__debug_abbrev"
         SegmentName: "__DWARF"
         Address: 0x41
@@ -93,7 +93,7 @@ SegmentCommand {
             S_ATTR_DEBUG (0x2000000)
     }
     Section {
-        Index: 3
+        Index: 4
         SectionName: "__debug_info"
         SegmentName: "__DWARF"
         Address: 0x7B
@@ -123,7 +123,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 4
+        Index: 5
         SectionName: "__debug_str"
         SegmentName: "__DWARF"
         Address: 0xCE
@@ -137,7 +137,7 @@ SegmentCommand {
             S_ATTR_DEBUG (0x2000000)
     }
     Section {
-        Index: 5
+        Index: 6
         SectionName: "__apple_names"
         SegmentName: "__DWARF"
         Address: 0x199
@@ -151,7 +151,7 @@ SegmentCommand {
             S_ATTR_DEBUG (0x2000000)
     }
     Section {
-        Index: 6
+        Index: 7
         SectionName: "__apple_objc"
         SegmentName: "__DWARF"
         Address: 0x1D5
@@ -165,7 +165,7 @@ SegmentCommand {
             S_ATTR_DEBUG (0x2000000)
     }
     Section {
-        Index: 7
+        Index: 8
         SectionName: "__apple_namespac"
         SegmentName: "__DWARF"
         Address: 0x1F9
@@ -179,7 +179,7 @@ SegmentCommand {
             S_ATTR_DEBUG (0x2000000)
     }
     Section {
-        Index: 8
+        Index: 9
         SectionName: "__apple_types"
         SegmentName: "__DWARF"
         Address: 0x21D
@@ -193,7 +193,7 @@ SegmentCommand {
             S_ATTR_DEBUG (0x2000000)
     }
     Section {
-        Index: 9
+        Index: 10
         SectionName: "__compact_unwind"
         SegmentName: "__LD"
         Address: 0x268
@@ -215,7 +215,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 10
+        Index: 11
         SectionName: "__debug_line"
         SegmentName: "__DWARF"
         Address: 0x288
diff --git a/crates/examples/testfiles/macho/base-aarch64.o.objcopy b/crates/examples/testfiles/macho/base-aarch64.o.objcopy
index 3acaee4..ad82dbf 100644
--- a/crates/examples/testfiles/macho/base-aarch64.o.objcopy
+++ b/crates/examples/testfiles/macho/base-aarch64.o.objcopy
@@ -28,7 +28,7 @@ SegmentCommand {
     NumberOfSections: 3
     Flags: 0x0
     Section {
-        Index: 0
+        Index: 1
         SectionName: "__text"
         SegmentName: "__TEXT"
         Address: 0x0
@@ -67,7 +67,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 1
+        Index: 2
         SectionName: "__cstring"
         SegmentName: "__TEXT"
         Address: 0x34
@@ -79,7 +79,7 @@ SegmentCommand {
         Flags: S_CSTRING_LITERALS (0x2)
     }
     Section {
-        Index: 2
+        Index: 3
         SectionName: "__compact_unwind"
         SegmentName: "__LD"
         Address: 0x48
diff --git a/crates/examples/testfiles/macho/base-aarch64.o.readobj b/crates/examples/testfiles/macho/base-aarch64.o.readobj
index 3acaee4..ad82dbf 100644
--- a/crates/examples/testfiles/macho/base-aarch64.o.readobj
+++ b/crates/examples/testfiles/macho/base-aarch64.o.readobj
@@ -28,7 +28,7 @@ SegmentCommand {
     NumberOfSections: 3
     Flags: 0x0
     Section {
-        Index: 0
+        Index: 1
         SectionName: "__text"
         SegmentName: "__TEXT"
         Address: 0x0
@@ -67,7 +67,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 1
+        Index: 2
         SectionName: "__cstring"
         SegmentName: "__TEXT"
         Address: 0x34
@@ -79,7 +79,7 @@ SegmentCommand {
         Flags: S_CSTRING_LITERALS (0x2)
     }
     Section {
-        Index: 2
+        Index: 3
         SectionName: "__compact_unwind"
         SegmentName: "__LD"
         Address: 0x48
diff --git a/crates/examples/testfiles/macho/base-aarch64.readobj b/crates/examples/testfiles/macho/base-aarch64.readobj
index 770c82c..d26931d 100644
--- a/crates/examples/testfiles/macho/base-aarch64.readobj
+++ b/crates/examples/testfiles/macho/base-aarch64.readobj
@@ -39,7 +39,7 @@ SegmentCommand {
     NumberOfSections: 4
     Flags: 0x0
     Section {
-        Index: 0
+        Index: 1
         SectionName: "__text"
         SegmentName: "__TEXT"
         Address: 0x100003F68
@@ -54,7 +54,7 @@ SegmentCommand {
             S_ATTR_SOME_INSTRUCTIONS (0x400)
     }
     Section {
-        Index: 1
+        Index: 2
         SectionName: "__stubs"
         SegmentName: "__TEXT"
         Address: 0x100003F9C
@@ -69,7 +69,7 @@ SegmentCommand {
             S_ATTR_SOME_INSTRUCTIONS (0x400)
     }
     Section {
-        Index: 2
+        Index: 3
         SectionName: "__cstring"
         SegmentName: "__TEXT"
         Address: 0x100003FA8
@@ -81,7 +81,7 @@ SegmentCommand {
         Flags: S_CSTRING_LITERALS (0x2)
     }
     Section {
-        Index: 3
+        Index: 4
         SectionName: "__unwind_info"
         SegmentName: "__TEXT"
         Address: 0x100003FB8
@@ -111,7 +111,7 @@ SegmentCommand {
     Flags: 0x10
         SG_READ_ONLY (0x10)
     Section {
-        Index: 4
+        Index: 5
         SectionName: "__got"
         SegmentName: "__DATA_CONST"
         Address: 0x100004000
diff --git a/crates/examples/testfiles/macho/base-x86_64-debug.o.readobj b/crates/examples/testfiles/macho/base-x86_64-debug.o.readobj
index 2b6fd72..ecae9f1 100644
--- a/crates/examples/testfiles/macho/base-x86_64-debug.o.readobj
+++ b/crates/examples/testfiles/macho/base-x86_64-debug.o.readobj
@@ -28,7 +28,7 @@ SegmentCommand {
     NumberOfSections: 12
     Flags: 0x0
     Section {
-        Index: 0
+        Index: 1
         SectionName: "__text"
         SegmentName: "__TEXT"
         Address: 0x0
@@ -59,7 +59,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 1
+        Index: 2
         SectionName: "__cstring"
         SegmentName: "__TEXT"
         Address: 0x25
@@ -71,7 +71,7 @@ SegmentCommand {
         Flags: S_CSTRING_LITERALS (0x2)
     }
     Section {
-        Index: 2
+        Index: 3
         SectionName: "__debug_abbrev"
         SegmentName: "__DWARF"
         Address: 0x32
@@ -85,7 +85,7 @@ SegmentCommand {
             S_ATTR_DEBUG (0x2000000)
     }
     Section {
-        Index: 3
+        Index: 4
         SectionName: "__debug_info"
         SegmentName: "__DWARF"
         Address: 0x6C
@@ -115,7 +115,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 4
+        Index: 5
         SectionName: "__debug_str"
         SegmentName: "__DWARF"
         Address: 0xBF
@@ -129,7 +129,7 @@ SegmentCommand {
             S_ATTR_DEBUG (0x2000000)
     }
     Section {
-        Index: 5
+        Index: 6
         SectionName: "__apple_names"
         SegmentName: "__DWARF"
         Address: 0x187
@@ -143,7 +143,7 @@ SegmentCommand {
             S_ATTR_DEBUG (0x2000000)
     }
     Section {
-        Index: 6
+        Index: 7
         SectionName: "__apple_objc"
         SegmentName: "__DWARF"
         Address: 0x1C3
@@ -157,7 +157,7 @@ SegmentCommand {
             S_ATTR_DEBUG (0x2000000)
     }
     Section {
-        Index: 7
+        Index: 8
         SectionName: "__apple_namespac"
         SegmentName: "__DWARF"
         Address: 0x1E7
@@ -171,7 +171,7 @@ SegmentCommand {
             S_ATTR_DEBUG (0x2000000)
     }
     Section {
-        Index: 8
+        Index: 9
         SectionName: "__apple_types"
         SegmentName: "__DWARF"
         Address: 0x20B
@@ -185,7 +185,7 @@ SegmentCommand {
             S_ATTR_DEBUG (0x2000000)
     }
     Section {
-        Index: 9
+        Index: 10
         SectionName: "__compact_unwind"
         SegmentName: "__LD"
         Address: 0x258
@@ -207,7 +207,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 10
+        Index: 11
         SectionName: "__eh_frame"
         SegmentName: "__TEXT"
         Address: 0x278
@@ -223,7 +223,7 @@ SegmentCommand {
             S_ATTR_LIVE_SUPPORT (0x8000000)
     }
     Section {
-        Index: 11
+        Index: 12
         SectionName: "__debug_line"
         SegmentName: "__DWARF"
         Address: 0x2B8
diff --git a/crates/examples/testfiles/macho/base-x86_64.o.objcopy b/crates/examples/testfiles/macho/base-x86_64.o.objcopy
index 4b66798..71c78cf 100644
--- a/crates/examples/testfiles/macho/base-x86_64.o.objcopy
+++ b/crates/examples/testfiles/macho/base-x86_64.o.objcopy
@@ -28,7 +28,7 @@ SegmentCommand {
     NumberOfSections: 4
     Flags: 0x0
     Section {
-        Index: 0
+        Index: 1
         SectionName: "__text"
         SegmentName: "__TEXT"
         Address: 0x0
@@ -59,7 +59,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 1
+        Index: 2
         SectionName: "__cstring"
         SegmentName: "__TEXT"
         Address: 0x25
@@ -71,7 +71,7 @@ SegmentCommand {
         Flags: S_CSTRING_LITERALS (0x2)
     }
     Section {
-        Index: 2
+        Index: 3
         SectionName: "__compact_unwind"
         SegmentName: "__LD"
         Address: 0x38
@@ -93,7 +93,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 3
+        Index: 4
         SectionName: "__eh_frame"
         SegmentName: "__TEXT"
         Address: 0x58
diff --git a/crates/examples/testfiles/macho/base-x86_64.o.readobj b/crates/examples/testfiles/macho/base-x86_64.o.readobj
index 4b66798..71c78cf 100644
--- a/crates/examples/testfiles/macho/base-x86_64.o.readobj
+++ b/crates/examples/testfiles/macho/base-x86_64.o.readobj
@@ -28,7 +28,7 @@ SegmentCommand {
     NumberOfSections: 4
     Flags: 0x0
     Section {
-        Index: 0
+        Index: 1
         SectionName: "__text"
         SegmentName: "__TEXT"
         Address: 0x0
@@ -59,7 +59,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 1
+        Index: 2
         SectionName: "__cstring"
         SegmentName: "__TEXT"
         Address: 0x25
@@ -71,7 +71,7 @@ SegmentCommand {
         Flags: S_CSTRING_LITERALS (0x2)
     }
     Section {
-        Index: 2
+        Index: 3
         SectionName: "__compact_unwind"
         SegmentName: "__LD"
         Address: 0x38
@@ -93,7 +93,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 3
+        Index: 4
         SectionName: "__eh_frame"
         SegmentName: "__TEXT"
         Address: 0x58
diff --git a/crates/examples/testfiles/macho/base-x86_64.readobj b/crates/examples/testfiles/macho/base-x86_64.readobj
index b097dd8..eb06e47 100644
--- a/crates/examples/testfiles/macho/base-x86_64.readobj
+++ b/crates/examples/testfiles/macho/base-x86_64.readobj
@@ -39,7 +39,7 @@ SegmentCommand {
     NumberOfSections: 5
     Flags: 0x0
     Section {
-        Index: 0
+        Index: 1
         SectionName: "__text"
         SegmentName: "__TEXT"
         Address: 0x100003F60
@@ -54,7 +54,7 @@ SegmentCommand {
             S_ATTR_SOME_INSTRUCTIONS (0x400)
     }
     Section {
-        Index: 1
+        Index: 2
         SectionName: "__stubs"
         SegmentName: "__TEXT"
         Address: 0x100003F86
@@ -69,7 +69,7 @@ SegmentCommand {
             S_ATTR_SOME_INSTRUCTIONS (0x400)
     }
     Section {
-        Index: 2
+        Index: 3
         SectionName: "__stub_helper"
         SegmentName: "__TEXT"
         Address: 0x100003F8C
@@ -84,7 +84,7 @@ SegmentCommand {
             S_ATTR_SOME_INSTRUCTIONS (0x400)
     }
     Section {
-        Index: 3
+        Index: 4
         SectionName: "__cstring"
         SegmentName: "__TEXT"
         Address: 0x100003FA6
@@ -96,7 +96,7 @@ SegmentCommand {
         Flags: S_CSTRING_LITERALS (0x2)
     }
     Section {
-        Index: 4
+        Index: 5
         SectionName: "__unwind_info"
         SegmentName: "__TEXT"
         Address: 0x100003FB4
@@ -126,7 +126,7 @@ SegmentCommand {
     Flags: 0x10
         SG_READ_ONLY (0x10)
     Section {
-        Index: 5
+        Index: 6
         SectionName: "__got"
         SegmentName: "__DATA_CONST"
         Address: 0x100004000
@@ -155,7 +155,7 @@ SegmentCommand {
     NumberOfSections: 2
     Flags: 0x0
     Section {
-        Index: 6
+        Index: 7
         SectionName: "__la_symbol_ptr"
         SegmentName: "__DATA"
         Address: 0x100008000
@@ -167,7 +167,7 @@ SegmentCommand {
         Flags: S_LAZY_SYMBOL_POINTERS (0x7)
     }
     Section {
-        Index: 7
+        Index: 8
         SectionName: "__data"
         SegmentName: "__DATA"
         Address: 0x100008008
diff --git a/crates/examples/testfiles/macho/reloc-aarch64.o.objcopy b/crates/examples/testfiles/macho/reloc-aarch64.o.objcopy
index 4e5e946..706a31d 100644
--- a/crates/examples/testfiles/macho/reloc-aarch64.o.objcopy
+++ b/crates/examples/testfiles/macho/reloc-aarch64.o.objcopy
@@ -28,7 +28,7 @@ SegmentCommand {
     NumberOfSections: 2
     Flags: 0x0
     Section {
-        Index: 0
+        Index: 1
         SectionName: "__text"
         SegmentName: "__TEXT"
         Address: 0x0
@@ -147,7 +147,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 1
+        Index: 2
         SectionName: "__data"
         SegmentName: "__DATA"
         Address: 0x28
diff --git a/crates/examples/testfiles/macho/reloc-aarch64.o.readobj b/crates/examples/testfiles/macho/reloc-aarch64.o.readobj
index 4e5e946..706a31d 100644
--- a/crates/examples/testfiles/macho/reloc-aarch64.o.readobj
+++ b/crates/examples/testfiles/macho/reloc-aarch64.o.readobj
@@ -28,7 +28,7 @@ SegmentCommand {
     NumberOfSections: 2
     Flags: 0x0
     Section {
-        Index: 0
+        Index: 1
         SectionName: "__text"
         SegmentName: "__TEXT"
         Address: 0x0
@@ -147,7 +147,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 1
+        Index: 2
         SectionName: "__data"
         SegmentName: "__DATA"
         Address: 0x28
diff --git a/crates/examples/testfiles/macho/reloc-arm.o.readobj b/crates/examples/testfiles/macho/reloc-arm.o.readobj
index 89437db..7ed8a7b 100644
--- a/crates/examples/testfiles/macho/reloc-arm.o.readobj
+++ b/crates/examples/testfiles/macho/reloc-arm.o.readobj
@@ -28,7 +28,7 @@ SegmentCommand {
     NumberOfSections: 2
     Flags: 0x0
     Section {
-        Index: 0
+        Index: 1
         SectionName: "__text"
         SegmentName: "__TEXT"
         Address: 0x0
@@ -153,7 +153,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 1
+        Index: 2
         SectionName: "__data"
         SegmentName: "__DATA"
         Address: 0x28
diff --git a/crates/examples/testfiles/macho/reloc-i386.o.readobj b/crates/examples/testfiles/macho/reloc-i386.o.readobj
index 0a56680..e08137e 100644
--- a/crates/examples/testfiles/macho/reloc-i386.o.readobj
+++ b/crates/examples/testfiles/macho/reloc-i386.o.readobj
@@ -28,7 +28,7 @@ SegmentCommand {
     NumberOfSections: 2
     Flags: 0x0
     Section {
-        Index: 0
+        Index: 1
         SectionName: "__text"
         SegmentName: "__TEXT"
         Address: 0x0
@@ -66,7 +66,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 1
+        Index: 2
         SectionName: "__data"
         SegmentName: "__DATA"
         Address: 0x11
diff --git a/crates/examples/testfiles/macho/reloc-x86_64.o.objcopy b/crates/examples/testfiles/macho/reloc-x86_64.o.objcopy
index 14b775e..fd90425 100644
--- a/crates/examples/testfiles/macho/reloc-x86_64.o.objcopy
+++ b/crates/examples/testfiles/macho/reloc-x86_64.o.objcopy
@@ -28,7 +28,7 @@ SegmentCommand {
     NumberOfSections: 2
     Flags: 0x0
     Section {
-        Index: 0
+        Index: 1
         SectionName: "__text"
         SegmentName: "__TEXT"
         Address: 0x0
@@ -131,7 +131,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 1
+        Index: 2
         SectionName: "__data"
         SegmentName: "__DATA"
         Address: 0x53
diff --git a/crates/examples/testfiles/macho/reloc-x86_64.o.readobj b/crates/examples/testfiles/macho/reloc-x86_64.o.readobj
index 14b775e..fd90425 100644
--- a/crates/examples/testfiles/macho/reloc-x86_64.o.readobj
+++ b/crates/examples/testfiles/macho/reloc-x86_64.o.readobj
@@ -28,7 +28,7 @@ SegmentCommand {
     NumberOfSections: 2
     Flags: 0x0
     Section {
-        Index: 0
+        Index: 1
         SectionName: "__text"
         SegmentName: "__TEXT"
         Address: 0x0
@@ -131,7 +131,7 @@ SegmentCommand {
         }
     }
     Section {
-        Index: 1
+        Index: 2
         SectionName: "__data"
         SegmentName: "__DATA"
         Address: 0x53