jon.recoil.org

Module Form_rewrite_plan

Form a rewrite plan for ELF section rewriting.

This module analyzes the input ELF file and builds a plan describing all the modifications needed: new sections, relocated symbols, and file layout. The plan can then be executed by Rewrite_sections.

module Symbol_entry : sig ... end

Information about an original symbol from the ELF symbol table.

module Section_layout : sig ... end

Layout of a section in the output file.

module Layout : sig ... end

Layout of all sections in the output file.

module Rewritten_rela_section : sig ... end

Rewritten relocation entries for a single .rela.text* section.

type t

A rewrite plan for an ELF file.

Returns the original symbols from the input file's symbol table.

val symbol_to_index : Form_rewrite_plan.t -> int Misc.Stdlib.String.Tbl.t

Returns a map from symbol name to index in the output symbol table.

val total_symbols : Form_rewrite_plan.t -> int

Returns the total number of symbols in the output symbol table.

Returns the list of rewritten .rela.text* sections, each with their original file offset and rewritten entries.

val strtab : Form_rewrite_plan.t -> Compiler_owee.Owee_elf_string_table.t

Returns the string table for symbol names.

val shstrtab : Form_rewrite_plan.t -> Compiler_owee.Owee_elf_string_table.t

Returns the section header string table.

val section_name_offsets : Form_rewrite_plan.t -> (int * string) Misc.Stdlib.String.Tbl.t

Returns a map from original section names to (offset, renamed_name) pairs in shstrtab. For Large_code partitions, the stored values point to the renamed name (e.g., .caml.p1.text instead of .text).

val igot_name_offset : Form_rewrite_plan.t -> int

Returns the offset of the IGOT section name in shstrtab.

val igot_name_str : Form_rewrite_plan.t -> string

Returns the IGOT section name string.

val rela_igot_name_offset : Form_rewrite_plan.t -> int

Returns the offset of the .rela.igot section name in shstrtab.

val rela_igot_name_str : Form_rewrite_plan.t -> string

Returns the .rela.igot section name string.

val iplt_name_offset : Form_rewrite_plan.t -> int

Returns the offset of the IPLT section name in shstrtab.

val iplt_name_str : Form_rewrite_plan.t -> string

Returns the IPLT section name string.

val rela_iplt_name_offset : Form_rewrite_plan.t -> int

Returns the offset of the .rela.iplt section name in shstrtab.

val rela_iplt_name_str : Form_rewrite_plan.t -> string

Returns the .rela.iplt section name string.

val igot_idx : Form_rewrite_plan.t -> int

Returns the section index of the IGOT section.

val rela_igot_idx : Form_rewrite_plan.t -> int

Returns the section index of the .rela.igot section.

val iplt_idx : Form_rewrite_plan.t -> int

Returns the section index of the IPLT section.

val rela_iplt_idx : Form_rewrite_plan.t -> int

Returns the section index of the .rela.iplt section.

val num_sections : Form_rewrite_plan.t -> int

Returns the total number of sections in the output file.

val symtab_idx : Form_rewrite_plan.t -> int

Returns the section index of the symbol table.

val symtab_shndx_idx : Form_rewrite_plan.t -> int option

Returns the index of the SYMTAB_SHNDX section in the input file.

val new_symtab_shndx_idx : Form_rewrite_plan.t -> int option

Returns the index of a newly created SYMTAB_SHNDX section, if one needs to be created because the input lacks one but new indices >= SHN_LORESERVE.

val symtab_shndx_name_offset : Form_rewrite_plan.t -> int option

Returns the name offset in shstrtab for a new SYMTAB_SHNDX section.

Returns the layout of all sections in the output file.

val compute : header:Compiler_owee.Owee_elf.header -> sections:Compiler_owee.Owee_elf.section array -> symtab_body:Compiler_owee.Owee_buf.t -> strtab_body:Compiler_owee.Owee_buf.t -> rela_text_sections: (Compiler_owee.Owee_elf.section * Compiler_owee.Owee_buf.t) list -> partition_kind:Partition.kind -> igot_and_iplt:Build_igot_and_iplt.t -> relocations:Extract_relocations.t -> Form_rewrite_plan.t

compute ~header ~sections ~symtab_body ~strtab_body ~rela_text_sections ~partition_kind ~igot_and_iplt ~relocations analyzes the ELF structure and builds a rewrite plan.

rela_text_sections is a list of (section, body) pairs for all .rela.text* sections in the input file. This handles both traditional single .rela.text sections and function sections (.rela.text.foo, .rela.text.bar, etc.).

For Large_code partitions, section names are renamed with a prefix (e.g., .text -> .caml.p1.text).