From 521dac4e0d950e6128b266b27eac1875d79200f1 Mon Sep 17 00:00:00 2001 From: varobert Date: Thu, 10 May 2012 07:53:57 +0000 Subject: cchecklink now reads segments instead of sections cchecklink is now using program header information to figure out the initial address space of the program, rather than the information in the parent section of each symbol. This decouples the resolution of symbols from inaccurate section information, reflecting more the actual program loading. Additionally, a -relaxed option has been added to deal with some strange ELFs, for instance when symbols data is dynamically bootstrapped from another place by boot code different than the program loader. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1893 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- checklink/ELF_types.ml | 123 +++++++++++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 61 deletions(-) (limited to 'checklink/ELF_types.ml') diff --git a/checklink/ELF_types.ml b/checklink/ELF_types.ml index a6568ed..f67b91d 100644 --- a/checklink/ELF_types.ml +++ b/checklink/ELF_types.ml @@ -26,11 +26,11 @@ type ev = | EV_CURRENT | EV_UNKNOWN -type elf_identification = { - ei_class: elfclass; (* 32/64 bit *) - ei_data: elfdata; (* endianness *) - ei_version: ev; (* ELF header version *) -} +type elf_identification = + { ei_class : elfclass (* 32/64 bit *) + ; ei_data : elfdata (* endianness *) + ; ei_version : ev (* ELF header version *) + } (** ELF header *) @@ -59,22 +59,22 @@ let shn_UNDEF = 0 let shn_ABS = 0xFFF1 let shn_COMMON = 0xFFF2 -type elf32_ehdr = { - e_ident: elf_identification; (* Machine-independent data *) - e_type: et; (* Object file type *) - e_machine: em; (* Required architecture *) - e_version: ev; (* Object file version *) - e_entry: elf32_addr; (* Entry point virtual address *) - e_phoff: elf32_off; (* Program header table's offset *) - e_shoff: elf32_off; (* Section header table's offset *) - e_flags: Bitstring.bitstring; (* Processor-specific flags *) - e_ehsize: elf32_half; (* ELF header size *) - e_phentsize: elf32_half; (* Size of a program header's entry *) - e_phnum: elf32_half; (* Number of program header entries *) - e_shentsize: elf32_half; (* Size of a section header's entry *) - e_shnum: elf32_half; (* Number of section header entries *) - e_shstrndx: elf32_half; (* Section name string table index *) -} +type elf32_ehdr = + { e_ident : elf_identification (* Machine-independent data *) + ; e_type : et (* Object file type *) + ; e_machine : em (* Required architecture *) + ; e_version : ev (* Object file version *) + ; e_entry : elf32_addr (* Entry point virtual address *) + ; e_phoff : elf32_off (* Program header table's offset *) + ; e_shoff : elf32_off (* Section header table's offset *) + ; e_flags : Bitstring.bitstring (* Processor-specific flags *) + ; e_ehsize : elf32_half (* ELF header size *) + ; e_phentsize : elf32_half (* Size of a program header's entry *) + ; e_phnum : elf32_half (* Number of program header entries *) + ; e_shentsize : elf32_half (* Size of a section header's entry *) + ; e_shnum : elf32_half (* Number of section header entries *) + ; e_shstrndx : elf32_half (* Section name string table index *) + } (** ELF section header *) @@ -93,18 +93,18 @@ type sht = | SHT_DYNSYM | SHT_UNKNOWN -type elf32_shdr = { - sh_name: string; - sh_type: sht; - sh_flags: elf32_word; - sh_addr: elf32_addr; - sh_offset: elf32_off; - sh_size: elf32_word; - sh_link: elf32_word; - sh_info: elf32_word; - sh_addralign: elf32_word; - sh_entsize: elf32_word; -} +type elf32_shdr = + { sh_name : string + ; sh_type : sht + ; sh_flags : elf32_word + ; sh_addr : elf32_addr + ; sh_offset : elf32_off + ; sh_size : elf32_word + ; sh_link : elf32_word + ; sh_info : elf32_word + ; sh_addralign : elf32_word + ; sh_entsize : elf32_word + } let shf_WRITE = 0x1l let shf_ALLOC = 0x2l @@ -124,15 +124,15 @@ type elf32_st_type = | STT_FILE | STT_UNKNOWN -type elf32_sym = { - st_name: string; - st_value: elf32_addr; - st_size: elf32_word; - st_bind: elf32_st_bind; - st_type: elf32_st_type; - st_other: byte; - st_shndx: elf32_half; -} +type elf32_sym = + { st_name : string + ; st_value : elf32_addr + ; st_size : elf32_word + ; st_bind : elf32_st_bind + ; st_type : elf32_st_type + ; st_other : byte + ; st_shndx : elf32_half + } (** ELF program header *) @@ -146,24 +146,25 @@ type p_type = | PT_PHDR | PT_UNKNOWN -type elf32_phdr = { - p_type: p_type ; - p_offset: elf32_off ; - p_vaddr: elf32_addr ; - p_paddr: elf32_addr ; - p_filesz: elf32_word ; - p_memsz: elf32_word ; - p_flags: bitstring ; - p_align: elf32_word ; -} +type elf32_phdr = + { p_type : p_type + ; p_offset : elf32_off + ; p_vaddr : elf32_addr + ; p_paddr : elf32_addr + ; p_filesz : elf32_word + ; p_memsz : elf32_word + ; p_flags : bitstring + ; p_align : elf32_word + } (** ELF *) -type elf = { - e_bitstring: bitstring; - e_hdr: elf32_ehdr; - e_shdra: elf32_shdr array; - e_phdra: elf32_phdr array; - e_symtab: elf32_sym array; - e_symtab_sndx: int; (* to avoid having to find it again when needed *) - e_syms_by_name: int list StringMap.t; (* faster lookup *) -} +type elf = + { e_bitstring : bitstring + ; e_hdr : elf32_ehdr + ; e_shdra : elf32_shdr array + ; e_phdra : elf32_phdr array + ; e_symtab : elf32_sym array + ; e_symtab_sndx : int (* section index of the symbol table *) + ; e_sym_phdr : int32 -> int option (* fast sym -> phdr lookup *) + ; e_syms_by_name : int list StringMap.t (* fast name -> sym lookup *) + } -- cgit v1.2.3