#[non_exhaustive]pub enum RelocationKind {
X86_64(X86_64Reloc),
Aarch64(Aarch64Reloc),
}Expand description
How a relocation patches its bytes: an architecture-specific kind.
Kinds are named for what they compute, not for one format’s numbering, so each
writer maps them to its own relocation types. Build one from the architecture enum
with From.
§Examples
use object_lang::{Aarch64Reloc, Architecture, RelocationKind, X86_64Reloc};
let x = RelocationKind::from(X86_64Reloc::Abs64);
let a = RelocationKind::from(Aarch64Reloc::AdrPrelPgHi21);
assert_eq!(x.architecture(), Architecture::X86_64);
assert_eq!(a.architecture(), Architecture::Aarch64);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Implementations§
Source§impl RelocationKind
impl RelocationKind
Sourcepub const fn architecture(self) -> Architecture
pub const fn architecture(self) -> Architecture
The architecture this kind belongs to. An object may only carry relocations of its own architecture.
§Examples
use object_lang::{Architecture, RelocationKind, X86_64Reloc};
assert_eq!(RelocationKind::from(X86_64Reloc::Plt32).architecture(), Architecture::X86_64);Sourcepub const fn size(self) -> u64
pub const fn size(self) -> u64
The number of bytes the relocation patches, starting at its offset.
§Examples
use object_lang::{Aarch64Reloc, RelocationKind, X86_64Reloc};
assert_eq!(RelocationKind::from(X86_64Reloc::Abs64).size(), 8);
assert_eq!(RelocationKind::from(X86_64Reloc::Plt32).size(), 4);
assert_eq!(RelocationKind::from(Aarch64Reloc::Call26).size(), 4);Sourcepub const fn is_instruction(self) -> bool
pub const fn is_instruction(self) -> bool
Whether the relocation patches an instruction’s immediate field rather than a plain data word. AArch64 instructions are 4-byte aligned, so such a relocation’s offset must be a multiple of 4.
§Examples
use object_lang::{Aarch64Reloc, RelocationKind, X86_64Reloc};
assert!(RelocationKind::from(Aarch64Reloc::AddAbsLo12Nc).is_instruction());
assert!(!RelocationKind::from(Aarch64Reloc::Prel32).is_instruction());
assert!(!RelocationKind::from(X86_64Reloc::Pc32).is_instruction());Trait Implementations§
Source§impl Clone for RelocationKind
impl Clone for RelocationKind
impl Copy for RelocationKind
Source§impl Debug for RelocationKind
impl Debug for RelocationKind
impl Eq for RelocationKind
Source§impl From<Aarch64Reloc> for RelocationKind
impl From<Aarch64Reloc> for RelocationKind
Source§fn from(kind: Aarch64Reloc) -> Self
fn from(kind: Aarch64Reloc) -> Self
Converts to this type from the input type.
Source§impl From<X86_64Reloc> for RelocationKind
impl From<X86_64Reloc> for RelocationKind
Source§fn from(kind: X86_64Reloc) -> Self
fn from(kind: X86_64Reloc) -> Self
Converts to this type from the input type.
Source§impl Hash for RelocationKind
impl Hash for RelocationKind
Source§impl PartialEq for RelocationKind
impl PartialEq for RelocationKind
impl StructuralPartialEq for RelocationKind
Auto Trait Implementations§
impl Freeze for RelocationKind
impl RefUnwindSafe for RelocationKind
impl Send for RelocationKind
impl Sync for RelocationKind
impl Unpin for RelocationKind
impl UnsafeUnpin for RelocationKind
impl UnwindSafe for RelocationKind
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