1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use super::mem;
use crate::slice::from_raw_parts;
const R_X86_64_RELATIVE: u32 = 8;
#[repr(packed)]
struct Rela<T> {
offset: T,
info: T,
addend: T,
}
pub fn relocate_elf_rela() {
extern "C" {
static RELA: u64;
static RELACOUNT: usize;
}
if unsafe { RELACOUNT } == 0 {
return;
}
let relas = unsafe {
from_raw_parts::<Rela<u64>>(mem::rel_ptr(RELA), RELACOUNT)
};
for rela in relas {
if rela.info != (R_X86_64_RELATIVE as u64) {
rtabort!("Invalid relocation");
}
unsafe { *mem::rel_ptr_mut::<*const ()>(rela.offset) = mem::rel_ptr(rela.addend) };
}
}