[llvm] r372473 - [Support] Add a DataExtractor constructor that takes ArrayRef<uint8_t>
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 21 08:05:03 PDT 2019
Author: maskray
Date: Sat Sep 21 08:05:03 2019
New Revision: 372473
URL: http://llvm.org/viewvc/llvm-project?rev=372473&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/Support/DataExtractor.h
llvm/trunk/tools/llvm-readobj/DwarfCFIEHPrinter.h
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
Modified: llvm/trunk/include/llvm/Support/DataExtractor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/DataExtractor.h?rev=372473&r1=372472&r2=372473&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/DataExtractor.h (original)
+++ llvm/trunk/include/llvm/Support/DataExtractor.h Sat Sep 21 08:05:03 2019
@@ -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; }
Modified: llvm/trunk/tools/llvm-readobj/DwarfCFIEHPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/DwarfCFIEHPrinter.h?rev=372473&r1=372472&r2=372473&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/DwarfCFIEHPrinter.h (original)
+++ llvm/trunk/tools/llvm-readobj/DwarfCFIEHPrinter.h Sat Sep 21 08:05:03 2019
@@ -114,11 +114,9 @@ void PrinterContext<ELFT>::printEHFrameH
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;
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=372473&r1=372472&r2=372473&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Sat Sep 21 08:05:03 2019
@@ -4639,10 +4639,9 @@ void GNUStyle<ELFT>::printNotes(const EL
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>::printNonRelocatabl
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>::printRelocatableSt
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 E
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);
More information about the llvm-commits
mailing list