Skip to content

Commit

Permalink
read/elf: GNU properties do not use section alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed May 5, 2023
1 parent f3d3c4f commit 7908f82
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
25 changes: 25 additions & 0 deletions src/read/elf/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,15 @@ pub trait FileHeader: Debug + Pod {
/// This is a property of the type, not a value in the header data.
fn is_type_64(&self) -> bool;

/// Return true if this type is a 64-bit header.
///
/// This is a property of the type, not a value in the header data.
///
/// This is the same as `is_type_64`, but is non-dispatchable.
fn is_type_64_sized() -> bool
where
Self: Sized;

fn e_ident(&self) -> &elf::Ident;
fn e_type(&self, endian: Self::Endian) -> u16;
fn e_machine(&self, endian: Self::Endian) -> u16;
Expand Down Expand Up @@ -724,6 +733,14 @@ impl<Endian: endian::Endian> FileHeader for elf::FileHeader32<Endian> {
false
}

#[inline]
fn is_type_64_sized() -> bool
where
Self: Sized,
{
false
}

#[inline]
fn e_ident(&self) -> &elf::Ident {
&self.e_ident
Expand Down Expand Up @@ -813,6 +830,14 @@ impl<Endian: endian::Endian> FileHeader for elf::FileHeader64<Endian> {
true
}

#[inline]
fn is_type_64_sized() -> bool
where
Self: Sized,
{
true
}

#[inline]
fn e_ident(&self) -> &elf::Ident {
&self.e_ident
Expand Down
13 changes: 5 additions & 8 deletions src/read/elf/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,7 @@ where
}
self.data = data;

Ok(Some(Note {
align: self.align,
header,
name,
desc,
}))
Ok(Some(Note { header, name, desc }))
}
}

Expand All @@ -95,7 +90,6 @@ pub struct Note<'data, Elf>
where
Elf: FileHeader,
{
align: usize,
header: &'data Elf::NoteHeader,
name: &'data [u8],
desc: &'data [u8],
Expand Down Expand Up @@ -152,9 +146,12 @@ impl<'data, Elf: FileHeader> Note<'data, Elf> {
if self.name() != elf::ELF_NOTE_GNU || self.n_type(endian) != elf::NT_GNU_PROPERTY_TYPE_0 {
return None;
}
// Use the ELF class instead of the section alignment.
// This matches what other parsers do.
let align = if Elf::is_type_64_sized() { 8 } else { 4 };
Some(GnuPropertyIterator {
endian,
align: self.align,
align,
data: Bytes(self.desc),
})
}
Expand Down

0 comments on commit 7908f82

Please sign in to comment.