Class: Rubycc::ObjFile::ELFWriter::RelocDesc
- Inherits:
-
Data
- Object
- Data
- Rubycc::ObjFile::ELFWriter::RelocDesc
- 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_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
-
#addend ⇒ Object
readonly
Returns the value of attribute addend.
-
#addend_bias ⇒ Object
readonly
Returns the value of attribute addend_bias.
-
#offset_delta ⇒ Object
readonly
Returns the value of attribute offset_delta.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(addend_bias: 0, offset_delta: 0, **rest) ⇒ RelocDesc
constructor
A new instance of RelocDesc.
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
#addend ⇒ Object (readonly)
Returns the value of attribute addend
162 163 164 |
# File 'lib/rubycc/objfile/elf_writer.rb', line 162 def addend @addend end |
#addend_bias ⇒ Object (readonly)
Returns the value of attribute addend_bias
162 163 164 |
# File 'lib/rubycc/objfile/elf_writer.rb', line 162 def addend_bias @addend_bias end |
#offset_delta ⇒ Object (readonly)
Returns the value of attribute offset_delta
162 163 164 |
# File 'lib/rubycc/objfile/elf_writer.rb', line 162 def offset_delta @offset_delta end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol
162 163 164 |
# File 'lib/rubycc/objfile/elf_writer.rb', line 162 def symbol @symbol end |
#type ⇒ Object (readonly)
Returns the value of attribute type
162 163 164 |
# File 'lib/rubycc/objfile/elf_writer.rb', line 162 def type @type end |