summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-09-21 15:05:03 +0000
committerFangrui Song <maskray@google.com>2019-09-21 15:05:03 +0000
commit9ec7117506355771a8410b6c92c94bc6f6754ffb (patch)
treef0e7f67857eb83f9962c41c74e3b9c21ac9622e2
parente75c6b6d48d857a95750f63923ea7d26c220a9a4 (diff)
downloadbcm5719-llvm-9ec7117506355771a8410b6c92c94bc6f6754ffb.tar.gz
bcm5719-llvm-9ec7117506355771a8410b6c92c94bc6f6754ffb.zip
[Support] Add a DataExtractor constructor that takes ArrayRef<uint8_t>
The new constructor can simplify some llvm-readobj call sites. Reviewed By: grimar, dblaikie Differential Revision: https://reviews.llvm.org/D67797 llvm-svn: 372473
-rw-r--r--llvm/include/llvm/Support/DataExtractor.h5
-rw-r--r--llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h8
-rw-r--r--llvm/tools/llvm-readobj/ELFDumper.cpp24
3 files changed, 16 insertions, 21 deletions
diff --git a/llvm/include/llvm/Support/DataExtractor.h b/llvm/include/llvm/Support/DataExtractor.h
index bd337f23925..f590a1e104f 100644
--- a/llvm/include/llvm/Support/DataExtractor.h
+++ b/llvm/include/llvm/Support/DataExtractor.h
@@ -82,6 +82,11 @@ public:
/// valid.
DataExtractor(StringRef Data, bool IsLittleEndian, uint8_t AddressSize)
: Data(Data), IsLittleEndian(IsLittleEndian), AddressSize(AddressSize) {}
+ DataExtractor(ArrayRef<uint8_t> Data, bool IsLittleEndian,
+ uint8_t AddressSize)
+ : Data(StringRef(reinterpret_cast<const char *>(Data.data()),
+ Data.size())),
+ IsLittleEndian(IsLittleEndian), AddressSize(AddressSize) {}
/// Get the data pointed to by this extractor.
StringRef getData() const { return Data; }
diff --git a/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h b/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
index fdd01e12283..683243f8cd4 100644
--- a/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
+++ b/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
@@ -114,11 +114,9 @@ void PrinterContext<ELFT>::printEHFrameHdr(uint64_t EHFrameHdrOffset,
W.printString("Corresponding Section", *SectionName);
}
- DataExtractor DE(
- StringRef(reinterpret_cast<const char *>(Obj->base()) + EHFrameHdrOffset,
- EHFrameHdrSize),
- ELFT::TargetEndianness == support::endianness::little,
- ELFT::Is64Bits ? 8 : 4);
+ DataExtractor DE(makeArrayRef(Obj->base() + EHFrameHdrOffset, EHFrameHdrSize),
+ ELFT::TargetEndianness == support::endianness::little,
+ ELFT::Is64Bits ? 8 : 4);
DictScope D(W, "Header");
uint64_t Offset = 0;
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 51e242f7db9..82d9fbb3ee7 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -4639,10 +4639,9 @@ void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
OS << " " << N.Type << ":\n " << N.Value << '\n';
} else if (Name == "CORE") {
if (Type == ELF::NT_FILE) {
- DataExtractor DescExtractor(
- StringRef(reinterpret_cast<const char *>(Descriptor.data()),
- Descriptor.size()),
- ELFT::TargetEndianness == support::little, sizeof(Elf_Addr));
+ DataExtractor DescExtractor(Descriptor,
+ ELFT::TargetEndianness == support::little,
+ sizeof(Elf_Addr));
Expected<CoreNote> Note = readCoreNote(DescExtractor);
if (Note)
printCoreNote<ELFT>(OS, *Note);
@@ -4836,10 +4835,7 @@ void DumpStyle<ELFT>::printNonRelocatableStackSizes(
const Elf_Shdr *ElfSec = Obj->getSection(Sec.getRawDataRefImpl());
ArrayRef<uint8_t> Contents =
unwrapOrError(this->FileName, EF->getSectionContents(ElfSec));
- DataExtractor Data(
- StringRef(reinterpret_cast<const char *>(Contents.data()),
- Contents.size()),
- Obj->isLittleEndian(), sizeof(Elf_Addr));
+ DataExtractor Data(Contents, Obj->isLittleEndian(), sizeof(Elf_Addr));
// A .stack_sizes section header's sh_link field is supposed to point
// to the section that contains the functions whose stack sizes are
// described in it.
@@ -4937,10 +4933,7 @@ void DumpStyle<ELFT>::printRelocatableStackSizes(
RelocationResolver Resolver;
std::tie(IsSupportedFn, Resolver) = getRelocationResolver(*Obj);
auto Contents = unwrapOrError(this->FileName, StackSizesSec.getContents());
- DataExtractor Data(
- StringRef(reinterpret_cast<const char *>(Contents.data()),
- Contents.size()),
- Obj->isLittleEndian(), sizeof(Elf_Addr));
+ DataExtractor Data(Contents, Obj->isLittleEndian(), sizeof(Elf_Addr));
for (const RelocationRef &Reloc : RelocSec.relocations()) {
if (!IsSupportedFn(Reloc.getType()))
reportError(createStringError(
@@ -5831,10 +5824,9 @@ void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
W.printString(N.Type, N.Value);
} else if (Name == "CORE") {
if (Type == ELF::NT_FILE) {
- DataExtractor DescExtractor(
- StringRef(reinterpret_cast<const char *>(Descriptor.data()),
- Descriptor.size()),
- ELFT::TargetEndianness == support::little, sizeof(Elf_Addr));
+ DataExtractor DescExtractor(Descriptor,
+ ELFT::TargetEndianness == support::little,
+ sizeof(Elf_Addr));
Expected<CoreNote> Note = readCoreNote(DescExtractor);
if (Note)
printCoreNoteLLVMStyle(*Note, W);
OpenPOWER on IntegriCloud