From b6e2710b5e32b054a8e5cea9202ac586d5c5f42e Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Tue, 30 Apr 2024 00:00:00 +0000 Subject: [PATCH] readobj/macho: fix section index (#674) --- crates/examples/src/readobj/macho.rs | 2 +- .../macho/base-aarch64-debug.o.readobj | 22 ++++++++--------- .../testfiles/macho/base-aarch64.o.objcopy | 6 ++--- .../testfiles/macho/base-aarch64.o.readobj | 6 ++--- .../testfiles/macho/base-aarch64.readobj | 10 ++++---- .../macho/base-x86_64-debug.o.readobj | 24 +++++++++---------- .../testfiles/macho/base-x86_64.o.objcopy | 8 +++---- .../testfiles/macho/base-x86_64.o.readobj | 8 +++---- .../testfiles/macho/base-x86_64.readobj | 16 ++++++------- .../testfiles/macho/reloc-aarch64.o.objcopy | 4 ++-- .../testfiles/macho/reloc-aarch64.o.readobj | 4 ++-- .../testfiles/macho/reloc-arm.o.readobj | 4 ++-- .../testfiles/macho/reloc-i386.o.readobj | 4 ++-- .../testfiles/macho/reloc-x86_64.o.objcopy | 4 ++-- .../testfiles/macho/reloc-x86_64.o.readobj | 4 ++-- 15 files changed, 63 insertions(+), 63 deletions(-) diff --git a/crates/examples/src/readobj/macho.rs b/crates/examples/src/readobj/macho.rs index e2cd7c32..456b77ea 100644 --- a/crates/examples/src/readobj/macho.rs +++ b/crates/examples/src/readobj/macho.rs @@ -609,8 +609,8 @@ fn print_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/crates/examples/testfiles/macho/base-aarch64-debug.o.readobj b/crates/examples/testfiles/macho/base-aarch64-debug.o.readobj index 8ab0bd8a..6c37941a 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 3acaee40..ad82dbfc 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 3acaee40..ad82dbfc 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 770c82c3..d26931dd 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 2b6fd72f..ecae9f1a 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 4b66798b..71c78cfd 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 4b66798b..71c78cfd 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 b097dd8c..eb06e476 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 4e5e9464..706a31d5 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 4e5e9464..706a31d5 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 89437dba..7ed8a7b0 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 0a566807..e08137e2 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 14b775e8..fd904259 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 14b775e8..fd904259 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