From 3f205ff4314ccac92e4d74951929aa31b0308274 Mon Sep 17 00:00:00 2001 From: varobert Date: Fri, 13 Apr 2012 08:35:21 +0000 Subject: New section mapping checks and symbol data lookup Section mapping is now discovered on-the-fly, and linker script remappings are reported as warnings at the end. Symbol data lookup is now able to gracefully fail if the symbol's virtual address is not within the range of its parent section's virtual address space. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1878 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- checklink/ELF_utils.ml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'checklink/ELF_utils.ml') diff --git a/checklink/ELF_utils.ml b/checklink/ELF_utils.ml index 5244dc8..4d90160 100644 --- a/checklink/ELF_utils.ml +++ b/checklink/ELF_utils.ml @@ -35,20 +35,26 @@ let section_at_vaddr (e: elf)(vaddr: int32): int option = *) let bitstring_at_vaddr e sndx vaddr size = let shdr = e.e_shdra.(sndx) in - let bs = section_bitstring e sndx in - let bit_ofs = Safe.(8 * Safe32.(to_int (vaddr - shdr.sh_addr))) in - Bitstring.subbitstring bs bit_ofs size + if vaddr < shdr.sh_addr || Safe32.(shdr.sh_addr + shdr.sh_size) <= vaddr + then None + else + let bs = section_bitstring e sndx in + let bit_ofs = Safe.(8 * Safe32.(to_int (vaddr - shdr.sh_addr))) in + Some(Bitstring.subbitstring bs bit_ofs size) (** Returns the entire bitstring that begins at the specified virtual address within the specified section and ends at the end of the file. This is useful when you don't know the sections size yet. *) -let bitstring_at_vaddr_nosize (e: elf)(sndx: int)(vaddr: int32): bitstring = +let bitstring_at_vaddr_nosize (e: elf)(sndx: int)(vaddr: int32): bitstring option = let shdr = e.e_shdra.(sndx) in - let bs = section_bitstring e sndx in - let bit_ofs = Safe.(8 * Safe32.(to_int (vaddr - shdr.sh_addr))) in - Bitstring.dropbits bit_ofs bs + if vaddr < shdr.sh_addr || Safe32.(shdr.sh_addr + shdr.sh_size) <= vaddr + then None + else + let bs = section_bitstring e sndx in + let bit_ofs = Safe.(8 * Safe32.(to_int (vaddr - shdr.sh_addr))) in + Some(Bitstring.dropbits bit_ofs bs) (** Removes symbol version for GCC's symbols. -- cgit v1.2.3