Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use u64/i64 instead of usize/isize for r_offset and r_addend #86

Merged
merged 2 commits into from
Apr 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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