Repository: gimli-rs/object
Pull request #683 (2024-05-09 00:40:55)

readobj/elf: delete duplicated field
Also fix a typo.


Patch:
diff --git a/crates/examples/src/readobj/elf.rs b/crates/examples/src/readobj/elf.rs
index 8a0091c..e21770b 100644
--- a/crates/examples/src/readobj/elf.rs
+++ b/crates/examples/src/readobj/elf.rs
@@ -43,7 +43,6 @@ fn print_file_header<Elf: FileHeader>(p: &mut Printer<'_>, endian: Elf::Endian,
         } else {
             p.field_hex("Version", version);
         }
-        p.field_enum("Type", elf.e_type(endian), FLAGS_ET);
         p.field_hex("Entry", elf.e_entry(endian).into());
         p.field_hex("ProgramHeaderOffset", elf.e_phoff(endian).into());
         p.field_hex("SectionHeaderOffset", elf.e_shoff(endian).into());
diff --git a/src/read/elf/section.rs b/src/read/elf/section.rs
index eaf7277..44a2513 100644
--- a/src/read/elf/section.rs
+++ b/src/read/elf/section.rs
@@ -59,7 +59,7 @@ impl<'data, Elf: FileHeader, R: ReadRef<'data>> SectionTable<'data, Elf, R> {
     /// Returns an error for the null section at index 0.
     pub fn section(&self, index: SectionIndex) -> read::Result<&'data Elf::SectionHeader> {
         if index.0 == 0 {
-            return Err(read::Error("Invalid ELF symbol index"));
+            return Err(read::Error("Invalid ELF section index"));
         }
         self.sections
             .get(index.0)


Test patch:
diff --git a/crates/examples/testfiles/archive/bsd.a.readobj b/crates/examples/testfiles/archive/bsd.a.readobj
index a95de26..582405d 100644
--- a/crates/examples/testfiles/archive/bsd.a.readobj
+++ b/crates/examples/testfiles/archive/bsd.a.readobj
@@ -15,7 +15,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x228
@@ -281,7 +280,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x228
@@ -547,7 +545,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x230
@@ -813,7 +810,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x228
@@ -1079,7 +1075,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x228
@@ -1345,7 +1340,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x228
diff --git a/crates/examples/testfiles/archive/gnu.a.readobj b/crates/examples/testfiles/archive/gnu.a.readobj
index 6e742b3..7588e92 100644
--- a/crates/examples/testfiles/archive/gnu.a.readobj
+++ b/crates/examples/testfiles/archive/gnu.a.readobj
@@ -15,7 +15,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x228
@@ -281,7 +280,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x228
@@ -547,7 +545,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x230
@@ -813,7 +810,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x228
@@ -1079,7 +1075,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x228
@@ -1345,7 +1340,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x228
diff --git a/crates/examples/testfiles/elf/base-aarch64.o.readobj b/crates/examples/testfiles/elf/base-aarch64.o.readobj
index 1b76f98..60fa8ba 100644
--- a/crates/examples/testfiles/elf/base-aarch64.o.readobj
+++ b/crates/examples/testfiles/elf/base-aarch64.o.readobj
@@ -12,7 +12,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_AARCH64 (0xB7)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x280
diff --git a/crates/examples/testfiles/elf/base-aarch64.readobj b/crates/examples/testfiles/elf/base-aarch64.readobj
index 640ab74..8614ac0 100644
--- a/crates/examples/testfiles/elf/base-aarch64.readobj
+++ b/crates/examples/testfiles/elf/base-aarch64.readobj
@@ -12,7 +12,6 @@ FileHeader {
     Type: ET_DYN (0x3)
     Machine: EM_AARCH64 (0xB7)
     Version: EV_CURRENT (0x1)
-    Type: ET_DYN (0x3)
     Entry: 0x620
     ProgramHeaderOffset: 0x40
     SectionHeaderOffset: 0x1CB8
diff --git a/crates/examples/testfiles/elf/base-mips64el.o.readobj b/crates/examples/testfiles/elf/base-mips64el.o.readobj
index 190d89d..29fc81e 100644
--- a/crates/examples/testfiles/elf/base-mips64el.o.readobj
+++ b/crates/examples/testfiles/elf/base-mips64el.o.readobj
@@ -12,7 +12,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_MIPS (0x8)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x3E8
diff --git a/crates/examples/testfiles/elf/base-mips64el.readobj b/crates/examples/testfiles/elf/base-mips64el.readobj
index 76d870b..283ff7f 100644
--- a/crates/examples/testfiles/elf/base-mips64el.readobj
+++ b/crates/examples/testfiles/elf/base-mips64el.readobj
@@ -12,7 +12,6 @@ FileHeader {
     Type: ET_EXEC (0x2)
     Machine: EM_MIPS (0x8)
     Version: EV_CURRENT (0x1)
-    Type: ET_EXEC (0x2)
     Entry: 0x120000900
     ProgramHeaderOffset: 0x40
     SectionHeaderOffset: 0x1C50
diff --git a/crates/examples/testfiles/elf/base-strip.readobj b/crates/examples/testfiles/elf/base-strip.readobj
index 1644813..43f8433 100644
--- a/crates/examples/testfiles/elf/base-strip.readobj
+++ b/crates/examples/testfiles/elf/base-strip.readobj
@@ -12,7 +12,6 @@ FileHeader {
     Type: ET_DYN (0x3)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_DYN (0x3)
     Entry: 0x570
     ProgramHeaderOffset: 0x40
     SectionHeaderOffset: 0x0
diff --git a/crates/examples/testfiles/elf/base.o.readobj b/crates/examples/testfiles/elf/base.o.readobj
index 8b34b81..908c2f1 100644
--- a/crates/examples/testfiles/elf/base.o.readobj
+++ b/crates/examples/testfiles/elf/base.o.readobj
@@ -12,7 +12,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x2D0
diff --git a/crates/examples/testfiles/elf/base.readobj b/crates/examples/testfiles/elf/base.readobj
index c1a43e2..548479f 100644
--- a/crates/examples/testfiles/elf/base.readobj
+++ b/crates/examples/testfiles/elf/base.readobj
@@ -12,7 +12,6 @@ FileHeader {
     Type: ET_DYN (0x3)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_DYN (0x3)
     Entry: 0x570
     ProgramHeaderOffset: 0x40
     SectionHeaderOffset: 0x1948
diff --git a/crates/examples/testfiles/elf/nostd-mipsel.o.readobj b/crates/examples/testfiles/elf/nostd-mipsel.o.readobj
index 6de02f3..d5fe089 100644
--- a/crates/examples/testfiles/elf/nostd-mipsel.o.readobj
+++ b/crates/examples/testfiles/elf/nostd-mipsel.o.readobj
@@ -12,7 +12,6 @@ FileHeader {
     Type: ET_REL (0x1)
     Machine: EM_MIPS (0x8)
     Version: EV_CURRENT (0x1)
-    Type: ET_REL (0x1)
     Entry: 0x0
     ProgramHeaderOffset: 0x0
     SectionHeaderOffset: 0x1A0
diff --git a/crates/examples/testfiles/elf/nostd-mipsel.readobj b/crates/examples/testfiles/elf/nostd-mipsel.readobj
index c6afcdf..6c0a024 100644
--- a/crates/examples/testfiles/elf/nostd-mipsel.readobj
+++ b/crates/examples/testfiles/elf/nostd-mipsel.readobj
@@ -12,7 +12,6 @@ FileHeader {
     Type: ET_EXEC (0x2)
     Machine: EM_MIPS (0x8)
     Version: EV_CURRENT (0x1)
-    Type: ET_EXEC (0x2)
     Entry: 0x0
     ProgramHeaderOffset: 0x34
     SectionHeaderOffset: 0x123C
diff --git a/crates/rewrite/testfiles/elf/base.noop b/crates/rewrite/testfiles/elf/base.noop
index 46a7312..3899ebf 100644
--- a/crates/rewrite/testfiles/elf/base.noop
+++ b/crates/rewrite/testfiles/elf/base.noop
@@ -12,7 +12,6 @@ FileHeader {
     Type: ET_DYN (0x3)
     Machine: EM_X86_64 (0x3E)
     Version: EV_CURRENT (0x1)
-    Type: ET_DYN (0x3)
     Entry: 0x570
     ProgramHeaderOffset: 0x40
     SectionHeaderOffset: 0x1948