]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/sgx/abi/reloc.rs
Add x86_64-fortanix-unknown-sgx target to libstd and dependencies
[rust.git] / src / libstd / sys / sgx / abi / reloc.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use slice::from_raw_parts;
12 use super::mem;
13
14 const R_X86_64_RELATIVE: u32 = 8;
15
16 #[repr(packed)]
17 struct Rela<T> {
18     offset: T,
19     info: T,
20     addend: T,
21 }
22
23 pub fn relocate_elf_rela() {
24     extern {
25         static RELA: u64;
26         static RELACOUNT: usize;
27     }
28
29     if unsafe { RELACOUNT } == 0 { return }  // unsafe ok: link-time constant
30
31     let relas = unsafe {
32         from_raw_parts::<Rela<u64>>(mem::rel_ptr(RELA), RELACOUNT)  // unsafe ok: link-time constant
33     };
34     for rela in relas {
35         if rela.info != (/*0 << 32 |*/ R_X86_64_RELATIVE as u64) {
36             panic!("Invalid relocation");
37         }
38         unsafe { *mem::rel_ptr_mut::<*const ()>(rela.offset) = mem::rel_ptr(rela.addend) };
39     }
40 }