Class: Rubycc::Link::PartialLinker::Merger

Inherits:
Object
  • Object
show all
Includes:
ObjFile
Defined in:
lib/rubycc/link/partial_linker.rb

Overview

Merges the selected objects into one ET_REL image. Kept as an inner class so the phase-2 state (placement maps, the output symbol table, the per-object symbol remaps) stays isolated from the selection driver.

Constant Summary collapse

SHT_NOBITS =
PartialLinker::SHT_NOBITS
SHN_ABS =
PartialLinker::SHN_ABS

Constants included from ObjFile

ObjFile::AR_MAGIC

Instance Method Summary collapse

Constructor Details

#initialize(included) ⇒ Merger

Returns a new instance of Merger.



285
286
287
288
289
290
291
292
293
294
# File 'lib/rubycc/link/partial_linker.rb', line 285

def initialize(included)
  @objects = included # [{reader:, label:}]
  # The merged object keeps the inputs' architecture: the merge is
  # machine-independent (section concatenation and numeric-type relocation
  # retargeting), but the output header must carry the right e_machine so
  # the final linker that reads it back can pick the target's relocation
  # and crt logic. Empty inputs default to x86_64 through RelocatableWriter.
  machine = included.first&.dig(:reader)&.machine
  @writer = machine ? RelocatableWriter.new(machine: machine) : RelocatableWriter.new
end

Instance Method Details

#runObject



296
297
298
299
300
301
# File 'lib/rubycc/link/partial_linker.rb', line 296

def run
  merge_sections
  resolve_symbols
  retarget_relocations
  @writer.to_binary
end