summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2016-02-16 14:50:39 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2016-02-16 14:50:39 +0000
commitc70aedab0e0561df2b426a7a464670847063232d (patch)
tree802f0400f0aea5870a692f55e88ffa7e7e75f882
parent42770525ebbd2cdd5f9c362897c225eb20719202 (diff)
downloadbcm5719-llvm-c70aedab0e0561df2b426a7a464670847063232d.tar.gz
bcm5719-llvm-c70aedab0e0561df2b426a7a464670847063232d.zip
Introduce a getAsRange helper.
This requires making an error message a bit more generic, but that seems a reasonable tradeoff. Extracted from r260488 but simplified a bit. llvm-svn: 260967
-rw-r--r--llvm/test/Object/corrupt.test2
-rw-r--r--llvm/tools/llvm-readobj/ELFDumper.cpp34
2 files changed, 10 insertions, 26 deletions
diff --git a/llvm/test/Object/corrupt.test b/llvm/test/Object/corrupt.test
index 0d9aad378f8..7208566c25b 100644
--- a/llvm/test/Object/corrupt.test
+++ b/llvm/test/Object/corrupt.test
@@ -49,7 +49,7 @@ RUN: not llvm-readobj -dyn-relocations \
RUN: %p/Inputs/corrupt-invalid-relocation-size.elf.x86-64 2>&1 | \
RUN: FileCheck --check-prefix=RELOC %s
-RELOC: Invalid relocation entry size
+RELOC: Invalid entity size
RUN: not llvm-readobj -dyn-relocations \
RUN: %p/Inputs/corrupt-invalid-dynamic-table-size.elf.x86-64 2>&1 | \
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index cd221e39747..b8c815e4b35 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -57,6 +57,13 @@ struct DynRegionInfo {
uint64_t Size;
/// \brief Size of each entity in the region.
uint64_t EntSize;
+
+ template <typename Type> iterator_range<const Type *> getAsRange() const {
+ const Type *Start = reinterpret_cast<const Type *>(Addr);
+ if (EntSize != sizeof(Type) || Size % EntSize)
+ reportError("Invalid entity size");
+ return {Start, Start + (Size / EntSize)};
+ }
};
template<typename ELFT>
@@ -123,10 +130,6 @@ private:
void printRelocation(Elf_Rela Rel, const Elf_Shdr *SymTab);
void printValue(uint64_t Type, uint64_t Value);
- template <typename REL>
- static const REL *dyn_rel_begin(const DynRegionInfo &region);
- template <typename REL>
- static const REL *dyn_rel_end(const DynRegionInfo &region);
Elf_Rel_Range dyn_rels() const;
Elf_Rela_Range dyn_relas() const;
StringRef getDynamicString(uint64_t Offset) const;
@@ -1111,32 +1114,13 @@ void ELFDumper<ELFT>::parseDynamicTable(
}
template <typename ELFT>
-template <typename REL>
-const REL *ELFDumper<ELFT>::dyn_rel_begin(const DynRegionInfo &Region) {
- if (Region.Size && Region.EntSize != sizeof(REL))
- report_fatal_error("Invalid relocation entry size");
- return reinterpret_cast<const REL *>(Region.Addr);
-}
-
-template <typename ELFT>
-template <typename REL>
-const REL *ELFDumper<ELFT>::dyn_rel_end(const DynRegionInfo &Region) {
- uint64_t Size = Region.Size;
- if (Size % sizeof(REL))
- report_fatal_error("Invalid relocation table size");
- return dyn_rel_begin<REL>(Region) + Size / sizeof(REL);
-}
-
-template <typename ELFT>
typename ELFDumper<ELFT>::Elf_Rel_Range ELFDumper<ELFT>::dyn_rels() const {
- return make_range(dyn_rel_begin<Elf_Rel>(DynRelRegion),
- dyn_rel_end<Elf_Rel>(DynRelRegion));
+ return DynRelRegion.getAsRange<Elf_Rel>();
}
template <typename ELFT>
typename ELFDumper<ELFT>::Elf_Rela_Range ELFDumper<ELFT>::dyn_relas() const {
- return make_range(dyn_rel_begin<Elf_Rela>(DynRelaRegion),
- dyn_rel_end<Elf_Rela>(DynRelaRegion));
+ return DynRelaRegion.getAsRange<Elf_Rela>();
}
template<class ELFT>
OpenPOWER on IntegriCloud