pub trait MachInstLabelUse: Clone + Copy + Debug + Eq {
    const ALIGN: CodeOffset;

    fn max_pos_range(self) -> CodeOffset;
fn max_neg_range(self) -> CodeOffset;
fn patch_size(self) -> CodeOffset;
fn patch(
        self,
        buffer: &mut [u8],
        use_offset: CodeOffset,
        label_offset: CodeOffset
    );
fn supports_veneer(self) -> bool;
fn veneer_size(self) -> CodeOffset;
fn generate_veneer(
        self,
        buffer: &mut [u8],
        veneer_offset: CodeOffset
    ) -> (CodeOffset, Self); }
Expand description

A descriptor of a label reference (use) in an instruction set.

Associated Constants

Required alignment for any veneer. Usually the required instruction alignment (e.g., 4 for a RISC with 32-bit instructions, or 1 for x86).

Required methods

What is the maximum PC-relative range (positive)? E.g., if 1024, a label-reference fixup at offset x is valid if the label resolves to `x

  • 1024`.

What is the maximum PC-relative range (negative)? This is the absolute value; i.e., if 1024, then a label-reference fixup at offset x is valid if the label resolves to x - 1024.

What is the size of code-buffer slice this label-use needs to patch in the label’s value?

Perform a code-patch, given the offset into the buffer of this label use and the offset into the buffer of the label’s definition. It is guaranteed that, given delta = offset - label_offset, we will have offset >= -self.max_neg_range() and offset <= self.max_pos_range().

Can the label-use be patched to a veneer that supports a longer range? Usually valid for jumps (a short-range jump can jump to a longer-range jump), but not for e.g. constant pool references, because the constant load would require different code (one more level of indirection).

How many bytes are needed for a veneer?

Generate a veneer. The given code-buffer slice is self.veneer_size() bytes long at offset veneer_offset in the buffer. The original label-use will be patched to refer to this veneer’s offset. A new (offset, LabelUse) is returned that allows the veneer to use the actual label. For veneers to work properly, it is expected that the new veneer has a larger range; on most platforms this probably means either a “long-range jump” (e.g., on ARM, the 26-bit form), or if already at that stage, a jump that supports a full 32-bit range, for example.

Implementors