Skip to content

Commit ab92cec

Browse files
Merge pull request #2 from mkj/pr/elf-os
Ignore ELF header OS byte
2 parents 27734a9 + c03580d commit ab92cec

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ where
8888
const ET_EXEC: u16 = 0x0002;
8989
/// Standard ELF magic header
9090
const ELF_MAGIC: u32 = 0x7F454C46;
91-
/// 32-bit, little-endian, version 1, SysV
91+
/// 32-bit, little-endian, version 1, low OS byte ignored.
9292
const DESIRED_ELF_VERSION: u32 = 0x01010100;
9393

9494
/// Make a new loader
@@ -98,7 +98,8 @@ where
9898
// File doesn't start 0x7F E L F
9999
return Err(Error::NotAnElfFile);
100100
}
101-
let class_endian_version_abi = data_source.read_u32_be(0x04)?;
101+
// Mask out the OS byte which varies between Rust compiler versions.
102+
let class_endian_version_abi = data_source.read_u32_be(0x04)? & 0xffffff00;
102103
if class_endian_version_abi != Self::DESIRED_ELF_VERSION {
103104
return Err(Error::WrongElfFile);
104105
}
@@ -156,15 +157,15 @@ where
156157
}
157158

158159
/// Create a section header iterator.
159-
pub fn iter_section_headers(&self) -> IterSectionHeaders<DS> {
160+
pub fn iter_section_headers(&self) -> IterSectionHeaders<'_, DS> {
160161
IterSectionHeaders {
161162
parent: self,
162163
next_section: 0,
163164
}
164165
}
165166

166167
/// Create a program header iterator.
167-
pub fn iter_program_headers(&self) -> IterProgramHeaders<DS> {
168+
pub fn iter_program_headers(&self) -> IterProgramHeaders<'_, DS> {
168169
IterProgramHeaders {
169170
parent: self,
170171
next_program_header: 0,

0 commit comments

Comments
 (0)