#[non_exhaustive]pub struct Reloc {
pub offset: usize,
pub kind: RelocKind,
pub symbol: String,
pub addend: i64,
}Expand description
A place in the code that refers to a symbol defined elsewhere (declared
with Emitter::declare_external): the bytes at offset receive the
value kind computes from the symbol’s address and addend. The bytes
hold zero until a linker patches them.
§Examples
use backend_lang::mir::Function;
use backend_lang::x86_64::{op, Emitter, RelocKind, SYSV};
let mut f = Function::new("f", &SYSV);
f.omit_frame_pointer();
let b = f.block()?;
let puts = f.symbol("puts")?;
f.push(b, op::CALL, &[puts.into()])?;
f.push(b, op::RET, &[])?;
let mut e = Emitter::new();
e.declare_external("puts")?;
e.function(&f)?;
let p = e.finish()?;
let r = &p.relocations()[0];
assert_eq!((r.kind, r.symbol.as_str(), r.addend), (RelocKind::Call32, "puts", -4));
// The field follows the `call` opcode and holds zero until linked.
assert_eq!(p.bytes()[r.offset - 1..r.offset + 4], [0xE8, 0, 0, 0, 0]);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.offset: usizeWhere the patched bytes start, from the start of the code.
kind: RelocKindWhat is computed.
symbol: StringThe symbol whose address is used.
addend: i64The constant added to the address.
Implementations§
Trait Implementations§
impl Eq for Reloc
impl StructuralPartialEq for Reloc
Auto Trait Implementations§
impl Freeze for Reloc
impl RefUnwindSafe for Reloc
impl Send for Reloc
impl Sync for Reloc
impl Unpin for Reloc
impl UnsafeUnpin for Reloc
impl UnwindSafe for Reloc
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more