Skip to content

Commit 9ec7117

Browse files
committed
[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
1 parent e75c6b6 commit 9ec7117

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

llvm/include/llvm/Support/DataExtractor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ class DataExtractor {
8282
/// valid.
8383
DataExtractor(StringRef Data, bool IsLittleEndian, uint8_t AddressSize)
8484
: Data(Data), IsLittleEndian(IsLittleEndian), AddressSize(AddressSize) {}
85+
DataExtractor(ArrayRef<uint8_t> Data, bool IsLittleEndian,
86+
uint8_t AddressSize)
87+
: Data(StringRef(reinterpret_cast<const char *>(Data.data()),
88+
Data.size())),
89+
IsLittleEndian(IsLittleEndian), AddressSize(AddressSize) {}
8590

8691
/// Get the data pointed to by this extractor.
8792
StringRef getData() const { return Data; }

llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,9 @@ void PrinterContext<ELFT>::printEHFrameHdr(uint64_t EHFrameHdrOffset,
114114
W.printString("Corresponding Section", *SectionName);
115115
}
116116

117-
DataExtractor DE(
118-
StringRef(reinterpret_cast<const char *>(Obj->base()) + EHFrameHdrOffset,
119-
EHFrameHdrSize),
120-
ELFT::TargetEndianness == support::endianness::little,
121-
ELFT::Is64Bits ? 8 : 4);
117+
DataExtractor DE(makeArrayRef(Obj->base() + EHFrameHdrOffset, EHFrameHdrSize),
118+
ELFT::TargetEndianness == support::endianness::little,
119+
ELFT::Is64Bits ? 8 : 4);
122120

123121
DictScope D(W, "Header");
124122
uint64_t Offset = 0;

llvm/tools/llvm-readobj/ELFDumper.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4639,10 +4639,9 @@ void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
46394639
OS << " " << N.Type << ":\n " << N.Value << '\n';
46404640
} else if (Name == "CORE") {
46414641
if (Type == ELF::NT_FILE) {
4642-
DataExtractor DescExtractor(
4643-
StringRef(reinterpret_cast<const char *>(Descriptor.data()),
4644-
Descriptor.size()),
4645-
ELFT::TargetEndianness == support::little, sizeof(Elf_Addr));
4642+
DataExtractor DescExtractor(Descriptor,
4643+
ELFT::TargetEndianness == support::little,
4644+
sizeof(Elf_Addr));
46464645
Expected<CoreNote> Note = readCoreNote(DescExtractor);
46474646
if (Note)
46484647
printCoreNote<ELFT>(OS, *Note);
@@ -4836,10 +4835,7 @@ void DumpStyle<ELFT>::printNonRelocatableStackSizes(
48364835
const Elf_Shdr *ElfSec = Obj->getSection(Sec.getRawDataRefImpl());
48374836
ArrayRef<uint8_t> Contents =
48384837
unwrapOrError(this->FileName, EF->getSectionContents(ElfSec));
4839-
DataExtractor Data(
4840-
StringRef(reinterpret_cast<const char *>(Contents.data()),
4841-
Contents.size()),
4842-
Obj->isLittleEndian(), sizeof(Elf_Addr));
4838+
DataExtractor Data(Contents, Obj->isLittleEndian(), sizeof(Elf_Addr));
48434839
// A .stack_sizes section header's sh_link field is supposed to point
48444840
// to the section that contains the functions whose stack sizes are
48454841
// described in it.
@@ -4937,10 +4933,7 @@ void DumpStyle<ELFT>::printRelocatableStackSizes(
49374933
RelocationResolver Resolver;
49384934
std::tie(IsSupportedFn, Resolver) = getRelocationResolver(*Obj);
49394935
auto Contents = unwrapOrError(this->FileName, StackSizesSec.getContents());
4940-
DataExtractor Data(
4941-
StringRef(reinterpret_cast<const char *>(Contents.data()),
4942-
Contents.size()),
4943-
Obj->isLittleEndian(), sizeof(Elf_Addr));
4936+
DataExtractor Data(Contents, Obj->isLittleEndian(), sizeof(Elf_Addr));
49444937
for (const RelocationRef &Reloc : RelocSec.relocations()) {
49454938
if (!IsSupportedFn(Reloc.getType()))
49464939
reportError(createStringError(
@@ -5831,10 +5824,9 @@ void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
58315824
W.printString(N.Type, N.Value);
58325825
} else if (Name == "CORE") {
58335826
if (Type == ELF::NT_FILE) {
5834-
DataExtractor DescExtractor(
5835-
StringRef(reinterpret_cast<const char *>(Descriptor.data()),
5836-
Descriptor.size()),
5837-
ELFT::TargetEndianness == support::little, sizeof(Elf_Addr));
5827+
DataExtractor DescExtractor(Descriptor,
5828+
ELFT::TargetEndianness == support::little,
5829+
sizeof(Elf_Addr));
58385830
Expected<CoreNote> Note = readCoreNote(DescExtractor);
58395831
if (Note)
58405832
printCoreNoteLLVMStyle(*Note, W);

0 commit comments

Comments
 (0)