Class: ELFTools::Sections::RelativeRelocationSection

Inherits:
Section
  • Object
show all
Defined in:
lib/elftools/sections/relative_relocation_section.rb

Overview

Class of the section packing the relocations that only add the load bias.

This section is usually named .relr.dyn, and records the very relocations the DT_RELR tag points at.

Instance Attribute Summary

Attributes inherited from Section

#header, #stream

Instance Method Summary collapse

Methods inherited from Section

#allocated?, create, #data, #executable?, #name, #null?, #type, #writable?

Constructor Details

#initialize(header, stream, machine: nil, **_kwargs) ⇒ RelativeRelocationSection

Parameters:

  • header (ELFTools::Structs::ELF_Shdr)

    See Section#initialize for more information.

  • stream (#pos=, #read)

    See Section#initialize for more information.

  • machine (Integer) (defaults to: nil)

    The machine of the ELF file, which decides what these relocations are of. This should be e_machine of the ELF header.



21
22
23
24
# File 'lib/elftools/sections/relative_relocation_section.rb', line 21

def initialize(header, stream, machine: nil, **_kwargs)
  @machine = machine
  super
end

Instance Method Details

#num_relocationsInteger

How many relocations the section packs.

Returns:

  • (Integer)

    The number.



41
42
43
# File 'lib/elftools/sections/relative_relocation_section.rb', line 41

def num_relocations
  relocations.size
end

#relocationsArray<ELFTools::Relocation>

The relocations the section packs.

Examples:

section.relocations.map(&:type_name).uniq
#=> ['R_X86_64_RELATIVE']

Returns:

  • (Array<ELFTools::Relocation>)

    The relocations, in the ascending order the section records them.



32
33
34
35
36
37
# File 'lib/elftools/sections/relative_relocation_section.rb', line 32

def relocations
  @relocations ||= RelativeRelocations.new(
    stream, header.sh_offset.to_i...(header.sh_offset.to_i + header.sh_size.to_i),
    elf_class: header.elf_class, endian: header.class.self_endian, machine: @machine
  ).to_a
end