[PATCH] D25822: [DWARF parsers] - Add a way to get section indices when call DWARFUnit::collectAddressRanges()

Greg Clayton via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 21 10:37:15 PDT 2016


clayborg added a comment.

In https://reviews.llvm.org/D25822#575786, @grimar wrote:

> In https://reviews.llvm.org/D25822#575566, @clayborg wrote:
>
> > Seems like a lot of work to include the section index everywhere. Can't the section index just be looked up using the ObjectFile given an address? Something like:
> >
> >   uint32_t ObjectFile::getSectionIndexForAddress(uint64_t addr);
> >
>
>
> Could you elaborate what addr should I use for such search ? 
>  getAddressRanges() returns me LowPC/HighPC.
>
> For example for gdb-index-a.elf from https://reviews.llvm.org/D24706, LowPC = 0x0, HighPC = 0xb, readelf shows:
>
>   Section Headers:
>     [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
>     [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
>     [ 1] .text             PROGBITS        0000000000000000 000040 00000b 00  AX  0   0  1
>     [ 2] .data             PROGBITS        0000000000000000 00004b 000000 00  WA  0   0  1
>     [ 3] .bss              NOBITS          0000000000000000 00004b 000000 00  WA  0   0  1
>     [ 4] .debug_addr       PROGBITS        0000000000000000 00004b 000008 00      0   0  1
>     [ 5] .rela.debug_addr  RELA            0000000000000000 000380 000018 18   I 23   4  8
>   .....
>
>
> How having just there values I can know that section I am looking is .text ?


You can see that .text has a size of 0xb and starts at 0x0. So the address would fall into the .text section. You would probably want to keep a table of the PROGBITS sections that also have AX permissions if you know you are looking for code addresses. Someone else more familiar with ELF .o files might be able to help.


https://reviews.llvm.org/D25822





More information about the llvm-commits mailing list