Index: test/tools/llvm-readobj/gnu-notes.test =================================================================== --- test/tools/llvm-readobj/gnu-notes.test +++ test/tools/llvm-readobj/gnu-notes.test @@ -79,10 +79,10 @@ ## that goes past the end of file. # RUN: yaml2obj --docnum=2 %s > %t2.so -# RUN: not llvm-readelf --notes %t2.so 2>&1 | FileCheck %s --check-prefix=ERR1 -# RUN: not llvm-readobj --notes %t2.so 2>&1 | FileCheck %s --check-prefix=ERR1 +# RUN: not llvm-readelf --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1 +# RUN: not llvm-readobj --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1 -# ERR1: error: SHT_NOTE section [index 1] has invalid offset (0xffff0000) or size (0x0) +# ERR1: error: '[[FILE]]': SHT_NOTE section [index 1] has invalid offset (0xffff0000) or size (0x0) --- !ELF FileHeader: @@ -99,10 +99,10 @@ ## that goes past the end of file. # RUN: yaml2obj --docnum=3 %s > %t3.so -# RUN: not llvm-readelf --notes %t3.so 2>&1 | FileCheck %s --check-prefix=ERR2 -# RUN: not llvm-readobj --notes %t3.so 2>&1 | FileCheck %s --check-prefix=ERR2 +# RUN: not llvm-readelf --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2 +# RUN: not llvm-readobj --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2 -# ERR2: error: SHT_NOTE section [index 1] has invalid offset (0x180) or size (0xffff0000) +# ERR2: error: '[[FILE]]': SHT_NOTE section [index 1] has invalid offset (0x180) or size (0xffff0000) --- !ELF FileHeader: @@ -119,10 +119,10 @@ ## goes past the end of file. # RUN: yaml2obj --docnum=4 %s > %t4.so -# RUN: not llvm-readelf --notes %t4.so 2>&1 | FileCheck %s --check-prefix=ERR3 -# RUN: not llvm-readobj --notes %t4.so 2>&1 | FileCheck %s --check-prefix=ERR3 +# RUN: not llvm-readelf --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3 +# RUN: not llvm-readobj --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3 -# ERR3: error: PT_NOTE header has invalid offset (0xffff0000) or size (0x0) +# ERR3: error: '[[FILE]]': PT_NOTE header has invalid offset (0xffff0000) or size (0x0) --- !ELF FileHeader: @@ -143,10 +143,10 @@ ## goes past the end of file. # RUN: yaml2obj --docnum=5 %s > %t5.so -# RUN: not llvm-readelf --notes %t5.so 2>&1 | FileCheck %s --check-prefix=ERR4 -# RUN: not llvm-readobj --notes %t5.so 2>&1 | FileCheck %s --check-prefix=ERR4 +# RUN: not llvm-readelf --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4 +# RUN: not llvm-readobj --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4 -# ERR4: error: PT_NOTE header has invalid offset (0x1b8) or size (0xffff0000) +# ERR4: error: '[[FILE]]': PT_NOTE header has invalid offset (0x1b8) or size (0xffff0000) --- !ELF FileHeader: Index: tools/llvm-readobj/ARMEHABIPrinter.h =================================================================== --- tools/llvm-readobj/ARMEHABIPrinter.h +++ tools/llvm-readobj/ARMEHABIPrinter.h @@ -370,7 +370,7 @@ return readobj_error::unknown_symbol; auto StrTableOrErr = ELF->getStringTableForSymtab(*Symtab); if (!StrTableOrErr) - error(StrTableOrErr.takeError()); + reportError(FileName, StrTableOrErr.takeError()); StringRef StrTable = *StrTableOrErr; for (const Elf_Sym &Sym : unwrapOrError(FileName, ELF->symbols(Symtab))) @@ -405,7 +405,7 @@ auto SymTabOrErr = ELF->getSection(Sec.sh_link); if (!SymTabOrErr) - error(SymTabOrErr.takeError()); + reportError(FileName, SymTabOrErr.takeError()); const Elf_Shdr *SymTab = *SymTabOrErr; for (const Elf_Rel &R : unwrapOrError(FileName, ELF->rels(&Sec))) { Index: tools/llvm-readobj/COFFDumper.cpp =================================================================== --- tools/llvm-readobj/COFFDumper.cpp +++ tools/llvm-readobj/COFFDumper.cpp @@ -912,26 +912,27 @@ // The section consists of a number of subsection in the following format: // |SubSectionType|SubSectionSize|Contents...| uint32_t SubType, SubSectionSize; - error(Reader.readInteger(SubType)); - error(Reader.readInteger(SubSectionSize)); + reportError(Obj->getFileName(), Reader.readInteger(SubType)); + reportError(Obj->getFileName(), Reader.readInteger(SubSectionSize)); StringRef Contents; - error(Reader.readFixedString(Contents, SubSectionSize)); + reportError(Obj->getFileName(), + Reader.readFixedString(Contents, SubSectionSize)); BinaryStreamRef ST(Contents, support::little); switch (DebugSubsectionKind(SubType)) { case DebugSubsectionKind::FileChecksums: - error(CVFileChecksumTable.initialize(ST)); + reportError(Obj->getFileName(), CVFileChecksumTable.initialize(ST)); break; case DebugSubsectionKind::StringTable: - error(CVStringTable.initialize(ST)); + reportError(Obj->getFileName(), CVStringTable.initialize(ST)); break; default: break; } uint32_t PaddedSize = alignTo(SubSectionSize, 4); - error(Reader.skip(PaddedSize - SubSectionSize)); + reportError(Obj->getFileName(), Reader.skip(PaddedSize - SubSectionSize)); } } @@ -949,7 +950,7 @@ W.printNumber("Section", SectionName, Obj->getSectionID(Section)); uint32_t Magic; - error(consume(Data, Magic)); + reportError(Obj->getFileName(), consume(Data, Magic)); W.printHex("Magic", Magic); if (Magic != COFF::DEBUG_SECTION_MAGIC) return error(object_error::parse_failed); @@ -962,8 +963,8 @@ // The section consists of a number of subsection in the following format: // |SubSectionType|SubSectionSize|Contents...| uint32_t SubType, SubSectionSize; - error(consume(Data, SubType)); - error(consume(Data, SubSectionSize)); + reportError(Obj->getFileName(), consume(Data, SubType)); + reportError(Obj->getFileName(), consume(Data, SubSectionSize)); ListScope S(W, "Subsection"); // Dump the subsection as normal even if the ignore bit is set. @@ -1038,7 +1039,7 @@ BinaryStreamReader SR(Contents, llvm::support::little); DebugFrameDataSubsectionRef FrameData; - error(FrameData.initialize(SR)); + reportError(Obj->getFileName(), FrameData.initialize(SR)); StringRef LinkageName; error(resolveSymbolName(Obj->getCOFFSection(Section), SectionContents, @@ -1100,7 +1101,7 @@ BinaryStreamReader Reader(FunctionLineTables[Name], support::little); DebugLinesSubsectionRef LineInfo; - error(LineInfo.initialize(Reader)); + reportError(Obj->getFileName(), LineInfo.initialize(Reader)); W.printHex("Flags", LineInfo.header()->Flags); W.printHex("CodeSize", LineInfo.header()->CodeSize); @@ -1156,7 +1157,7 @@ if (auto EC = CVSD.dump(Symbols)) { W.flush(); - error(std::move(EC)); + reportError(Obj->getFileName(), std::move(EC)); } CompilationCPUType = CVSD.getCompilationCPUType(); W.flush(); @@ -1165,7 +1166,7 @@ void COFFDumper::printCodeViewFileChecksums(StringRef Subsection) { BinaryStreamRef Stream(Subsection, llvm::support::little); DebugChecksumsSubsectionRef Checksums; - error(Checksums.initialize(Stream)); + reportError(Obj->getFileName(), Checksums.initialize(Stream)); for (auto &FC : Checksums) { DictScope S(W, "FileChecksum"); @@ -1184,7 +1185,7 @@ void COFFDumper::printCodeViewInlineeLines(StringRef Subsection) { BinaryStreamReader SR(Subsection, llvm::support::little); DebugInlineeLinesSubsectionRef Lines; - error(Lines.initialize(SR)); + reportError(Obj->getFileName(), Lines.initialize(SR)); for (auto &Line : Lines) { DictScope S(W, "InlineeSourceLine"); @@ -1232,7 +1233,7 @@ if (SectionName == ".debug$T") { StringRef Data = unwrapOrError(Obj->getFileName(), S.getContents()); uint32_t Magic; - error(consume(Data, Magic)); + reportError(Obj->getFileName(), consume(Data, Magic)); if (Magic != 4) error(object_error::parse_failed); @@ -1251,11 +1252,11 @@ if (auto EC = mergeTypeAndIdRecords(GlobalCVIDs, GlobalCVTypes, SourceToDest, Types, Hashes, PCHSignature)) - return error(std::move(EC)); + return reportError(Obj->getFileName(), std::move(EC)); } else { if (auto EC = mergeTypeAndIdRecords(CVIDs, CVTypes, SourceToDest, Types, PCHSignature)) - return error(std::move(EC)); + return reportError(Obj->getFileName(), std::move(EC)); } } } @@ -1271,7 +1272,7 @@ W.printBinaryBlock("Data", Data); uint32_t Magic; - error(consume(Data, Magic)); + reportError(Obj->getFileName(), consume(Data, Magic)); W.printHex("Magic", Magic); if (Magic != COFF::DEBUG_SECTION_MAGIC) return error(object_error::parse_failed); @@ -1279,7 +1280,7 @@ Types.reset(Data, 100); TypeDumpVisitor TDV(Types, &W, opts::CodeViewSubsectionBytes); - error(codeview::visitTypeStream(Types, TDV)); + reportError(Obj->getFileName(), codeview::visitTypeStream(Types, TDV)); W.flush(); } @@ -1504,7 +1505,7 @@ error(EC); Expected Res = getSectionName(Obj, AuxNumber, Assoc); if (!Res) - error(Res.takeError()); + reportError(Obj->getFileName(), Res.takeError()); AssocName = *Res; W.printNumber("AssocSection", AssocName, AuxNumber); @@ -1906,7 +1907,8 @@ { ListScope S(Writer, "MergedTypeStream"); TypeDumpVisitor TDV(TpiTypes, &Writer, opts::CodeViewSubsectionBytes); - error(codeview::visitTypeStream(TpiTypes, TDV)); + if (Error Err = codeview::visitTypeStream(TpiTypes, TDV)) + reportError("", std::move(Err)); Writer.flush(); } @@ -1917,7 +1919,8 @@ ListScope S(Writer, "MergedIDStream"); TypeDumpVisitor TDV(TpiTypes, &Writer, opts::CodeViewSubsectionBytes); TDV.setIpiTypes(IpiTypes); - error(codeview::visitTypeStream(IpiTypes, TDV)); + if (Error Err = codeview::visitTypeStream(IpiTypes, TDV)) + reportError("", std::move(Err)); Writer.flush(); } } Index: tools/llvm-readobj/ELFDumper.cpp =================================================================== --- tools/llvm-readobj/ELFDumper.cpp +++ tools/llvm-readobj/ELFDumper.cpp @@ -4415,7 +4415,7 @@ for (const auto &Note : Obj->notes(P, Err)) ProcessNote(Note); if (Err) - error(std::move(Err)); + reportError(this->FileName, std::move(Err)); } } else { for (const auto &S : @@ -4427,7 +4427,7 @@ for (const auto &Note : Obj->notes(S, Err)) ProcessNote(Note); if (Err) - error(std::move(Err)); + reportError(this->FileName, std::move(Err)); } } } @@ -5565,8 +5565,7 @@ Error Err = Error::success(); for (const auto &Note : Obj->notes(P, Err)) ProcessNote(Note); - if (Err) - error(std::move(Err)); + reportError(this->FileName, std::move(Err)); } } else { for (const auto &S : unwrapOrError(this->FileName, Obj->sections())) { @@ -5577,8 +5576,7 @@ Error Err = Error::success(); for (const auto &Note : Obj->notes(S, Err)) ProcessNote(Note); - if (Err) - error(std::move(Err)); + reportError(this->FileName, std::move(Err)); } } } Index: tools/llvm-readobj/Win64EHDumper.cpp =================================================================== --- tools/llvm-readobj/Win64EHDumper.cpp +++ tools/llvm-readobj/Win64EHDumper.cpp @@ -289,7 +289,8 @@ resolveRelocation(Ctx, Section, SectionOffset + 8, XData, Offset); ArrayRef Contents; - error(Ctx.COFF.getSectionContents(XData, Contents)); + reportError(Ctx.COFF.getFileName(), + Ctx.COFF.getSectionContents(XData, Contents)); if (Contents.empty()) return; @@ -311,7 +312,8 @@ const coff_section *PData = Ctx.COFF.getCOFFSection(Section); ArrayRef Contents; - error(Ctx.COFF.getSectionContents(PData, Contents)); + reportError(Ctx.COFF.getFileName(), + Ctx.COFF.getSectionContents(PData, Contents)); if (Contents.empty()) continue; Index: tools/llvm-readobj/llvm-readobj.h =================================================================== --- tools/llvm-readobj/llvm-readobj.h +++ tools/llvm-readobj/llvm-readobj.h @@ -27,7 +27,6 @@ void reportWarning(StringRef Input, Error Err); void warn(llvm::Error Err); void error(std::error_code EC); - void error(llvm::Error EC); template T unwrapOrError(StringRef Input, Expected EO) { if (EO) Index: tools/llvm-readobj/llvm-readobj.cpp =================================================================== --- tools/llvm-readobj/llvm-readobj.cpp +++ tools/llvm-readobj/llvm-readobj.cpp @@ -383,9 +383,12 @@ } void reportError(StringRef Input, Error Err) { + if (!Err) + return; if (Input == "-") Input = ""; - error(createFileError(Input, std::move(Err))); + handleAllErrors(createFileError(Input, std::move(Err)), + [&](const ErrorInfoBase &EI) { reportError(EI.message()); }); } void reportWarning(Twine Msg) { @@ -406,13 +409,6 @@ }); } -void error(Error EC) { - if (!EC) - return; - handleAllErrors(std::move(EC), - [&](const ErrorInfoBase &EI) { reportError(EI.message()); }); -} - void error(std::error_code EC) { if (!EC) return;