Skip to main content

Linker

Struct Linker 

Source
pub struct Linker { /* private fields */ }
Expand description

The linker: collects fragments and labels, resolves everything.

Implementations§

Source§

impl Linker

Source

pub fn new() -> Self

Create a new, empty linker with base address 0.

Source

pub fn set_base_address(&mut self, addr: u64)

Set the base (origin) address for the assembled output.

Source

pub fn base_address(&self) -> u64

Get the base address.

Source

pub fn fragment_count(&self) -> usize

The number of fragments currently added.

Source

pub fn define_external(&mut self, name: &str, addr: u64)

Define an external label at a known absolute address.

Source

pub fn define_constant(&mut self, name: &str, value: i128)

Define a constant value (.equ / .set).

Source

pub fn get_constant(&self, name: &str) -> Option<&i128>

Look up a constant value by name.

Source

pub fn add_label(&mut self, name: &str, span: Span) -> Result<(), AsmError>

Add a label definition at the current position (before the next fragment).

Source

pub fn add_fragment(&mut self, fragment: Fragment)

Add a pre-built fragment.

Source

pub fn add_bytes(&mut self, bytes: Vec<u8>, span: Span)

Convenience: add fixed bytes (data, non-branch instructions, etc.).

Source

pub fn add_encoded( &mut self, bytes: InstrBytes, relocation: Option<Relocation>, relax: Option<RelaxInfo>, span: Span, ) -> Result<(), AsmError>

Add an encoded instruction, automatically choosing Fixed or Relaxable.

Source

pub fn add_alignment( &mut self, alignment: u32, fill: u8, max_skip: Option<u32>, use_nop: bool, span: Span, )

Add alignment padding.

Source

pub fn add_org(&mut self, target: u64, fill: u8, span: Span)

Add an .org directive: advance the location counter to target, padding with fill bytes.

Source

pub fn resolve( &mut self, ) -> Result<(Vec<u8>, Vec<(String, u64)>, Vec<AppliedRelocation>, Vec<u64>), AsmError>

Resolve all labels, perform branch relaxation, and return the final bytes together with a label→address table and applied relocations.

§Note

This method consumes the linker’s internal fragment list. After calling resolve(), the Linker is left in an empty state — calling resolve() again will produce an empty output. If you need to re-link, create a new Linker instance and re-add all fragments.

Trait Implementations§

Source§

impl Debug for Linker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Linker

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Linker

§

impl RefUnwindSafe for Linker

§

impl !Send for Linker

§

impl !Sync for Linker

§

impl Unpin for Linker

§

impl UnwindSafe for Linker

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.