Skip to main content

Fragment

Enum Fragment 

Source
pub enum Fragment {
    Fixed {
        bytes: FragmentBytes,
        relocation: Option<Relocation>,
        span: Span,
    },
    Align {
        alignment: u32,
        fill: u8,
        max_skip: Option<u32>,
        use_nop: bool,
        span: Span,
    },
    Relaxable {
        short_bytes: InstrBytes,
        short_reloc_offset: usize,
        short_relocation: Option<Relocation>,
        long_bytes: InstrBytes,
        long_relocation: Relocation,
        is_long: bool,
        span: Span,
    },
    Org {
        target: u64,
        fill: u8,
        span: Span,
    },
}
Expand description

A fragment of assembled output.

The linker operates on an ordered list of fragments. During branch relaxation the sizes of Fragment::Relaxable and Fragment::Align fragments may change, but they only ever grow (monotonic), which guarantees convergence.

Variants§

§

Fixed

Fixed-size bytes with optional relocation.

Fields

§bytes: FragmentBytes

The raw assembled bytes (inline for instructions, heap for large data).

§relocation: Option<Relocation>

Optional relocation to apply to these bytes.

§span: Span

Source span of the originating instruction or directive.

§

Align

Alignment padding — size depends on preceding layout.

When use_nop is true (x86/x86-64 code alignment with no explicit fill byte), pad with Intel-recommended multi-byte NOP sequences instead of repeating a single fill byte.

Fields

§alignment: u32

Required byte alignment (must be a power of two).

§fill: u8

Byte value used for padding when use_nop is false.

§max_skip: Option<u32>

If set, skip this alignment entirely when the required padding exceeds this many bytes.

§use_nop: bool

Use multi-byte NOP sequences instead of repeating fill.

§span: Span

Source span of the alignment directive.

§

Relaxable

A relaxable branch instruction.

Starts in short form (rel8). If the linker determines the target is beyond ±127 bytes it promotes to the long form (rel32) and re-lays out. Promotion is irreversible (Szymanski monotonic growth).

Fields

§short_bytes: InstrBytes

Short-form bytes (e.g. [0xEB, 0x00] for JMP rel8).

§short_reloc_offset: usize

Offset of the rel8 displacement within short_bytes.

§short_relocation: Option<Relocation>

Optional relocation for the short form. When Some, the linker applies this relocation to short_bytes instead of raw byte-patching. Used for RISC-V B-type branches.

§long_bytes: InstrBytes

Long-form bytes (e.g. [0xE9, 0,0,0,0] for JMP rel32).

§long_relocation: Relocation

Relocation for the long form (contains label, offset, etc.).

§is_long: bool

Whether this fragment has been promoted to long form.

§span: Span

Source span.

§

Org

Advance the location counter to an absolute address, padding with fill bytes. If the target is behind the current position, an error is raised during emission.

Fields

§target: u64

Absolute target address for the location counter.

§fill: u8

Byte value used to fill the gap.

§span: Span

Source span of the .org directive.

Trait Implementations§

Source§

impl Clone for Fragment

Source§

fn clone(&self) -> Fragment

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Fragment

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.