Class: Rubycc::ObjFile::ELFWriter::RelocDesc

Inherits:
Data
  • Object
show all
Defined in:
lib/rubycc/objfile/elf_writer.rb

Overview

Machine description: the injected, target-specific half of the writer. It pairs the ELF e_machine value with a table translating each machine-independent relocation kind (the vocabulary the backend records — :call/:func/:string/:global/:got in .text, :symbol/:rodata in .data) into that target's ELF relocation entries.

A kind maps to an array of RelocDesc, not a single one, because how many ELF entries one source-level reference costs is a property of the machine. x86_64 forms an address in a single instruction with a single patched field, so every kind is a one-element array; aarch64 needs two instructions (adrp + add, or adrp + ldr) with a relocation apiece, so its address-forming kinds are two-element arrays. The writer simply emits each descriptor in order.

Within a descriptor: type is the concrete ELF relocation type (an R__* number). addend is either a fixed value or :recorded, meaning the relocation record carries its own addend. addend_bias is added on top of it and is where a target's field-placement convention lives — x86_64's PC-relative fields are measured from the end of the instruction, so a rel32 whose four bytes precede that end needs -4, while aarch64's adrp/add pair is biased by nothing. Keeping the bias here, and not in the caller, lets the compiler hand over a plain unbiased byte offset in the machine-independent vocabulary. offset_delta is the byte distance from the offset the backend recorded (always the first instruction of the sequence) to the field this descriptor patches: 0 and 4 for an aarch64 pair, 0 everywhere on x86_64. symbol is :named to resolve against the relocation's own symbol or :rodata_section to resolve against the .rodata section symbol.

text_padding is the filler the compiler repeats in the alignment gap between two functions — a no-op encoding of the target, so the gap disassembles cleanly and a stray fall-through lands on nothing harmful. Retargeting the writer is a matter of injecting a different MachineDescription — the section layout and symbol-table logic below is machine-independent.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addend_bias: 0, offset_delta: 0, **rest) ⇒ RelocDesc

Returns a new instance of RelocDesc.



163
164
165
# File 'lib/rubycc/objfile/elf_writer.rb', line 163

def initialize(addend_bias: 0, offset_delta: 0, **rest)
  super
end

Instance Attribute Details

#addendObject (readonly)

Returns the value of attribute addend

Returns:

  • (Object)

    the current value of addend



162
163
164
# File 'lib/rubycc/objfile/elf_writer.rb', line 162

def addend
  @addend
end

#addend_biasObject (readonly)

Returns the value of attribute addend_bias

Returns:

  • (Object)

    the current value of addend_bias



162
163
164
# File 'lib/rubycc/objfile/elf_writer.rb', line 162

def addend_bias
  @addend_bias
end

#offset_deltaObject (readonly)

Returns the value of attribute offset_delta

Returns:

  • (Object)

    the current value of offset_delta



162
163
164
# File 'lib/rubycc/objfile/elf_writer.rb', line 162

def offset_delta
  @offset_delta
end

#symbolObject (readonly)

Returns the value of attribute symbol

Returns:

  • (Object)

    the current value of symbol



162
163
164
# File 'lib/rubycc/objfile/elf_writer.rb', line 162

def symbol
  @symbol
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



162
163
164
# File 'lib/rubycc/objfile/elf_writer.rb', line 162

def type
  @type
end