Skip to content

Commit

Permalink
Merge pull request #86 from Amanieu/u64_reloc
Browse files Browse the repository at this point in the history
Use u64/i64 instead of usize/isize for r_offset and r_addend
  • Loading branch information
m4b authored Apr 16, 2018
2 parents 4bcb2a0 + bf3f7ba commit 971744d
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/elf/reloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,21 @@ macro_rules! elf_rela_std_impl { ($size:ident, $isize:ty) => {
impl From<Rela> for Reloc {
fn from(rela: Rela) -> Self {
Reloc {
r_offset: rela.r_offset as usize,
r_addend: rela.r_addend as isize,
r_offset: rela.r_offset as u64,
r_addend: Some(rela.r_addend as i64),
r_sym: r_sym(rela.r_info) as usize,
r_type: r_type(rela.r_info),
is_rela: true,
}
}
}

impl From<Rel> for Reloc {
fn from(rel: Rel) -> Self {
Reloc {
r_offset: rel.r_offset as usize,
r_addend: 0,
r_offset: rel.r_offset as u64,
r_addend: None,
r_sym: r_sym(rel.r_info) as usize,
r_type: r_type(rel.r_info),
is_rela: false,
}
}
}
Expand All @@ -147,7 +145,7 @@ macro_rules! elf_rela_std_impl { ($size:ident, $isize:ty) => {
Rela {
r_offset: rela.r_offset as $size,
r_info: r_info,
r_addend: rela.r_addend as $isize,
r_addend: rela.r_addend.unwrap_or(0) as $isize,
}
}
}
Expand Down Expand Up @@ -266,15 +264,13 @@ if_alloc! {
/// A unified ELF relocation structure
pub struct Reloc {
/// Address
pub r_offset: usize,
pub r_offset: u64,
/// Addend
pub r_addend: isize,
pub r_addend: Option<i64>,
/// The index into the corresponding symbol table - either dynamic or regular
pub r_sym: usize,
/// The relocation type
pub r_type: u32,
/// Whether this was constructed from a rela or rel relocation entry type
pub is_rela: bool
}

impl Reloc {
Expand Down Expand Up @@ -377,14 +373,22 @@ if_alloc! {

impl fmt::Debug for Reloc {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f,
"r_offset: {:x} r_typ: {} r_sym: {} r_addend: {:x} rela: {}",
self.r_offset,
self.r_type,
self.r_sym,
self.r_addend,
self.is_rela,
)
if let Some(addend) = self.r_addend {
write!(f,
"r_offset: {:x} r_typ: {} r_sym: {} r_addend: {:x}",
self.r_offset,
self.r_type,
self.r_sym,
addend,
)
} else {
write!(f,
"r_offset: {:x} r_typ: {} r_sym: {}",
self.r_offset,
self.r_type,
self.r_sym,
)
}
}
}
} // end if_alloc

0 comments on commit 971744d

Please sign in to comment.