jon.recoil.org

Module Rewrite_sections

Rewrite ELF sections for the dissector.

This module rewrites a partially-linked object file to add IGOT and IPLT sections, their associated relocation sections, and rewrites the .rela.text section to redirect PLT32 and GOTPCRELX relocations through the IGOT/IPLT.

For Large_code partitions, sections are also renamed with a prefix (e.g., .text -> .caml.p1.text) so the linker script can place them at higher addresses.

The transformation adds:

val rewrite : (module Compiler_owee.Unix_intf.S) -> input_file:string -> output_file:string -> partition_kind:Partition.kind -> igot_and_iplt:Build_igot_and_iplt.t -> relocations:Extract_relocations.t -> unit

rewrite unix ~input_file ~output_file ~partition_kind ~igot_and_iplt ~relocations reads the ELF object file at input_file, adds IGOT and IPLT sections, rewrites relocations, and writes the result to output_file.

For Large_code partitions, section names are also prefixed (e.g., .text -> .caml.p1.text). Main partition sections keep their original names.

  • parameter unix

    First-class Unix module for file operations

  • parameter input_file

    Path to the input partially-linked object file

  • parameter output_file

    Path to write the rewritten object file

  • parameter partition_kind

    The kind of partition (Main or Large_code)

  • parameter igot_and_iplt

    The IGOT and IPLT structures to add

  • parameter relocations

    The extracted relocations identifying which entries need rewriting