FreeBSD/contrib/binutils/binutils/readelf.c
/* Find the file offset corresponding to VMA by using the program headers.  */
Find the file offset corresponding to VMA by using the program headers.
Find the file offset corresponding to VMA by using the program headers .
static long
offset_from_vma (FILE *file, bfd_vma vma, bfd_size_type size)
{
  Elf_Internal_Phdr *seg;
  if (! get_program_headers (file))
    {
      warn (_("Cannot interpret virtual addresses without program headers.\n"));
      return (long) vma;
    }
  for (seg = program_headers;
       seg < program_headers + elf_header.e_phnum;
       ++seg)
    {
      if (seg->p_type != PT_LOAD)
	continue;
      if (vma >= (seg->p_vaddr & -seg->p_align)
	  && vma + size <= seg->p_vaddr + seg->p_filesz)
	return vma - seg->p_vaddr + seg->p_offset;
    }
  warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
	(long) vma);
  return (long) vma;
}
static long offset_from_vma ( FILE * file , bfd_vma vma , bfd_size_type size ) { Elf_Internal_Phdr * seg ; if ( ! get_program_headers ( file ) ) { warn ( _ ( " \n " ) ) ; return ( long ) vma ; } for ( seg = program_headers ; seg < program_headers + elf_header . e_phnum ; ++ seg ) { if ( seg -> p_type != PT_LOAD ) continue ; if ( vma >= ( seg -> p_vaddr & - seg -> p_align ) && vma + size <= seg -> p_vaddr + seg -> p_filesz ) return vma - seg -> p_vaddr + seg -> p_offset ; } warn ( _ ( " \n " ) , ( long ) vma ) ; return ( long ) vma ; }
Find the file offset corresponding to VMA by using the program headers.
Find the file offset corresponding to VMA by using the program headers .