Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -243,24 +243,14 @@ TYPEDEF_ELF_TYPES(ELFT) - DynRegionInfo checkDRI(DynRegionInfo DRI) { + DynRegionInfo createDRI(uint64_t Offset, uint64_t Size, uint64_t EntSize) { const ELFFile *Obj = ObjF->getELFFile(); - if (DRI.Addr < Obj->base() || - reinterpret_cast(DRI.Addr) + DRI.Size > - Obj->base() + Obj->getBufSize()) + const uint8_t *Addr = Obj->base() + Offset; + if (Addr < Obj->base() || Addr + Size > Obj->base() + Obj->getBufSize()) reportError(errorCodeToError(llvm::object::object_error::parse_failed), ObjF->getFileName()); - return DRI; - } - - DynRegionInfo createDRIFrom(const Elf_Phdr *P, uintX_t EntSize) { - return checkDRI({ObjF->getELFFile()->base() + P->p_offset, P->p_filesz, - EntSize, ObjF->getFileName()}); - } - DynRegionInfo createDRIFrom(const Elf_Shdr *S) { - return checkDRI({ObjF->getELFFile()->base() + S->sh_offset, S->sh_size, - S->sh_entsize, ObjF->getFileName()}); + return {Addr, Size, EntSize, ObjF->getFileName()}; } void printAttributes(); @@ -1936,7 +1926,8 @@ DynRegionInfo FromPhdr(ObjF->getFileName()); bool IsPhdrTableValid = false; if (DynamicPhdr) { - FromPhdr = createDRIFrom(DynamicPhdr, sizeof(Elf_Dyn)); + FromPhdr = createDRI(DynamicPhdr->p_offset, DynamicPhdr->p_filesz, + sizeof(Elf_Dyn)); FromPhdr.SizePrintName = "PT_DYNAMIC size"; FromPhdr.EntSizePrintName = ""; @@ -1951,8 +1942,7 @@ bool IsSecTableValid = false; if (DynamicSec) { FromSec = - checkDRI({ObjF->getELFFile()->base() + DynamicSec->sh_offset, - DynamicSec->sh_size, sizeof(Elf_Dyn), ObjF->getFileName()}); + createDRI(DynamicSec->sh_offset, DynamicSec->sh_size, sizeof(Elf_Dyn)); FromSec.Context = describe(*DynamicSec); FromSec.EntSizePrintName = ""; @@ -2040,7 +2030,7 @@ DotDynsymSec = &Sec; if (!DynSymRegion) { - DynSymRegion = createDRIFrom(&Sec); + DynSymRegion = createDRI(Sec.sh_offset, Sec.sh_size, Sec.sh_entsize); DynSymRegion->Context = describe(Sec); if (Expected E = Obj->getStringTableForSymtab(Sec))