Skip to content

Commit 36f2318

Browse files
author
George Rimar
committed
[llvm-readobj] - Remove 'error(Error EC)' helper.
We do not need it. I replaced it with reportError(StringRef Input, Error Err). Differential revision: https://reviews.llvm.org/D66011 llvm-svn: 368677
1 parent f8d6836 commit 36f2318

File tree

7 files changed

+103
-82
lines changed

7 files changed

+103
-82
lines changed

llvm/test/tools/llvm-readobj/gnu-notes.test

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ Sections:
7979
## that goes past the end of file.
8080

8181
# RUN: yaml2obj --docnum=2 %s > %t2.so
82-
# RUN: not llvm-readelf --notes %t2.so 2>&1 | FileCheck %s --check-prefix=ERR1
83-
# RUN: not llvm-readobj --notes %t2.so 2>&1 | FileCheck %s --check-prefix=ERR1
82+
# RUN: not llvm-readelf --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1
83+
# RUN: not llvm-readobj --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1
8484

85-
# ERR1: error: SHT_NOTE section [index 1] has invalid offset (0xffff0000) or size (0x0)
85+
# ERR1: error: '[[FILE]]': SHT_NOTE section [index 1] has invalid offset (0xffff0000) or size (0x0)
8686

8787
--- !ELF
8888
FileHeader:
@@ -99,10 +99,10 @@ Sections:
9999
## that goes past the end of file.
100100

101101
# RUN: yaml2obj --docnum=3 %s > %t3.so
102-
# RUN: not llvm-readelf --notes %t3.so 2>&1 | FileCheck %s --check-prefix=ERR2
103-
# RUN: not llvm-readobj --notes %t3.so 2>&1 | FileCheck %s --check-prefix=ERR2
102+
# RUN: not llvm-readelf --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2
103+
# RUN: not llvm-readobj --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2
104104

105-
# ERR2: error: SHT_NOTE section [index 1] has invalid offset (0x180) or size (0xffff0000)
105+
# ERR2: error: '[[FILE]]': SHT_NOTE section [index 1] has invalid offset (0x180) or size (0xffff0000)
106106

107107
--- !ELF
108108
FileHeader:
@@ -119,10 +119,10 @@ Sections:
119119
## goes past the end of file.
120120

121121
# RUN: yaml2obj --docnum=4 %s > %t4.so
122-
# RUN: not llvm-readelf --notes %t4.so 2>&1 | FileCheck %s --check-prefix=ERR3
123-
# RUN: not llvm-readobj --notes %t4.so 2>&1 | FileCheck %s --check-prefix=ERR3
122+
# RUN: not llvm-readelf --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3
123+
# RUN: not llvm-readobj --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3
124124

125-
# ERR3: error: PT_NOTE header has invalid offset (0xffff0000) or size (0x0)
125+
# ERR3: error: '[[FILE]]': PT_NOTE header has invalid offset (0xffff0000) or size (0x0)
126126

127127
--- !ELF
128128
FileHeader:
@@ -143,10 +143,10 @@ ProgramHeaders:
143143
## goes past the end of file.
144144

145145
# RUN: yaml2obj --docnum=5 %s > %t5.so
146-
# RUN: not llvm-readelf --notes %t5.so 2>&1 | FileCheck %s --check-prefix=ERR4
147-
# RUN: not llvm-readobj --notes %t5.so 2>&1 | FileCheck %s --check-prefix=ERR4
146+
# RUN: not llvm-readelf --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4
147+
# RUN: not llvm-readobj --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4
148148

149-
# ERR4: error: PT_NOTE header has invalid offset (0x1b8) or size (0xffff0000)
149+
# ERR4: error: '[[FILE]]': PT_NOTE header has invalid offset (0x1b8) or size (0xffff0000)
150150

151151
--- !ELF
152152
FileHeader:

llvm/tools/llvm-readobj/ARMEHABIPrinter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ PrinterContext<ET>::FunctionAtAddress(unsigned Section,
370370
return readobj_error::unknown_symbol;
371371
auto StrTableOrErr = ELF->getStringTableForSymtab(*Symtab);
372372
if (!StrTableOrErr)
373-
error(StrTableOrErr.takeError());
373+
reportError(StrTableOrErr.takeError(), FileName);
374374
StringRef StrTable = *StrTableOrErr;
375375

376376
for (const Elf_Sym &Sym : unwrapOrError(FileName, ELF->symbols(Symtab)))
@@ -405,7 +405,7 @@ PrinterContext<ET>::FindExceptionTable(unsigned IndexSectionIndex,
405405

406406
auto SymTabOrErr = ELF->getSection(Sec.sh_link);
407407
if (!SymTabOrErr)
408-
error(SymTabOrErr.takeError());
408+
reportError(SymTabOrErr.takeError(), FileName);
409409
const Elf_Shdr *SymTab = *SymTabOrErr;
410410

411411
for (const Elf_Rel &R : unwrapOrError(FileName, ELF->rels(&Sec))) {

llvm/tools/llvm-readobj/COFFDumper.cpp

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -912,26 +912,33 @@ void COFFDumper::initializeFileAndStringTables(BinaryStreamReader &Reader) {
912912
// The section consists of a number of subsection in the following format:
913913
// |SubSectionType|SubSectionSize|Contents...|
914914
uint32_t SubType, SubSectionSize;
915-
error(Reader.readInteger(SubType));
916-
error(Reader.readInteger(SubSectionSize));
915+
916+
if (Error E = Reader.readInteger(SubType))
917+
reportError(std::move(E), Obj->getFileName());
918+
if (Error E = Reader.readInteger(SubSectionSize))
919+
reportError(std::move(E), Obj->getFileName());
917920

918921
StringRef Contents;
919-
error(Reader.readFixedString(Contents, SubSectionSize));
922+
if (Error E = Reader.readFixedString(Contents, SubSectionSize))
923+
reportError(std::move(E), Obj->getFileName());
920924

921925
BinaryStreamRef ST(Contents, support::little);
922926
switch (DebugSubsectionKind(SubType)) {
923927
case DebugSubsectionKind::FileChecksums:
924-
error(CVFileChecksumTable.initialize(ST));
928+
if (Error E = CVFileChecksumTable.initialize(ST))
929+
reportError(std::move(E), Obj->getFileName());
925930
break;
926931
case DebugSubsectionKind::StringTable:
927-
error(CVStringTable.initialize(ST));
932+
if (Error E = CVStringTable.initialize(ST))
933+
reportError(std::move(E), Obj->getFileName());
928934
break;
929935
default:
930936
break;
931937
}
932938

933939
uint32_t PaddedSize = alignTo(SubSectionSize, 4);
934-
error(Reader.skip(PaddedSize - SubSectionSize));
940+
if (Error E = Reader.skip(PaddedSize - SubSectionSize))
941+
reportError(std::move(E), Obj->getFileName());
935942
}
936943
}
937944

@@ -949,7 +956,9 @@ void COFFDumper::printCodeViewSymbolSection(StringRef SectionName,
949956
W.printNumber("Section", SectionName, Obj->getSectionID(Section));
950957

951958
uint32_t Magic;
952-
error(consume(Data, Magic));
959+
if (Error E = consume(Data, Magic))
960+
reportError(std::move(E), Obj->getFileName());
961+
953962
W.printHex("Magic", Magic);
954963
if (Magic != COFF::DEBUG_SECTION_MAGIC)
955964
return error(object_error::parse_failed);
@@ -962,8 +971,10 @@ void COFFDumper::printCodeViewSymbolSection(StringRef SectionName,
962971
// The section consists of a number of subsection in the following format:
963972
// |SubSectionType|SubSectionSize|Contents...|
964973
uint32_t SubType, SubSectionSize;
965-
error(consume(Data, SubType));
966-
error(consume(Data, SubSectionSize));
974+
if (Error E = consume(Data, SubType))
975+
reportError(std::move(E), Obj->getFileName());
976+
if (Error E = consume(Data, SubSectionSize))
977+
reportError(std::move(E), Obj->getFileName());
967978

968979
ListScope S(W, "Subsection");
969980
// Dump the subsection as normal even if the ignore bit is set.
@@ -1038,7 +1049,8 @@ void COFFDumper::printCodeViewSymbolSection(StringRef SectionName,
10381049
BinaryStreamReader SR(Contents, llvm::support::little);
10391050

10401051
DebugFrameDataSubsectionRef FrameData;
1041-
error(FrameData.initialize(SR));
1052+
if (Error E = FrameData.initialize(SR))
1053+
reportError(std::move(E), Obj->getFileName());
10421054

10431055
StringRef LinkageName;
10441056
error(resolveSymbolName(Obj->getCOFFSection(Section), SectionContents,
@@ -1100,7 +1112,8 @@ void COFFDumper::printCodeViewSymbolSection(StringRef SectionName,
11001112
BinaryStreamReader Reader(FunctionLineTables[Name], support::little);
11011113

11021114
DebugLinesSubsectionRef LineInfo;
1103-
error(LineInfo.initialize(Reader));
1115+
if (Error E = LineInfo.initialize(Reader))
1116+
reportError(std::move(E), Obj->getFileName());
11041117

11051118
W.printHex("Flags", LineInfo.header()->Flags);
11061119
W.printHex("CodeSize", LineInfo.header()->CodeSize);
@@ -1154,9 +1167,9 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection,
11541167
error(object_error::parse_failed);
11551168
}
11561169

1157-
if (auto EC = CVSD.dump(Symbols)) {
1170+
if (Error E = CVSD.dump(Symbols)) {
11581171
W.flush();
1159-
error(std::move(EC));
1172+
reportError(std::move(E), Obj->getFileName());
11601173
}
11611174
CompilationCPUType = CVSD.getCompilationCPUType();
11621175
W.flush();
@@ -1165,7 +1178,8 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection,
11651178
void COFFDumper::printCodeViewFileChecksums(StringRef Subsection) {
11661179
BinaryStreamRef Stream(Subsection, llvm::support::little);
11671180
DebugChecksumsSubsectionRef Checksums;
1168-
error(Checksums.initialize(Stream));
1181+
if (Error E = Checksums.initialize(Stream))
1182+
reportError(std::move(E), Obj->getFileName());
11691183

11701184
for (auto &FC : Checksums) {
11711185
DictScope S(W, "FileChecksum");
@@ -1184,7 +1198,8 @@ void COFFDumper::printCodeViewFileChecksums(StringRef Subsection) {
11841198
void COFFDumper::printCodeViewInlineeLines(StringRef Subsection) {
11851199
BinaryStreamReader SR(Subsection, llvm::support::little);
11861200
DebugInlineeLinesSubsectionRef Lines;
1187-
error(Lines.initialize(SR));
1201+
if (Error E = Lines.initialize(SR))
1202+
reportError(std::move(E), Obj->getFileName());
11881203

11891204
for (auto &Line : Lines) {
11901205
DictScope S(W, "InlineeSourceLine");
@@ -1232,7 +1247,9 @@ void COFFDumper::mergeCodeViewTypes(MergingTypeTableBuilder &CVIDs,
12321247
if (SectionName == ".debug$T") {
12331248
StringRef Data = unwrapOrError(Obj->getFileName(), S.getContents());
12341249
uint32_t Magic;
1235-
error(consume(Data, Magic));
1250+
if (Error E = consume(Data, Magic))
1251+
reportError(std::move(E), Obj->getFileName());
1252+
12361253
if (Magic != 4)
12371254
error(object_error::parse_failed);
12381255

@@ -1248,14 +1265,14 @@ void COFFDumper::mergeCodeViewTypes(MergingTypeTableBuilder &CVIDs,
12481265
if (GHash) {
12491266
std::vector<GloballyHashedType> Hashes =
12501267
GloballyHashedType::hashTypes(Types);
1251-
if (auto EC =
1268+
if (Error E =
12521269
mergeTypeAndIdRecords(GlobalCVIDs, GlobalCVTypes, SourceToDest,
12531270
Types, Hashes, PCHSignature))
1254-
return error(std::move(EC));
1271+
return reportError(std::move(E), Obj->getFileName());
12551272
} else {
1256-
if (auto EC = mergeTypeAndIdRecords(CVIDs, CVTypes, SourceToDest, Types,
1273+
if (Error E = mergeTypeAndIdRecords(CVIDs, CVTypes, SourceToDest, Types,
12571274
PCHSignature))
1258-
return error(std::move(EC));
1275+
return reportError(std::move(E), Obj->getFileName());
12591276
}
12601277
}
12611278
}
@@ -1271,15 +1288,19 @@ void COFFDumper::printCodeViewTypeSection(StringRef SectionName,
12711288
W.printBinaryBlock("Data", Data);
12721289

12731290
uint32_t Magic;
1274-
error(consume(Data, Magic));
1291+
if (Error E = consume(Data, Magic))
1292+
reportError(std::move(E), Obj->getFileName());
1293+
12751294
W.printHex("Magic", Magic);
12761295
if (Magic != COFF::DEBUG_SECTION_MAGIC)
12771296
return error(object_error::parse_failed);
12781297

12791298
Types.reset(Data, 100);
12801299

12811300
TypeDumpVisitor TDV(Types, &W, opts::CodeViewSubsectionBytes);
1282-
error(codeview::visitTypeStream(Types, TDV));
1301+
if (Error E = codeview::visitTypeStream(Types, TDV))
1302+
reportError(std::move(E), Obj->getFileName());
1303+
12831304
W.flush();
12841305
}
12851306

@@ -1504,7 +1525,7 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) {
15041525
error(EC);
15051526
Expected<StringRef> Res = getSectionName(Obj, AuxNumber, Assoc);
15061527
if (!Res)
1507-
error(Res.takeError());
1528+
reportError(Res.takeError(), Obj->getFileName());
15081529
AssocName = *Res;
15091530

15101531
W.printNumber("AssocSection", AssocName, AuxNumber);
@@ -1906,7 +1927,8 @@ void llvm::dumpCodeViewMergedTypes(ScopedPrinter &Writer,
19061927
{
19071928
ListScope S(Writer, "MergedTypeStream");
19081929
TypeDumpVisitor TDV(TpiTypes, &Writer, opts::CodeViewSubsectionBytes);
1909-
error(codeview::visitTypeStream(TpiTypes, TDV));
1930+
if (Error Err = codeview::visitTypeStream(TpiTypes, TDV))
1931+
reportError(std::move(Err), "<?>");
19101932
Writer.flush();
19111933
}
19121934

@@ -1917,7 +1939,8 @@ void llvm::dumpCodeViewMergedTypes(ScopedPrinter &Writer,
19171939
ListScope S(Writer, "MergedIDStream");
19181940
TypeDumpVisitor TDV(TpiTypes, &Writer, opts::CodeViewSubsectionBytes);
19191941
TDV.setIpiTypes(IpiTypes);
1920-
error(codeview::visitTypeStream(IpiTypes, TDV));
1942+
if (Error Err = codeview::visitTypeStream(IpiTypes, TDV))
1943+
reportError(std::move(Err), "<?>");
19211944
Writer.flush();
19221945
}
19231946
}

llvm/tools/llvm-readobj/ELFDumper.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4417,7 +4417,7 @@ void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
44174417
for (const auto &Note : Obj->notes(P, Err))
44184418
ProcessNote(Note);
44194419
if (Err)
4420-
error(std::move(Err));
4420+
reportError(std::move(Err), this->FileName);
44214421
}
44224422
} else {
44234423
for (const auto &S :
@@ -4429,7 +4429,7 @@ void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
44294429
for (const auto &Note : Obj->notes(S, Err))
44304430
ProcessNote(Note);
44314431
if (Err)
4432-
error(std::move(Err));
4432+
reportError(std::move(Err), this->FileName);
44334433
}
44344434
}
44354435
}
@@ -4483,10 +4483,10 @@ void DumpStyle<ELFT>::printFunctionStackSize(
44834483
// integer.
44844484
if (*Offset == PrevOffset)
44854485
reportError(
4486-
FileStr,
44874486
createStringError(object_error::parse_failed,
44884487
"could not extract a valid stack size in section %s",
4489-
SectionName.data()));
4488+
SectionName.data()),
4489+
FileStr);
44904490

44914491
printStackSizeEntry(StackSize, FuncName);
44924492
}
@@ -4545,11 +4545,12 @@ void DumpStyle<ELFT>::printStackSize(const ELFObjectFile<ELFT> *Obj,
45454545

45464546
uint64_t Offset = Reloc.getOffset();
45474547
if (!Data.isValidOffsetForDataOfSize(Offset, sizeof(Elf_Addr) + 1))
4548-
reportError(FileStr, createStringError(
4549-
object_error::parse_failed,
4550-
"found invalid relocation offset into section %s "
4551-
"while trying to extract a stack size entry",
4552-
StackSizeSectionName.data()));
4548+
reportError(
4549+
createStringError(object_error::parse_failed,
4550+
"found invalid relocation offset into section %s "
4551+
"while trying to extract a stack size entry",
4552+
StackSizeSectionName.data()),
4553+
FileStr);
45534554

45544555
uint64_t Addend = Data.getAddress(&Offset);
45554556
uint64_t SymValue = Resolver(Reloc, RelocSymValue, Addend);
@@ -4595,11 +4596,11 @@ void DumpStyle<ELFT>::printNonRelocatableStackSizes(
45954596
// size. Check for an extra byte before we try to process the entry.
45964597
if (!Data.isValidOffsetForDataOfSize(Offset, sizeof(Elf_Addr) + 1)) {
45974598
reportError(
4598-
FileStr,
45994599
createStringError(
46004600
object_error::parse_failed,
46014601
"section %s ended while trying to extract a stack size entry",
4602-
SectionName.data()));
4602+
SectionName.data()),
4603+
FileStr);
46034604
}
46044605
uint64_t SymValue = Data.getAddress(&Offset);
46054606
printFunctionStackSize(Obj, SymValue,
@@ -4689,10 +4690,10 @@ void DumpStyle<ELFT>::printRelocatableStackSizes(
46894690
RelocSec.getName(RelocSectionName);
46904691
StringRef RelocName = EF->getRelocationTypeName(Reloc.getType());
46914692
reportError(
4692-
FileStr,
46934693
createStringError(object_error::parse_failed,
46944694
"unsupported relocation type in section %s: %s",
4695-
RelocSectionName.data(), RelocName.data()));
4695+
RelocSectionName.data(), RelocName.data()),
4696+
FileStr);
46964697
}
46974698
this->printStackSize(Obj, Reloc, FunctionSec, StackSizeSectionName,
46984699
Resolver, Data);
@@ -5568,7 +5569,7 @@ void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
55685569
for (const auto &Note : Obj->notes(P, Err))
55695570
ProcessNote(Note);
55705571
if (Err)
5571-
error(std::move(Err));
5572+
reportError(std::move(Err), this->FileName);
55725573
}
55735574
} else {
55745575
for (const auto &S : unwrapOrError(this->FileName, Obj->sections())) {
@@ -5580,7 +5581,7 @@ void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
55805581
for (const auto &Note : Obj->notes(S, Err))
55815582
ProcessNote(Note);
55825583
if (Err)
5583-
error(std::move(Err));
5584+
reportError(std::move(Err), this->FileName);
55845585
}
55855586
}
55865587
}

llvm/tools/llvm-readobj/Win64EHDumper.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ void Dumper::printRuntimeFunction(const Context &Ctx,
289289
resolveRelocation(Ctx, Section, SectionOffset + 8, XData, Offset);
290290

291291
ArrayRef<uint8_t> Contents;
292-
error(Ctx.COFF.getSectionContents(XData, Contents));
292+
if (Error E = Ctx.COFF.getSectionContents(XData, Contents))
293+
reportError(std::move(E), Ctx.COFF.getFileName());
294+
293295
if (Contents.empty())
294296
return;
295297

@@ -311,7 +313,9 @@ void Dumper::printData(const Context &Ctx) {
311313

312314
const coff_section *PData = Ctx.COFF.getCOFFSection(Section);
313315
ArrayRef<uint8_t> Contents;
314-
error(Ctx.COFF.getSectionContents(PData, Contents));
316+
317+
if (Error E = Ctx.COFF.getSectionContents(PData, Contents))
318+
reportError(std::move(E), Ctx.COFF.getFileName());
315319
if (Contents.empty())
316320
continue;
317321

0 commit comments

Comments
 (0)