pub struct Linker { /* private fields */ }Expand description
The linker: collects fragments and labels, resolves everything.
Implementations§
Source§impl Linker
impl Linker
Sourcepub fn set_base_address(&mut self, addr: u64)
pub fn set_base_address(&mut self, addr: u64)
Set the base (origin) address for the assembled output.
Sourcepub fn base_address(&self) -> u64
pub fn base_address(&self) -> u64
Get the base address.
Sourcepub fn fragment_count(&self) -> usize
pub fn fragment_count(&self) -> usize
The number of fragments currently added.
Sourcepub fn define_external(&mut self, name: &str, addr: u64)
pub fn define_external(&mut self, name: &str, addr: u64)
Define an external label at a known absolute address.
Sourcepub fn define_constant(&mut self, name: &str, value: i128)
pub fn define_constant(&mut self, name: &str, value: i128)
Define a constant value (.equ / .set).
Sourcepub fn get_constant(&self, name: &str) -> Option<&i128>
pub fn get_constant(&self, name: &str) -> Option<&i128>
Look up a constant value by name.
Sourcepub fn add_label(&mut self, name: &str, span: Span) -> Result<(), AsmError>
pub fn add_label(&mut self, name: &str, span: Span) -> Result<(), AsmError>
Add a label definition at the current position (before the next fragment).
Sourcepub fn add_fragment(&mut self, fragment: Fragment)
pub fn add_fragment(&mut self, fragment: Fragment)
Add a pre-built fragment.
Sourcepub fn add_bytes(&mut self, bytes: Vec<u8>, span: Span)
pub fn add_bytes(&mut self, bytes: Vec<u8>, span: Span)
Convenience: add fixed bytes (data, non-branch instructions, etc.).
Sourcepub fn add_encoded(
&mut self,
bytes: InstrBytes,
relocation: Option<Relocation>,
relax: Option<RelaxInfo>,
span: Span,
) -> Result<(), AsmError>
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.
Sourcepub fn add_alignment(
&mut self,
alignment: u32,
fill: u8,
max_skip: Option<u32>,
use_nop: bool,
span: Span,
)
pub fn add_alignment( &mut self, alignment: u32, fill: u8, max_skip: Option<u32>, use_nop: bool, span: Span, )
Add alignment padding.
Sourcepub fn add_org(&mut self, target: u64, fill: u8, span: Span)
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.
Sourcepub fn resolve(
&mut self,
) -> Result<(Vec<u8>, Vec<(String, u64)>, Vec<AppliedRelocation>, Vec<u64>), AsmError>
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.