From 7bf9f8e7580bbba0f22f02c3892744dd188203bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 6 Jun 2022 03:53:30 +0200 Subject: [PATCH] FileFlags::Elf: Add os_abi (#438) --- crates/examples/testfiles/elf/base-strip.objdump | 2 +- crates/examples/testfiles/elf/base.o.objdump | 2 +- crates/examples/testfiles/elf/base.objdump | 2 +- src/common.rs | 2 ++ src/read/elf/file.rs | 1 + src/write/elf/object.rs | 8 ++++---- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/examples/testfiles/elf/base-strip.objdump b/crates/examples/testfiles/elf/base-strip.objdump index fc3e4f6a..e47efc07 100644 --- a/crates/examples/testfiles/elf/base-strip.objdump +++ b/crates/examples/testfiles/elf/base-strip.objdump @@ -1,7 +1,7 @@ Format: Elf Little-endian 64-bit Kind: Dynamic Architecture: X86_64 -Flags: Elf { e_flags: 0 } +Flags: Elf { os_abi: 0, e_flags: 0 } Relative Address Base: 0 Entry Address: 570 Build ID: [d4, 46, a0, 61, bb, 9a, c2, 7a, b4, 3b, 11, 71, 8f, de, df, 5b, 7f, 3a, f6, f4] diff --git a/crates/examples/testfiles/elf/base.o.objdump b/crates/examples/testfiles/elf/base.o.objdump index 0b947310..a3426e65 100644 --- a/crates/examples/testfiles/elf/base.o.objdump +++ b/crates/examples/testfiles/elf/base.o.objdump @@ -1,7 +1,7 @@ Format: Elf Little-endian 64-bit Kind: Relocatable Architecture: X86_64 -Flags: Elf { e_flags: 0 } +Flags: Elf { os_abi: 0, e_flags: 0 } Relative Address Base: 0 Entry Address: 0 0: Section { name: "", address: 0, size: 0, align: 0, kind: Metadata, flags: Elf { sh_flags: 0 } } diff --git a/crates/examples/testfiles/elf/base.objdump b/crates/examples/testfiles/elf/base.objdump index 9192d57b..f8763c19 100644 --- a/crates/examples/testfiles/elf/base.objdump +++ b/crates/examples/testfiles/elf/base.objdump @@ -1,7 +1,7 @@ Format: Elf Little-endian 64-bit Kind: Dynamic Architecture: X86_64 -Flags: Elf { e_flags: 0 } +Flags: Elf { os_abi: 0, e_flags: 0 } Relative Address Base: 0 Entry Address: 570 Build ID: [d4, 46, a0, 61, bb, 9a, c2, 7a, b4, 3b, 11, 71, 8f, de, df, 5b, 7f, 3a, f6, f4] diff --git a/src/common.rs b/src/common.rs index 987c6f88..e8529566 100644 --- a/src/common.rs +++ b/src/common.rs @@ -353,6 +353,8 @@ pub enum FileFlags { None, /// ELF file flags. Elf { + /// `os_abi` field in the ELF file header. + os_abi: u8, /// `e_flags` field in the ELF file header. e_flags: u32, }, diff --git a/src/read/elf/file.rs b/src/read/elf/file.rs index d5a2647b..0af86d6b 100644 --- a/src/read/elf/file.rs +++ b/src/read/elf/file.rs @@ -419,6 +419,7 @@ where fn flags(&self) -> FileFlags { FileFlags::Elf { + os_abi: self.header.e_ident().os_abi, e_flags: self.header.e_flags(self.endian), } } diff --git a/src/write/elf/object.rs b/src/write/elf/object.rs index b4b5f400..bb1688ac 100644 --- a/src/write/elf/object.rs +++ b/src/write/elf/object.rs @@ -288,13 +288,13 @@ impl<'a> Object<'a> { ))); } }; - let e_flags = if let FileFlags::Elf { e_flags } = self.flags { - e_flags + let (os_abi, e_flags) = if let FileFlags::Elf { os_abi, e_flags } = self.flags { + (os_abi, e_flags) } else { - 0 + (elf::ELFOSABI_NONE, 0) }; writer.write_file_header(&FileHeader { - os_abi: elf::ELFOSABI_NONE, + os_abi, abi_version: 0, e_type, e_machine,