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 ... endInformation about an original symbol from the ELF symbol table.
module Section_layout : sig ... endLayout of a section in the output file.
module Layout : sig ... endLayout of all sections in the output file.
module Rewritten_rela_section : sig ... endRewritten relocation entries for a single .rela.text* section.
val original_symbols :
Form_rewrite_plan.t ->
Form_rewrite_plan.Symbol_entry.t arrayReturns the original symbols from the input file's symbol table.
val symbol_to_index : Form_rewrite_plan.t -> int Misc.Stdlib.String.Tbl.tReturns a map from symbol name to index in the output symbol table.
val total_symbols : Form_rewrite_plan.t -> intReturns the total number of symbols in the output symbol table.
val rewritten_rela_sections :
Form_rewrite_plan.t ->
Form_rewrite_plan.Rewritten_rela_section.t listReturns 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.tReturns the string table for symbol names.
val shstrtab : Form_rewrite_plan.t -> Compiler_owee.Owee_elf_string_table.tReturns the section header string table.
val section_name_offsets :
Form_rewrite_plan.t ->
(int * string) Misc.Stdlib.String.Tbl.tReturns 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 -> intReturns the offset of the IGOT section name in shstrtab.
val igot_name_str : Form_rewrite_plan.t -> stringReturns the IGOT section name string.
val rela_igot_name_offset : Form_rewrite_plan.t -> intReturns the offset of the .rela.igot section name in shstrtab.
val rela_igot_name_str : Form_rewrite_plan.t -> stringReturns the .rela.igot section name string.
val iplt_name_offset : Form_rewrite_plan.t -> intReturns the offset of the IPLT section name in shstrtab.
val iplt_name_str : Form_rewrite_plan.t -> stringReturns the IPLT section name string.
val rela_iplt_name_offset : Form_rewrite_plan.t -> intReturns the offset of the .rela.iplt section name in shstrtab.
val rela_iplt_name_str : Form_rewrite_plan.t -> stringReturns the .rela.iplt section name string.
val igot_idx : Form_rewrite_plan.t -> intReturns the section index of the IGOT section.
val rela_igot_idx : Form_rewrite_plan.t -> intReturns the section index of the .rela.igot section.
val iplt_idx : Form_rewrite_plan.t -> intReturns the section index of the IPLT section.
val rela_iplt_idx : Form_rewrite_plan.t -> intReturns the section index of the .rela.iplt section.
val num_sections : Form_rewrite_plan.t -> intReturns the total number of sections in the output file.
val symtab_idx : Form_rewrite_plan.t -> intReturns the section index of the symbol table.
val symtab_shndx_idx : Form_rewrite_plan.t -> int optionReturns the index of the SYMTAB_SHNDX section in the input file.
val new_symtab_shndx_idx : Form_rewrite_plan.t -> int optionReturns 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 optionReturns the name offset in shstrtab for a new SYMTAB_SHNDX section.
val layout : Form_rewrite_plan.t -> Form_rewrite_plan.Layout.tReturns 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.tcompute ~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).