Skip to content

Commit b10fe3d

Browse files
authored
Add ELF bindings for DT_REL relocations. (#85)
This includes the `Elf_Rel` struct.
1 parent 5f4f6c1 commit b10fe3d

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

src/elf.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ pub const DT_SYMTAB: usize = 6;
4242
pub const DT_RELA: usize = 7;
4343
pub const DT_RELASZ: usize = 8;
4444
pub const DT_RELAENT: usize = 9;
45+
pub const DT_REL: usize = 17;
46+
pub const DT_RELSZ: usize = 18;
47+
pub const DT_RELENT: usize = 19;
4548
pub const DT_SYMENT: usize = 11;
4649
pub const DT_VERSYM: usize = 0x6fff_fff0;
4750
pub const DT_VERDEF: usize = 0x6fff_fffc;
@@ -233,6 +236,34 @@ impl Elf_Rela {
233236
}
234237
}
235238

239+
#[cfg(target_pointer_width = "32")]
240+
#[repr(C)]
241+
pub struct Elf_Rel {
242+
pub r_offset: usize,
243+
pub r_info: u32,
244+
}
245+
246+
#[cfg(target_pointer_width = "64")]
247+
#[repr(C)]
248+
pub struct Elf_Rel {
249+
pub r_offset: usize,
250+
pub r_info: u64,
251+
}
252+
253+
impl Elf_Rel {
254+
#[inline]
255+
pub fn type_(&self) -> u32 {
256+
#[cfg(target_pointer_width = "32")]
257+
{
258+
self.r_info & 0xff
259+
}
260+
#[cfg(target_pointer_width = "64")]
261+
{
262+
(self.r_info & 0xffff_ffff) as u32
263+
}
264+
}
265+
}
266+
236267
#[cfg(target_arch = "x86_64")]
237268
pub const R_RELATIVE: u32 = 8; // `R_X86_64_RELATIVE`
238269
#[cfg(target_arch = "x86")]

0 commit comments

Comments
 (0)