#[non_exhaustive]pub struct Relocation {
pub offset: u64,
pub kind: RelocationKind,
pub target: RelocationTarget,
pub addend: i64,
}Expand description
A place in a section to patch: the bytes at offset receive the value kind
computes from the address of target plus addend.
The addend is always explicit, whatever format the relocation is written in.
§Examples
use object_lang::{Relocation, RelocationKind, RelocationTarget, SymbolId, X86_64Reloc};
// `call callee` is e8 followed by a 32-bit displacement from the next instruction.
let reloc = Relocation::new(1, X86_64Reloc::Plt32, RelocationTarget::Symbol(target), -4);
assert_eq!(reloc.kind, RelocationKind::X86_64(X86_64Reloc::Plt32));
assert_eq!(reloc.addend, -4);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: u64Where the patched bytes start, as an offset within the section.
kind: RelocationKindHow the bytes are computed and how many are patched.
target: RelocationTargetThe symbol or section whose address is used.
addend: i64A constant added to the target’s address.
Implementations§
Source§impl Relocation
impl Relocation
Sourcepub fn new(
offset: u64,
kind: impl Into<RelocationKind>,
target: RelocationTarget,
addend: i64,
) -> Self
pub fn new( offset: u64, kind: impl Into<RelocationKind>, target: RelocationTarget, addend: i64, ) -> Self
A relocation at offset of kind, against target, with addend.
§Examples
use object_lang::{Aarch64Reloc, Relocation, RelocationTarget};
let r = Relocation::new(8, Aarch64Reloc::Abs64, RelocationTarget::Section(data), 16);
assert_eq!((r.offset, r.addend), (8, 16));Trait Implementations§
Source§impl Clone for Relocation
impl Clone for Relocation
impl Copy for Relocation
Source§impl Debug for Relocation
impl Debug for Relocation
impl Eq for Relocation
Source§impl Hash for Relocation
impl Hash for Relocation
Source§impl PartialEq for Relocation
impl PartialEq for Relocation
impl StructuralPartialEq for Relocation
Auto Trait Implementations§
impl Freeze for Relocation
impl RefUnwindSafe for Relocation
impl Send for Relocation
impl Sync for Relocation
impl Unpin for Relocation
impl UnsafeUnpin for Relocation
impl UnwindSafe for Relocation
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