This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: dwfl_module_relocate_address() versus base address


Hi Roland,

On Tue, 2008-12-16 at 15:05 -0800, Roland McGrath wrote:
> The main ELF file's bias is the difference between what the file's
> headers like p_vaddr and sh_addr say and what the actual address is in
> the address space described by your Dwfl object.
>[...]
> The dwarf_module_getelf call gives you the main file's bias.  This is
> what you need to adjust a p_vaddr/sh_addr address by to make it an
> absolute address in your Dwfl's space (or vice versa, in your use
> here).
>[...]
> dwfl_module_relocation_info tells you the ELF section index and name
> for a relocation base index.  For ET_REL this is a proper index and
> that section's name.  For ET_DYN(-like) there is only one valid
> relocation base index (0), for which dwfl_module_relocation_info
> yields SHN_ABS and "".
>[...]
>Is that all clear?

So many addresses spaces, biases, offsets and elf/section/program
headers to get wrong :{ And I see in my write up I actually switched
dwfl_module_relocation_info and dwfl_module_address_section in a couple
of places, sigh. But yes, I think it is all clear now. Thanks.

The one remaining issue is finding the correct p_vaddr. I must be
missing the obvious. Currently I am just going through all program
headers to try and find the correct one (after adjusting sym_addr for
the elf main file bias):

      ehdr = gelf_getehdr(elf, &ehdr_mem);
      for (idx = 0; idx < ehdr->e_phnum; idx++)
        {
          phdr = gelf_getphdr (elf, idx, &phdr_mem);
          if (phdr != NULL
              && phdr->p_type == PT_LOAD
              && phdr->p_flags & PF_X
              && sym_addr >= phdr->p_vaddr
              && sym_addr < phdr->p_vaddr + phdr->p_memsz)
            break;
        }
      if (phdr != NULL && idx < ehdr->e_phnum)
        sym_addr -= phdr->p_vaddr;

Is there a simpler way?

Cheers,

Mark


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]