package object

  1. Overview
  2. Docs

Module ElfSource

Linux ELF parser based on /usr/include/elf.h

Sourcetype elf_class = [
  1. | `ELFCLASSNONE
    (*

    Invalid class

    *)
  2. | `ELFCLASS32
    (*

    32-bit objects

    *)
  3. | `ELFCLASS64
    (*

    64-bit objects

    *)
]

ELF file class indicating the architecture word size. Determines the size of addresses and offsets throughout the ELF file format.

Sourcetype elf_data = [
  1. | `ELFDATANONE
    (*

    Invalid data encoding

    *)
  2. | `ELFDATA2LSB
    (*

    2's complement, little endian

    *)
  3. | `ELFDATA2MSB
    (*

    2's complement, big endian

    *)
]

ELF data encoding specifying the byte order used for multi-byte values within the ELF file. Affects interpretation of all integers and addresses in the file.

Sourcetype elf_osabi = [
  1. | `ELFOSABI_NONE
    (*

    UNIX System V ABI

    *)
  2. | `ELFOSABI_SYSV
    (*

    Alias for ELFOSABI_NONE

    *)
  3. | `ELFOSABI_HPUX
    (*

    HP-UX

    *)
  4. | `ELFOSABI_NETBSD
    (*

    NetBSD

    *)
  5. | `ELFOSABI_GNU
    (*

    Object uses GNU ELF extensions

    *)
  6. | `ELFOSABI_LINUX
    (*

    Compatibility alias for GNU

    *)
  7. | `ELFOSABI_SOLARIS
    (*

    Sun Solaris

    *)
  8. | `ELFOSABI_AIX
    (*

    IBM AIX

    *)
  9. | `ELFOSABI_IRIX
    (*

    SGI Irix

    *)
  10. | `ELFOSABI_FREEBSD
    (*

    FreeBSD

    *)
  11. | `ELFOSABI_TRU64
    (*

    Compaq TRU64 UNIX

    *)
  12. | `ELFOSABI_MODESTO
    (*

    Novell Modesto

    *)
  13. | `ELFOSABI_OPENBSD
    (*

    OpenBSD

    *)
  14. | `ELFOSABI_ARM_AEABI
    (*

    ARM EABI

    *)
  15. | `ELFOSABI_ARM
    (*

    ARM

    *)
  16. | `ELFOSABI_STANDALONE
    (*

    Standalone (embedded) application

    *)
  17. | `ELFOSABI_UNKNOWN of int
    (*

    Unknown OS ABI

    *)
]

ELF OS/ABI identification specifying the target operating system and ABI. Indicates which OS-specific extensions and conventions are used in the ELF file.

Sourcetype elf_type = [
  1. | `ET_NONE
    (*

    No file type

    *)
  2. | `ET_REL
    (*

    Relocatable file

    *)
  3. | `ET_EXEC
    (*

    Executable file

    *)
  4. | `ET_DYN
    (*

    Shared object file

    *)
  5. | `ET_CORE
    (*

    Core file

    *)
  6. | `ET_LOOS
    (*

    OS-specific range start

    *)
  7. | `ET_HIOS
    (*

    OS-specific range end

    *)
  8. | `ET_LOPROC
    (*

    Processor-specific range start

    *)
  9. | `ET_HIPROC
    (*

    Processor-specific range end

    *)
  10. | `ET_UNKNOWN of int
    (*

    Unknown file type

    *)
]

ELF file type indicating the purpose and format of the ELF file. Determines how the file should be processed - whether it's an intermediate object file for linking, a complete executable, a shared library, or a core dump.

Sourcetype elf_machine = [
  1. | `EM_NONE
    (*

    No machine

    *)
  2. | `EM_M32
    (*

    AT&T WE 32100

    *)
  3. | `EM_SPARC
    (*

    SUN SPARC

    *)
  4. | `EM_386
    (*

    Intel 80386

    *)
  5. | `EM_68K
    (*

    Motorola m68k family

    *)
  6. | `EM_88K
    (*

    Motorola m88k family

    *)
  7. | `EM_860
    (*

    Intel 80860

    *)
  8. | `EM_MIPS
    (*

    MIPS R3000 big-endian

    *)
  9. | `EM_S370
    (*

    IBM System/370

    *)
  10. | `EM_MIPS_RS3_LE
    (*

    MIPS R3000 little-endian

    *)
  11. | `EM_PARISC
    (*

    HPPA

    *)
  12. | `EM_VPP500
    (*

    Fujitsu VPP500

    *)
  13. | `EM_SPARC32PLUS
    (*

    Sun's "v8plus"

    *)
  14. | `EM_960
    (*

    Intel 80960

    *)
  15. | `EM_PPC
    (*

    PowerPC

    *)
  16. | `EM_PPC64
    (*

    PowerPC 64-bit

    *)
  17. | `EM_S390
    (*

    IBM S390

    *)
  18. | `EM_ARM
    (*

    ARM

    *)
  19. | `EM_SH
    (*

    Hitachi SH

    *)
  20. | `EM_SPARCV9
    (*

    SPARC v9 64-bit

    *)
  21. | `EM_IA_64
    (*

    Intel Merced

    *)
  22. | `EM_X86_64
    (*

    AMD x86-64 architecture

    *)
  23. | `EM_AARCH64
    (*

    ARM AARCH64

    *)
  24. | `EM_RISCV
  25. | `EM_UNKNOWN of int
    (*

    Unknown machine type

    *)
]

ELF target machine architecture specification. Indicates the required architecture for the ELF file, determining instruction set compatibility and execution requirements. This field ensures that the file can only be executed on systems with compatible processor architectures.

Sourcetype identification = {
  1. elf_class : elf_class;
    (*

    Object file class (32-bit, 64-bit, etc.)

    *)
  2. elf_data : elf_data;
    (*

    Data encoding (little-endian, big-endian)

    *)
  3. elf_version : Object_types.u8;
    (*

    ELF header version (must be 1)

    *)
  4. elf_osabi : elf_osabi;
    (*

    Operating system/ABI identification

    *)
  5. elf_abiversion : Object_types.u8;
    (*

    ABI version

    *)
}

ELF identification structure from the e_ident field. Contains basic file format information including architecture class, byte order, and target operating system ABI. This is parsed from the first 16 bytes of an ELF file.

Sourcetype header = {
  1. e_ident : identification;
    (*

    ELF identification and magic number

    *)
  2. e_type : elf_type;
    (*

    Object file type (executable, shared lib, relocatable, core)

    *)
  3. e_machine : elf_machine;
    (*

    Target architecture (e.g., EM_X86_64 for x64)

    *)
  4. e_version : Object_types.u32;
    (*

    ELF version (must be 1)

    *)
  5. e_entry : Object_types.u64;
    (*

    Program entry point virtual address

    *)
  6. e_phoff : Object_types.u64;
    (*

    Program header table file offset

    *)
  7. e_shoff : Object_types.u64;
    (*

    Section header table file offset

    *)
  8. e_flags : Object_types.u32;
    (*

    Processor-specific flags

    *)
  9. e_ehsize : Object_types.u16;
    (*

    ELF header size in bytes

    *)
  10. e_phentsize : Object_types.u16;
    (*

    Size of a program header table entry

    *)
  11. e_phnum : Object_types.u16;
    (*

    Number of entries in program header table

    *)
  12. e_shentsize : Object_types.u16;
    (*

    Size of a section header table entry

    *)
  13. e_shnum : Object_types.u16;
    (*

    Number of entries in section header table

    *)
  14. e_shstrndx : Object_types.u16;
    (*

    Section header string table index

    *)
}

ELF header structure containing essential file metadata. This is the first structure in an ELF file and provides information needed to interpret the rest of the file, including table locations, entry points, and architecture details.

Sourcetype section_type = [
  1. | `SHT_NULL
    (*

    Section header table entry is unused.

    *)
  2. | `SHT_PROGBITS
    (*

    Program data.

    *)
  3. | `SHT_SYMTAB
    (*

    Symbol table.

    *)
  4. | `SHT_STRTAB
    (*

    String table.

    *)
  5. | `SHT_RELA
    (*

    Relocation entries with explicit addends.

    *)
  6. | `SHT_HASH
    (*

    Symbol hash table.

    *)
  7. | `SHT_DYNAMIC
    (*

    Dynamic linking information.

    *)
  8. | `SHT_NOTE
    (*

    Notes.

    *)
  9. | `SHT_NOBITS
    (*

    Program space with no data (bss).

    *)
  10. | `SHT_REL
    (*

    Relocation entries without explicit addends.

    *)
  11. | `SHT_SHLIB
    (*

    Reserved section type.

    *)
  12. | `SHT_DYNSYM
    (*

    Dynamic linker symbol table.

    *)
  13. | `SHT_INIT_ARRAY
    (*

    Array of constructors.

    *)
  14. | `SHT_FINI_ARRAY
    (*

    Array of destructors.

    *)
  15. | `SHT_PREINIT_ARRAY
    (*

    Array of pre-constructors.

    *)
  16. | `SHT_GROUP
    (*

    Section group.

    *)
  17. | `SHT_SYMTAB_SHNDX
    (*

    Extended section indices for a symbol table.

    *)
  18. | `SHT_RELR
    (*

    Relocation entries; only offsets.

    *)
  19. | `SHT_LOOS
    (*

    Start of OS-specific section types.

    *)
  20. | `SHT_LLVM_DEPENDENT_LIBRARIES
    (*

    LLVM-style dependent libraries.

    *)
  21. | `SHT_GNU_ATTRIBUTES
    (*

    Object attributes

    *)
  22. | `SHT_GNU_HASH
    (*

    GNU-style hash table.

    *)
  23. | `SHT_GNU_LIBLIST
    (*

    Prelink library list.

    *)
  24. | `SHT_CHECKSUM
    (*

    Checksum for DSO content.

    *)
  25. | `SHT_LOSUNW
    (*

    Sun-specific low bound.

    *)
  26. | `SHT_SUNW_move
  27. | `SHT_SUNW_COMDAT
  28. | `SHT_SUNW_syminfo
  29. | `SHT_GNU_VERDEF
    (*

    Version definition section.

    *)
  30. | `SHT_GNU_VERNEED
    (*

    Version needs section.

    *)
  31. | `SHT_GNU_VERSYM
    (*

    Version symbol table.

    *)
  32. | `SHT_HISUNW
    (*

    Sun-specific high bound.

    *)
  33. | `SHT_HIOS
    (*

    End of OS-specific section types.

    *)
  34. | `SHT_LOPROC
    (*

    Start of processor-specific section types.

    *)
  35. | `SHT_HIPROC
    (*

    End of processor-specific section types.

    *)
  36. | `SHT_LOUSER
    (*

    Start of application-specific section types.

    *)
  37. | `SHT_HIUSER
    (*

    End of application-specific section types.

    *)
]

ELF section type classification. Identifies the specific purpose and format of section contents, enabling proper interpretation by linkers, loaders, and debuggers. Different section types require different processing during linking and program loading.

Sourcetype section_flags = [
  1. | `SHF_WRITE
    (*

    Writable

    *)
  2. | `SHF_ALLOC
    (*

    Occupies memory during execution

    *)
  3. | `SHF_EXECINSTR
    (*

    Executable

    *)
  4. | `SHF_MERGE
    (*

    Might be merged

    *)
  5. | `SHF_STRINGS
    (*

    Contains nul-terminated strings

    *)
  6. | `SHF_OS_NONCONFORMING
    (*

    Non-standard OS specific handling required

    *)
  7. | `SHF_GROUP
    (*

    Section is member of a group.

    *)
  8. | `SHF_TLS
    (*

    Section hold thread-local data.

    *)
  9. | `SHF_COMPRESSED
    (*

    Section with compressed data.

    *)
  10. | `SHF_MASKOS
    (*

    OS-specific.

    *)
  11. | `SHF_MASKPROC
    (*

    Processor-specific

    *)
  12. | `SHF_ORDERED
    (*

    Special ordering requirement (Solaris).

    *)
  13. | `SHF_EXCLUDE
    (*

    Section is excluded unless referenced or allocated (Solaris).

    *)
]

Values for section.sh_flags.

Sourcetype section = {
  1. sh_name : Object_types.u32;
    (*

    Section name as string table index

    *)
  2. sh_name_str : string;
    (*

    Section name as resolved string

    *)
  3. sh_type : Object_types.u32;
    (*

    Section type (code, data, symbol table, etc.)

    *)
  4. sh_flags : Object_types.u64;
    (*

    Section attributes (writable, executable, allocatable, etc.)

    *)
  5. sh_addr : Object_types.u64;
    (*

    Virtual address where section should be loaded

    *)
  6. sh_offset : Object_types.u64;
    (*

    File offset to section data

    *)
  7. sh_size : Object_types.u64;
    (*

    Section size in bytes

    *)
  8. sh_info : Object_types.u32;
    (*

    Additional section information (type-dependent)

    *)
  9. sh_addralign : Object_types.u64;
    (*

    Section alignment constraint

    *)
  10. sh_entsize : Object_types.u64;
    (*

    Size of entries if section contains a table

    *)
}

ELF section header describing a section within the file. Sections provide fine-grained organization of the file content for linking, debugging, and analysis. Each section has a specific type and set of attributes that determine how it should be processed.

Sourcetype program_type = [
  1. | `PT_NULL
    (*

    Program header table entry is unused.

    *)
  2. | `PT_LOAD
    (*

    Specifies a segment to load into memory at the given file address.

    *)
  3. | `PT_DYNAMIC
    (*

    Dynamic linking information.

    *)
  4. | `PT_INTERP
    (*

    Specifies the location and size of the path to the dynamic linker.

    *)
  5. | `PT_NOTE
    (*

    The location and size of auxiliary information about the binary.

    *)
  6. | `PT_SHLIB
    (*

    Reserved

    *)
  7. | `PT_PHDR
    (*

    Location to load the program headers

    *)
  8. | `PT_TLS
    (*

    Thread-local storage.

    *)
  9. | `PT_NUM
    (*

    Number of defined types

    *)
  10. | `PT_LOOS
    (*

    Start of OS-specific

    *)
  11. | `PT_GNU_EH_FRAME
    (*

    The stack unwinding information (points to the same memory as .eh_frame section).

    *)
  12. | `PT_GNU_STACK
    (*

    Indicates stack executability, specific to the Linux kernel

    *)
  13. | `PT_GNU_RELRO
    (*

    Read-only after relocation.

    *)
  14. | `PT_GNU_PROPERTY
    (*

    Special note with dynamic linker specific information (.note.gnu.property)

    *)
  15. | `PT_GNU_SFRAME
    (*

    SFrame segment.

    *)
  16. | `PT_LOSUNW
  17. | `PT_SUNWBSS
    (*

    Sun Specific segment

    *)
  18. | `PT_SUNWSTACK
    (*

    Stack segment

    *)
  19. | `PT_HISUNW
  20. | `PT_HIOS
    (*

    End of OS-specific

    *)
  21. | `PT_LOPROC
    (*

    Start of processor-specific

    *)
  22. | `PT_HIPROC
    (*

    End of processor-specific

    *)
]

Legal values for p_type field of program (segment type).

Sourcetype program_flags = [
  1. | `PF_X
    (*

    Segment is executable

    *)
  2. | `PF_W
    (*

    Segment is writable

    *)
  3. | `PF_R
    (*

    Segment is readable

    *)
  4. | `PF_RX
    (*

    Segment is readable and executable

    *)
  5. | `PF_RW
    (*

    Segment is readable and writable

    *)
  6. | `PF_WX
    (*

    Segment is writable and executable

    *)
  7. | `PF_RWX
    (*

    Segment is readable, writable and executable

    *)
  8. | `PF_MASKOS
    (*

    OS-specific

    *)
  9. | `PF_MASKPROC
    (*

    Processor-specific

    *)
]

ELF program segment permission flags. Defines access permissions for segments in memory during program execution. These flags control memory protection by specifying whether a segment can be read from, written to, or executed, enabling proper memory management and security.

Sourcetype program = {
  1. p_type : program_type;
    (*

    Segment type

    *)
  2. p_flags : program_flags;
    (*

    Segment flags

    *)
  3. p_offset : Object_types.u64;
    (*

    Segment file offset

    *)
  4. p_vaddr : Object_types.u64;
    (*

    Segment virtual address

    *)
  5. p_paddr : Object_types.u64;
    (*

    Segment physical address

    *)
  6. p_filesz : Object_types.u64;
    (*

    Segment size in file

    *)
  7. p_memsz : Object_types.u64;
    (*

    Segment size in memory

    *)
  8. p_align : Object_types.u64;
    (*

    Segment alignment

    *)
}

Program headers describe the segments of the program relevant to program loading.

What is the Auxiliary Vector?

The auxiliary vector (auxv) is a mechanism used by the Linux kernel and other Unix-like systems to pass system and program-specific information to user programs at startup. It consists of an array of key-value pairs containing essential data that programs and dynamic linkers need to function properly.

Purpose and Usage

The auxiliary vector serves several critical purposes:

  • Provides system information (page size, CPU features, security context)
  • Passes program metadata (entry point, program headers location)
  • Enables efficient dynamic linking without filesystem access
  • Allows secure communication of sensitive data (user/group IDs)
  • Supports performance optimizations by avoiding redundant system calls

Common auxiliary vector entries include:

  • AT_PAGESZ: System memory page size (typically 4096 bytes)
  • AT_PHDR: Memory address where program headers are loaded
  • AT_ENTRY: Program entry point address
  • AT_BASE: Base address of the dynamic linker/interpreter
  • AT_UID/AT_GID: Real user and group IDs for security context

Memory Location

The auxiliary vector can be accessed from two sources:

  • Memory: Located on the program stack above environment variables during startup
  • Filesystem: Available via /proc/<pid>/auxv for any running process

The exact memory location is platform-specific; consult the platform ELF ABI documents for details. See: https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf

The auxiliary vector is essential for program interpreters and dynamic linkers (such as /lib/ld-linux-x86-64.so.2) to bootstrap the dynamic linking process without requiring additional system calls to examine executable files.

Sourcetype entry_type = [
  1. | `AT_NULL
    (*

    End of vector

    *)
  2. | `AT_IGNORE
    (*

    Entry should be ignored

    *)
  3. | `AT_EXECFD
    (*

    File descriptor of program

    *)
  4. | `AT_PHDR
    (*

    Program headers for program

    *)
  5. | `AT_PHENT
    (*

    Size of program header entry

    *)
  6. | `AT_PHNUM
    (*

    Number of program headers

    *)
  7. | `AT_PAGESZ
    (*

    System page size

    *)
  8. | `AT_BASE
    (*

    Base address of interpreter

    *)
  9. | `AT_FLAGS
    (*

    Flags

    *)
  10. | `AT_ENTRY
    (*

    Entry point of program

    *)
  11. | `AT_NOTELF
    (*

    Program is not ELF

    *)
  12. | `AT_UID
    (*

    Real uid

    *)
  13. | `AT_EUID
    (*

    Effective uid

    *)
  14. | `AT_GID
    (*

    Real gid

    *)
  15. | `AT_EGID
    (*

    Effective gid

    *)
  16. | `AT_CLKTCK
    (*

    Frequency of times()

    *)
]

Auxiliary vector entry type identifiers. These constants define the different types of information that can be passed from the kernel to userspace programs through the auxiliary vector, including system parameters, program metadata, and security contexts.

Sourcetype auxiliary_vector = {
  1. a_type : entry_type;
    (*

    Entry type identifying what information this entry contains

    *)
  2. a_val : Object_types.u64;
    (*

    Value associated with the entry type

    *)
}

Auxiliary vector entry containing system information passed from kernel to user programs at startup. Each entry consists of a type identifier and an associated value (address, size, flags, etc.).

Sourceval read_elf : Buffer.t -> header * section array

read_elf buffer decodes the header and section table from a buffer pointing to an ELF image.

ELF Sections and Segments

ELF files organize their content using two overlapping but distinct structures: sections and segments. Understanding their relationship is crucial for working with ELF files effectively.

Sections vs Segments

Sections are used during linking and debugging:

  • Fine-grained organization of data and code
  • Each section has a specific purpose (code, data, symbols, strings, etc.)
  • Defined by the Section Header Table
  • Used by linkers, debuggers, and analysis tools
  • Can be stripped from executables to reduce size

Segments are used during program loading:

  • Coarse-grained organization for runtime loading
  • Group related sections together for efficient loading
  • Defined by the Program Header Table
  • Used by the OS loader and dynamic linker
  • Essential for program execution (cannot be stripped)

Memory Layout Relationship

ELF File Structure:
+------------------+
|   ELF Header     |  <- Points to both header tables
+------------------+
|  Program Headers |  <- Segments (for loading)
+------------------+
|                  |
|   File Content   |  <- Actual data/code
|                  |
+------------------+
| Section Headers  |  <- Sections (for linking/debug)
+------------------+

Segment-to-Section Mapping:
+----------------+     +------------------+
|    LOAD        |---->| .text (code)     |
|   Segment 1    |     | .rodata (const)  |
+----------------+     +------------------+
|    LOAD        |---->| .data (init var) |
|   Segment 2    |     | .bss (uninit var)|
+----------------+     +------------------+
|   DYNAMIC      |---->| .dynamic         |
+----------------+     +------------------+

Common Sections

  • .text: Executable code
  • .rodata: Read-only data (string literals, constants)
  • .data: Initialized global and static variables
  • .bss: Uninitialized global and static variables
  • .symtab: Static symbol table (for debugging)
  • .dynsym: Dynamic symbol table (for runtime linking)
  • .strtab/.dynstr: String tables for symbol names
  • .rel/.rela: Relocation information
  • .dynamic: Dynamic linking information

Common Segments

  • LOAD: Segments to be loaded into memory (typically .text, .data)
  • DYNAMIC: Dynamic linking information
  • INTERP: Path to program interpreter (dynamic linker)
  • NOTE: Auxiliary information (build ID, ABI notes)
  • GNU_STACK: Stack permissions and properties

Why Two Systems?

The dual organization serves different phases of a program's lifecycle:

  • Link time: Sections provide fine-grained control for combining object files
  • Load time: Segments provide efficient bulk loading with proper permissions
  • Debug time: Sections provide detailed symbol and debugging information
  • Strip time: Sections can be removed while preserving executable functionality
Sourceval read_programs : Buffer.t -> header -> program array

read_programs buffer header decodes the program headers from a buffer pointing to an ELF image.

Sourceval read_auxiliary_vector : Buffer.t -> auxiliary_vector list

read_auxiliary_vector buffer decodes the auxiliary vector from buffer.

Standard ELF Symbol Tables

ELF files contain standardized symbol tables as defined by the ELF specification and System V Application Binary Interface (ABI):

Static Symbol Table (.symtab)

  • Contains all symbols in the object file (local, global, debug information)
  • Used by debuggers, profilers, and development tools
  • Often stripped from release binaries to reduce file size
  • Uses read_symbol_table with ~symtab_name:".symtab"
  • Associated string table: .strtab

Dynamic Symbol Table (.dynsym)

  • Contains only symbols needed for dynamic linking at runtime
  • Always present in dynamically linked executables and shared libraries
  • Smaller subset focused on runtime symbol resolution
  • Cannot be stripped as it's required for program execution
  • Uses read_symbol_table with ~symtab_name:".dynsym"
  • Associated string table: .dynstr

Usage Examples

(* Read default symbol table (tries .symtab first, falls back to .dynsym) *)
let symbols = read_symbol_table buffer header sections

(* Read static symbols explicitly *)
let static_symbols =
  read_symbol_table ~symtab_name:".symtab" buffer header sections

(* Read dynamic symbols explicitly *)
let dynamic_symbols =
  read_symbol_table ~symtab_name:".dynsym" buffer header sections

ELF symbol table entry

Sourcetype symbol_binding = [
  1. | `STB_LOCAL
    (*

    Local symbol

    *)
  2. | `STB_GLOBAL
    (*

    Global symbol

    *)
  3. | `STB_WEAK
    (*

    Weak symbol

    *)
  4. | `STB_LOOS
    (*

    Start of OS-specific binding

    *)
  5. | `STB_HIOS
    (*

    End of OS-specific binding

    *)
  6. | `STB_LOPROC
    (*

    Start of processor-specific binding

    *)
  7. | `STB_HIPROC
    (*

    End of processor-specific binding

    *)
  8. | `STB_UNKNOWN of int
    (*

    Unknown binding

    *)
]

ELF symbol binding attributes. Defines the linkage visibility and behavior of symbols in the symbol table, controlling how symbols are resolved during linking. This determines whether symbols are local to the file, globally visible across modules, or have weak linkage semantics.

Sourcetype symbol_type = [
  1. | `STT_NOTYPE
    (*

    Symbol type is unspecified

    *)
  2. | `STT_OBJECT
    (*

    Symbol is a data object

    *)
  3. | `STT_FUNC
    (*

    Symbol is a code object

    *)
  4. | `STT_SECTION
    (*

    Symbol associated with a section

    *)
  5. | `STT_FILE
    (*

    Symbol's name is file name

    *)
  6. | `STT_COMMON
    (*

    Symbol is a common data object

    *)
  7. | `STT_TLS
    (*

    Symbol is thread-local data object

    *)
  8. | `STT_LOOS
    (*

    Start of OS-specific symbol types

    *)
  9. | `STT_HIOS
    (*

    End of OS-specific symbol types

    *)
  10. | `STT_LOPROC
    (*

    Start of processor-specific symbol types

    *)
  11. | `STT_HIPROC
    (*

    End of processor-specific symbol types

    *)
  12. | `STT_UNKNOWN of int
    (*

    Unknown type

    *)
]

ELF symbol type classification. Categorizes symbols by their nature and intended use, distinguishing between data objects, functions, sections, and special symbol types. This classification helps linkers and debuggers understand how to process and resolve different kinds of symbols.

Sourcetype symbol_visibility = [
  1. | `STV_DEFAULT
    (*

    Default visibility

    *)
  2. | `STV_INTERNAL
    (*

    Processor specific hidden class

    *)
  3. | `STV_HIDDEN
    (*

    Symbol unavailable to other modules

    *)
  4. | `STV_PROTECTED
    (*

    Not preemptible, not exported

    *)
  5. | `STV_UNKNOWN of int
    (*

    Unknown visibility

    *)
]

ELF symbol visibility attributes. Controls the visibility and preemption behavior of symbols during dynamic linking. This determines how symbols are exposed to other modules and whether they can be intercepted or overridden by definitions in other shared libraries.

Sourcetype symbol = {
  1. st_name : Object_types.u32;
    (*

    Symbol name string table index

    *)
  2. st_name_str : string;
    (*

    Symbol name

    *)
  3. st_info : Object_types.u8;
    (*

    Symbol binding and type

    *)
  4. st_other : Object_types.u8;
    (*

    Symbol visibility

    *)
  5. st_shndx : Object_types.u16;
    (*

    Section index

    *)
  6. st_value : Object_types.u64;
    (*

    Symbol value

    *)
  7. st_size : Object_types.u64;
    (*

    Symbol size

    *)
  8. st_binding : symbol_binding;
    (*

    Symbol binding

    *)
  9. st_type : symbol_type;
    (*

    Symbol type

    *)
  10. st_visibility : symbol_visibility;
    (*

    Symbol visibility

    *)
}

ELF symbol table entry. Represents a single symbol in the symbol table, containing all information needed to identify, locate, and link to the symbol. This includes both the raw ELF fields and parsed representations of binding, type, and visibility attributes.

Sourceval read_symbol_table : ?symtab_name:string -> Buffer.t -> header -> section array -> symbol array

read_symbol_table ?symtab_name buffer header sections reads symbol table from ELF file.

  • parameter symtab_name

    Optional symbol table section name to read from. Must be either ".symtab" (static symbol table) or ".dynsym" (dynamic symbol table). If not provided, defaults to trying ".symtab" first, then ".dynsym" as fallback. When ".dynsym" is specified, uses ".dynstr" as the string table; otherwise uses ".strtab".

  • parameter buffer

    The ELF file buffer

  • parameter header

    The ELF header

  • parameter sections

    Array of ELF sections

  • returns

    Array of symbols from the specified or default symbol table

Raises Failure if the specified symbol table or its corresponding string table is not found.

Sourceval read_section_contents : Buffer.t -> section array -> string -> Buffer.t option

read_section_contents buf section_name reads the section contents for section_name. Returns None if the section name is not found

Sourceval get_section_contents : Buffer.t -> string -> Buffer.t option

get_section_contents buffer section_name searches for a section with the given section_name in the ELF file and returns its contents as a buffer. Returns None if the section is not found.