[llvm] r211150 - [llvm-readobj][ELF] New `-mips-plt-got` command line option to output

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 11:18:21 PST 2016


On Tue, Feb 2, 2016 at 9:59 PM, Rafael EspĂ­ndola
<rafael.espindola at gmail.com> wrote:
>> +template <class ELFT>
>> +static const typename ELFFile<ELFT>::Elf_Shdr *
>> +findSectionByAddress(const ELFFile<ELFT> *Obj, uint64_t Addr) {
>> +  for (const auto &Shdr : Obj->sections())
>> +    if (Shdr.sh_addr == Addr)
>> +      return &Shdr;
>> +  return nullptr;
>> +}
> Hi Simon, this assumes that the first section with a given address is
> the one you want. This seems invalid since you can have multiple empty
> sections at the same address. From the code it looks like this is used
> to find the size of sections like .got. Is this really what the
> dynamic linker does? Or it doesn't need to know the size at at all?

You are right, in general case this function might return unexpected
section. A better name for it is 'findFirstSectionAtAddress'.

AFAIK dynamic linker and readelf tool do not rely on the actual
section size. They use DT_PLTGOT to find section address,
DT_MIPS_LOCAL_GOTNO to iterate over local GOT entries and
DT_MIPS_SYMTABNO/DT_MIPS_GOTSYM to iterate over global GOT entries.

I do not know what is the best solution in our case. Probably more
accurate approach is to find a section with specified address and
non-zero size. I can take a look at this problem if you do not plan to
fix it by yourself.


More information about the llvm-commits mailing list