[PATCH] D67797: [Support] Add a DataExtractor constructor that takes ArrayRef<uint8_t>
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 19 23:24:29 PDT 2019
MaskRay created this revision.
MaskRay added reviewers: aprantl, grimar, ikudrin, labath, probinson.
Herald added subscribers: llvm-commits, seiya, kristina, rupprecht.
Herald added a project: LLVM.
The new constructor can simplify some llvm-readobj call sites.
Repository:
rL LLVM
https://reviews.llvm.org/D67797
Files:
include/llvm/Support/DataExtractor.h
tools/llvm-readobj/DwarfCFIEHPrinter.h
tools/llvm-readobj/ELFDumper.cpp
Index: tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- tools/llvm-readobj/ELFDumper.cpp
+++ tools/llvm-readobj/ELFDumper.cpp
@@ -4639,10 +4639,9 @@
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 @@
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 @@
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 @@
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);
Index: tools/llvm-readobj/DwarfCFIEHPrinter.h
===================================================================
--- tools/llvm-readobj/DwarfCFIEHPrinter.h
+++ tools/llvm-readobj/DwarfCFIEHPrinter.h
@@ -114,11 +114,9 @@
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;
Index: include/llvm/Support/DataExtractor.h
===================================================================
--- include/llvm/Support/DataExtractor.h
+++ include/llvm/Support/DataExtractor.h
@@ -82,6 +82,11 @@
/// 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; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67797.220953.patch
Type: text/x-patch
Size: 4335 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190920/e68ce9dc/attachment.bin>
More information about the llvm-commits
mailing list