Skip to content

Commit

Permalink
Add ELF bindings for DT_REL relocations. (#85) (#86)
Browse files Browse the repository at this point in the history
This includes the `Elf_Rel` struct.
  • Loading branch information
sunfishcode authored Oct 8, 2023
1 parent 7e56cf9 commit ac32a2f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub const DT_SYMTAB: usize = 6;
pub const DT_RELA: usize = 7;
pub const DT_RELASZ: usize = 8;
pub const DT_RELAENT: usize = 9;
pub const DT_REL: usize = 17;
pub const DT_RELSZ: usize = 18;
pub const DT_RELENT: usize = 19;
pub const DT_SYMENT: usize = 11;
pub const DT_VERSYM: usize = 0x6fff_fff0;
pub const DT_VERDEF: usize = 0x6fff_fffc;
Expand Down Expand Up @@ -233,6 +236,34 @@ impl Elf_Rela {
}
}

#[cfg(target_pointer_width = "32")]
#[repr(C)]
pub struct Elf_Rel {
pub r_offset: usize,
pub r_info: u32,
}

#[cfg(target_pointer_width = "64")]
#[repr(C)]
pub struct Elf_Rel {
pub r_offset: usize,
pub r_info: u64,
}

impl Elf_Rel {
#[inline]
pub fn type_(&self) -> u32 {
#[cfg(target_pointer_width = "32")]
{
self.r_info & 0xff
}
#[cfg(target_pointer_width = "64")]
{
(self.r_info & 0xffff_ffff) as u32
}
}
}

#[cfg(target_arch = "x86_64")]
pub const R_RELATIVE: u32 = 8; // `R_X86_64_RELATIVE`
#[cfg(target_arch = "x86")]
Expand Down

0 comments on commit ac32a2f

Please sign in to comment.