diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -160,11 +160,11 @@ const uint64_t ObjSize = Obj->getMemoryBufferRef().getBufferSize(); if (Size > ObjSize - Offset) { - Dumper->reportUniqueWarning(createError( + Dumper->reportUniqueWarning( "unable to read data at 0x" + Twine::utohexstr(Offset) + " of size 0x" + Twine::utohexstr(Size) + " (" + SizePrintName + "): it goes past the end of the file of size 0x" + - Twine::utohexstr(ObjSize))); + Twine::utohexstr(ObjSize)); return {Start, Start}; } @@ -182,7 +182,7 @@ (" or " + EntSizePrintName + " (0x" + Twine::utohexstr(EntSize) + ")") .str(); - Dumper->reportUniqueWarning(createError(Msg.c_str())); + Dumper->reportUniqueWarning(Msg); return {Start, Start}; } }; @@ -522,12 +522,12 @@ } if (SymTabOrErr->first.size() != VersionsOrErr->size()) - reportUniqueWarning( - createError(describe(Sec) + ": the number of entries (" + - Twine(VersionsOrErr->size()) + - ") does not match the number of symbols (" + - Twine(SymTabOrErr->first.size()) + - ") in the symbol table with index " + Twine(Sec.sh_link))); + reportUniqueWarning(describe(Sec) + ": the number of entries (" + + Twine(VersionsOrErr->size()) + + ") does not match the number of symbols (" + + Twine(SymTabOrErr->first.size()) + + ") in the symbol table with index " + + Twine(Sec.sh_link)); if (SymTab) std::tie(*SymTab, *StrTab) = *SymTabOrErr; @@ -717,16 +717,16 @@ Obj.getStringTableForSymtab(*DotSymtabSec)) StrTable = *StrTableOrErr; else - reportUniqueWarning(createError( + reportUniqueWarning( "unable to get the string table for the SHT_SYMTAB section: " + - toString(StrTableOrErr.takeError()))); + toString(StrTableOrErr.takeError())); if (Expected SymsOrErr = Obj.symbols(DotSymtabSec)) Syms = *SymsOrErr; else reportUniqueWarning( - createError("unable to read symbols from the SHT_SYMTAB section: " + - toString(SymsOrErr.takeError()))); + "unable to read symbols from the SHT_SYMTAB section: " + + toString(SymsOrErr.takeError())); Entries = DotSymtabSec->getEntityCount(); } if (Syms.begin() == Syms.end()) @@ -800,6 +800,7 @@ virtual void printMipsABIFlags() = 0; const ELFDumper &dumper() const { return Dumper; } void reportUniqueWarning(Error Err) const; + void reportUniqueWarning(const Twine &Msg) const; protected: std::vector getGroups(); @@ -957,6 +958,11 @@ this->dumper().reportUniqueWarning(std::move(Err)); } +template +void DumpStyle::reportUniqueWarning(const Twine &Msg) const { + this->dumper().reportUniqueWarning(Msg); +} + template class LLVMStyle : public DumpStyle { public: TYPEDEF_ELF_TYPES(ELFT) @@ -1136,9 +1142,8 @@ template std::string ELFDumper::getStaticSymbolName(uint32_t Index) const { auto Warn = [&](Error E) -> std::string { - this->reportUniqueWarning( - createError("unable to read the name of symbol with index " + - Twine(Index) + ": " + toString(std::move(E)))); + this->reportUniqueWarning("unable to read the name of symbol with index " + + Twine(Index) + ": " + toString(std::move(E))); return ""; }; @@ -1877,9 +1882,9 @@ break; } } else { - this->reportUniqueWarning(createError( + this->reportUniqueWarning( "unable to read program headers to locate the PT_DYNAMIC segment: " + - toString(PhdrsOrErr.takeError()))); + toString(PhdrsOrErr.takeError())); } // Try to locate the .dynamic section in the sections header table. @@ -1895,12 +1900,12 @@ ObjF.getMemoryBufferRef().getBufferSize()) || (DynamicPhdr->p_offset + DynamicPhdr->p_filesz < DynamicPhdr->p_offset))) { - reportUniqueWarning(createError( + reportUniqueWarning( "PT_DYNAMIC segment offset (0x" + Twine::utohexstr(DynamicPhdr->p_offset) + ") + file size (0x" + Twine::utohexstr(DynamicPhdr->p_filesz) + ") exceeds the size of the file (0x" + - Twine::utohexstr(ObjF.getMemoryBufferRef().getBufferSize()) + ")")); + Twine::utohexstr(ObjF.getMemoryBufferRef().getBufferSize()) + ")"); // Don't use the broken dynamic header. DynamicPhdr = nullptr; } @@ -1909,14 +1914,13 @@ if (DynamicSec->sh_addr + DynamicSec->sh_size > DynamicPhdr->p_vaddr + DynamicPhdr->p_memsz || DynamicSec->sh_addr < DynamicPhdr->p_vaddr) - reportUniqueWarning(createError(describe(*DynamicSec) + - " is not contained within the " - "PT_DYNAMIC segment")); + reportUniqueWarning(describe(*DynamicSec) + + " is not contained within the " + "PT_DYNAMIC segment"); if (DynamicSec->sh_addr != DynamicPhdr->p_vaddr) - reportUniqueWarning(createError(describe(*DynamicSec) + - " is not at the start of " - "PT_DYNAMIC segment")); + reportUniqueWarning(describe(*DynamicSec) + " is not at the start of " + "PT_DYNAMIC segment"); } return std::make_pair(DynamicPhdr, DynamicSec); @@ -1957,9 +1961,9 @@ FromSec.EntSizePrintName = ""; IsSecTableValid = !FromSec.getAsArrayRef().empty(); } else { - reportUniqueWarning(createError("unable to read the dynamic table from " + - describe(*DynamicSec) + ": " + - toString(RegOrErr.takeError()))); + reportUniqueWarning("unable to read the dynamic table from " + + describe(*DynamicSec) + ": " + + toString(RegOrErr.takeError())); } } @@ -1970,7 +1974,7 @@ DynamicTable = DynamicPhdr ? FromPhdr : FromSec; parseDynamicTable(); } else { - reportUniqueWarning(createError("no valid dynamic table was found")); + reportUniqueWarning("no valid dynamic table was found"); } return; } @@ -1980,25 +1984,25 @@ // verify that. if (FromPhdr.Addr != FromSec.Addr) - reportUniqueWarning(createError("SHT_DYNAMIC section header and PT_DYNAMIC " - "program header disagree about " - "the location of the dynamic table")); + reportUniqueWarning("SHT_DYNAMIC section header and PT_DYNAMIC " + "program header disagree about " + "the location of the dynamic table"); if (!IsPhdrTableValid && !IsSecTableValid) { - reportUniqueWarning(createError("no valid dynamic table was found")); + reportUniqueWarning("no valid dynamic table was found"); return; } - // Information in the PT_DYNAMIC program header has priority over the information - // in a section header. + // Information in the PT_DYNAMIC program header has priority over the + // information in a section header. if (IsPhdrTableValid) { if (!IsSecTableValid) - reportUniqueWarning(createError( - "SHT_DYNAMIC dynamic table is invalid: PT_DYNAMIC will be used")); + reportUniqueWarning( + "SHT_DYNAMIC dynamic table is invalid: PT_DYNAMIC will be used"); DynamicTable = FromPhdr; } else { - reportUniqueWarning(createError( - "PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used")); + reportUniqueWarning( + "PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used"); DynamicTable = FromSec; } @@ -2042,9 +2046,9 @@ else reportWarning(E.takeError(), ObjF.getFileName()); } else { - reportUniqueWarning(createError( - "unable to read dynamic symbols from " + describe(Sec) + ": " + - toString(RegOrErr.takeError()))); + reportUniqueWarning("unable to read dynamic symbols from " + + describe(Sec) + ": " + + toString(RegOrErr.takeError())); } } break; @@ -2185,8 +2189,8 @@ else if (Dyn.getVal() == DT_RELA) DynPLTRelRegion.EntSize = sizeof(Elf_Rela); else - reportUniqueWarning(createError(Twine("unknown DT_PLTREL value of ") + - Twine((uint64_t)Dyn.getVal()))); + reportUniqueWarning(Twine("unknown DT_PLTREL value of ") + + Twine((uint64_t)Dyn.getVal())); DynPLTRelRegion.EntSizePrintName = "PLTREL entry size"; break; case ELF::DT_JMPREL: @@ -2203,10 +2207,10 @@ const uint64_t FileSize = Obj.getBufSize(); const uint64_t Offset = (const uint8_t *)StringTableBegin - Obj.base(); if (StringTableSize > FileSize - Offset) - reportUniqueWarning(createError( + reportUniqueWarning( "the dynamic string table at 0x" + Twine::utohexstr(Offset) + " goes past the end of the file (0x" + Twine::utohexstr(FileSize) + - ") with DT_STRSZ = 0x" + Twine::utohexstr(StringTableSize))); + ") with DT_STRSZ = 0x" + Twine::utohexstr(StringTableSize)); else DynamicStringTable = StringRef(StringTableBegin, StringTableSize); } @@ -2229,14 +2233,13 @@ // according to the section header. if (HashTable && IsHashTableSupported) { if (DynSymRegion->EntSize == 0) - reportUniqueWarning( - createError("SHT_DYNSYM section has sh_entsize == 0")); + reportUniqueWarning("SHT_DYNSYM section has sh_entsize == 0"); else if (HashTable->nchain != DynSymRegion->Size / DynSymRegion->EntSize) - reportUniqueWarning(createError( + reportUniqueWarning( "hash table nchain (" + Twine(HashTable->nchain) + ") differs from symbol count derived from SHT_DYNSYM section " "header (" + - Twine(DynSymRegion->Size / DynSymRegion->EntSize) + ")")); + Twine(DynSymRegion->Size / DynSymRegion->EntSize) + ")"); } } @@ -2261,11 +2264,11 @@ (uint64_t)HashTable->nchain * DynSymRegion->EntSize; const uint64_t Offset = (const uint8_t *)DynSymRegion->Addr - Obj.base(); if (DerivedSize > FileSize - Offset) - reportUniqueWarning(createError( + reportUniqueWarning( "the size (0x" + Twine::utohexstr(DerivedSize) + ") of the dynamic symbol table at 0x" + Twine::utohexstr(Offset) + ", derived from the hash table, goes past the end of the file (0x" + - Twine::utohexstr(FileSize) + ") and will be ignored")); + Twine::utohexstr(FileSize) + ") and will be ignored"); else DynSymRegion->Size = HashTable->nchain * DynSymRegion->EntSize; } @@ -2438,9 +2441,8 @@ if (*NameOrErr == Name) return &Shdr; } else { - reportUniqueWarning(createError("unable to read the name of " + - describe(Shdr) + ": " + - toString(NameOrErr.takeError()))); + reportUniqueWarning("unable to read the name of " + describe(Shdr) + + ": " + toString(NameOrErr.takeError())); } } return nullptr; @@ -2619,13 +2621,13 @@ template StringRef ELFDumper::getDynamicString(uint64_t Value) const { if (DynamicStringTable.empty() && !DynamicStringTable.data()) { - reportUniqueWarning(createError("string table was not found")); + reportUniqueWarning("string table was not found"); return ""; } auto WarnAndReturn = [this](const Twine &Msg, uint64_t Offset) { - reportUniqueWarning(createError("string table at offset 0x" + - Twine::utohexstr(Offset) + Msg)); + reportUniqueWarning("string table at offset 0x" + Twine::utohexstr(Offset) + + Msg); return ""; }; @@ -2838,10 +2840,9 @@ Expected> Chains = getGnuHashTableChains(DynSymRegion, GnuHashTable); if (!Chains) { - reportUniqueWarning( - createError("unable to dump 'Values' for the SHT_GNU_HASH " - "section: " + - toString(Chains.takeError()))); + reportUniqueWarning("unable to dump 'Values' for the SHT_GNU_HASH " + "section: " + + toString(Chains.takeError())); return; } @@ -3324,16 +3325,15 @@ Expected> ContentsOrErr = Obj.getSectionContents(*RegInfoSec); if (!ContentsOrErr) { - this->reportUniqueWarning(createError( + this->reportUniqueWarning( "unable to read the content of the .reginfo section (" + - describe(*RegInfoSec) + "): " + toString(ContentsOrErr.takeError()))); + describe(*RegInfoSec) + "): " + toString(ContentsOrErr.takeError())); return; } if (ContentsOrErr->size() < sizeof(Elf_Mips_RegInfo)) { - this->reportUniqueWarning( - createError("the .reginfo section has an invalid size (0x" + - Twine::utohexstr(ContentsOrErr->size()) + ")")); + this->reportUniqueWarning("the .reginfo section has an invalid size (0x" + + Twine::utohexstr(ContentsOrErr->size()) + ")"); return; } @@ -3422,9 +3422,9 @@ return; auto Warn = [&](Error &&E) { - this->reportUniqueWarning(createError("unable to read the stack map from " + - describe(*StackMapSection) + ": " + - toString(std::move(E)))); + this->reportUniqueWarning("unable to read the stack map from " + + describe(*StackMapSection) + ": " + + toString(std::move(E))); }; Expected> ContentOrErr = @@ -3567,19 +3567,19 @@ const Elf_Shdr &Symtab) -> StringRef { Expected StrTableOrErr = Obj.getStringTableForSymtab(Symtab); if (!StrTableOrErr) { - reportUniqueWarning(createError("unable to get the string table for " + - describe(Obj, Symtab) + ": " + - toString(StrTableOrErr.takeError()))); + reportUniqueWarning("unable to get the string table for " + + describe(Obj, Symtab) + ": " + + toString(StrTableOrErr.takeError())); return ""; } StringRef Strings = *StrTableOrErr; if (Sym.st_name >= Strings.size()) { - reportUniqueWarning(createError( - "unable to get the name of the symbol with index " + Twine(SymNdx) + - ": st_name (0x" + Twine::utohexstr(Sym.st_name) + - ") is past the end of the string table of size 0x" + - Twine::utohexstr(Strings.size()))); + reportUniqueWarning("unable to get the name of the symbol with index " + + Twine(SymNdx) + ": st_name (0x" + + Twine::utohexstr(Sym.st_name) + + ") is past the end of the string table of size 0x" + + Twine::utohexstr(Strings.size())); return ""; } @@ -3599,28 +3599,27 @@ Obj.template getEntry(**SymtabOrErr, Sec.sh_info)) Signature = GetSignature(**SymOrErr, Sec.sh_info, **SymtabOrErr); else - reportUniqueWarning(createError( - "unable to get the signature symbol for " + describe(Obj, Sec) + - ": " + toString(SymOrErr.takeError()))); + reportUniqueWarning("unable to get the signature symbol for " + + describe(Obj, Sec) + ": " + + toString(SymOrErr.takeError())); } else { - reportUniqueWarning(createError("unable to get the symbol table for " + - describe(Obj, Sec) + ": " + - toString(SymtabOrErr.takeError()))); + reportUniqueWarning("unable to get the symbol table for " + + describe(Obj, Sec) + ": " + + toString(SymtabOrErr.takeError())); } ArrayRef Data; if (Expected> ContentsOrErr = Obj.template getSectionContentsAsArray(Sec)) { if (ContentsOrErr->empty()) - reportUniqueWarning( - createError("unable to read the section group flag from the " + - describe(Obj, Sec) + ": the section is empty")); + reportUniqueWarning("unable to read the section group flag from the " + + describe(Obj, Sec) + ": the section is empty"); else Data = *ContentsOrErr; } else { - reportUniqueWarning(createError("unable to get the content of the " + - describe(Obj, Sec) + ": " + - toString(ContentsOrErr.takeError()))); + reportUniqueWarning("unable to get the content of the " + + describe(Obj, Sec) + ": " + + toString(ContentsOrErr.takeError())); } Ret.push_back({getPrintableSectionName(Sec), @@ -3640,10 +3639,10 @@ if (Expected SecOrErr = Obj.getSection(Ndx)) { GM.push_back({getPrintableSectionName(**SecOrErr), Ndx}); } else { - reportUniqueWarning( - createError("unable to get the section with index " + Twine(Ndx) + - " when dumping the " + describe(Obj, Sec) + ": " + - toString(SecOrErr.takeError()))); + reportUniqueWarning("unable to get the section with index " + + Twine(Ndx) + " when dumping the " + + describe(Obj, Sec) + ": " + + toString(SecOrErr.takeError())); GM.push_back({"", Ndx}); } } @@ -3673,11 +3672,11 @@ const GroupSection *MainGroup = Map[GM.Index]; if (MainGroup != &G) this->reportUniqueWarning( - createError("section with index " + Twine(GM.Index) + - ", included in the group section with index " + - Twine(MainGroup->Index) + - ", was also found in the group section with index " + - Twine(G.Index))); + "section with index " + Twine(GM.Index) + + ", included in the group section with index " + + Twine(MainGroup->Index) + + ", was also found in the group section with index " + + Twine(G.Index)); OS << " [" << format_decimal(GM.Index, 5) << "] " << GM.Name << "\n"; } } @@ -3692,9 +3691,9 @@ Expected> Target = this->dumper().getRelocationTarget(R, SymTab); if (!Target) - this->reportUniqueWarning(createError( - "unable to print relocation " + Twine(RelIndex) + " in " + - describe(this->Obj, Sec) + ": " + toString(Target.takeError()))); + this->reportUniqueWarning("unable to print relocation " + Twine(RelIndex) + + " in " + describe(this->Obj, Sec) + ": " + + toString(Target.takeError())); else printRelRelaReloc(R, *Target); } @@ -3815,9 +3814,9 @@ if (Expected NumOrErr = GetEntriesNum(Sec)) EntriesNum = std::to_string(*NumOrErr); else - this->reportUniqueWarning(createError( - "unable to get the number of relocations in " + - describe(this->Obj, Sec) + ": " + toString(NumOrErr.takeError()))); + this->reportUniqueWarning("unable to get the number of relocations in " + + describe(this->Obj, Sec) + ": " + + toString(NumOrErr.takeError())); uintX_t Offset = Sec.sh_offset; StringRef Name = this->getPrintableSectionName(Sec); @@ -4106,9 +4105,9 @@ if (!FirstSym) { Optional DynSymRegion = this->dumper().getDynSymRegion(); this->reportUniqueWarning( - createError(Twine("unable to print symbols for the .hash table: the " - "dynamic symbol table ") + - (DynSymRegion ? "is empty" : "was not found"))); + Twine("unable to print symbols for the .hash table: the " + "dynamic symbol table ") + + (DynSymRegion ? "is empty" : "was not found")); return; } @@ -4146,21 +4145,21 @@ const Elf_Sym *FirstSym = DynSyms.empty() ? nullptr : &DynSyms[0]; Optional DynSymRegion = this->dumper().getDynSymRegion(); if (!FirstSym) { - this->reportUniqueWarning(createError( + this->reportUniqueWarning( Twine("unable to print symbols for the .gnu.hash table: the " "dynamic symbol table ") + - (DynSymRegion ? "is empty" : "was not found"))); + (DynSymRegion ? "is empty" : "was not found")); return; } auto GetSymbol = [&](uint64_t SymIndex, uint64_t SymsTotal) -> const Elf_Sym * { if (SymIndex >= SymsTotal) { - this->reportUniqueWarning(createError( + this->reportUniqueWarning( "unable to print hashed symbol with index " + Twine(SymIndex) + ", which is greater than or equal to the number of dynamic symbols " "(" + - Twine::utohexstr(SymsTotal) + ")")); + Twine::utohexstr(SymsTotal) + ")"); return nullptr; } return FirstSym + SymIndex; @@ -4170,10 +4169,9 @@ getGnuHashTableChains(DynSymRegion, &GnuHash); ArrayRef Values; if (!ValuesOrErr) - this->reportUniqueWarning( - createError("unable to get hash values for the SHT_GNU_HASH " - "section: " + - toString(ValuesOrErr.takeError()))); + this->reportUniqueWarning("unable to get hash values for the SHT_GNU_HASH " + "section: " + + toString(ValuesOrErr.takeError())); else Values = *ValuesOrErr; @@ -4191,11 +4189,11 @@ break; if (SymIndex < GnuHash.symndx) { - this->reportUniqueWarning(createError( + this->reportUniqueWarning( "unable to read the hash value for symbol with index " + Twine(SymIndex) + ", which is less than the index of the first hashed symbol (" + - Twine(GnuHash.symndx) + ")")); + Twine(GnuHash.symndx) + ")"); break; } @@ -4455,8 +4453,8 @@ Expected> PhdrsOrErr = this->Obj.program_headers(); if (!PhdrsOrErr) { - this->reportUniqueWarning(createError("unable to dump program headers: " + - toString(PhdrsOrErr.takeError()))); + this->reportUniqueWarning("unable to dump program headers: " + + toString(PhdrsOrErr.takeError())); return; } @@ -4509,9 +4507,9 @@ Expected> PhdrsOrErr = this->Obj.program_headers(); if (!PhdrsOrErr) { - this->reportUniqueWarning(createError( + this->reportUniqueWarning( "can't read program headers to build section to segment mapping: " + - toString(PhdrsOrErr.takeError()))); + toString(PhdrsOrErr.takeError())); return; } @@ -4710,9 +4708,9 @@ this->Obj.getSection(Sec.sh_link)) LinkedSecName = this->getPrintableSectionName(**LinkedSecOrErr); else - this->reportUniqueWarning( - createError("invalid section linked to " + describe(this->Obj, Sec) + - ": " + toString(LinkedSecOrErr.takeError()))); + this->reportUniqueWarning("invalid section linked to " + + describe(this->Obj, Sec) + ": " + + toString(LinkedSecOrErr.takeError())); OS << " Addr: " << format_hex_no_prefix(Sec.sh_addr, 16) << " Offset: " << format_hex(Sec.sh_offset, 8) @@ -4747,9 +4745,9 @@ Expected NameOrErr = this->dumper().getSymbolVersionByIndex(Ndx, IsDefault); if (!NameOrErr) { - this->reportUniqueWarning(createError( - "unable to get a version for entry " + Twine(I) + " of " + - describe(this->Obj, *Sec) + ": " + toString(NameOrErr.takeError()))); + this->reportUniqueWarning("unable to get a version for entry " + + Twine(I) + " of " + describe(this->Obj, *Sec) + + ": " + toString(NameOrErr.takeError())); Versions.emplace_back(""); continue; } @@ -4906,9 +4904,8 @@ Expected> ChainsOrErr = getGnuHashTableChains( this->dumper().getDynSymRegion(), &GnuHashTable); if (!ChainsOrErr) { - this->reportUniqueWarning( - createError("unable to print the GNU hash table histogram: " + - toString(ChainsOrErr.takeError()))); + this->reportUniqueWarning("unable to print the GNU hash table histogram: " + + toString(ChainsOrErr.takeError())); return; } @@ -5542,9 +5539,9 @@ for (const typename ELFT::Note Note : Obj.notes(S, Err)) ProcessNoteFn(Note); if (Err) - Dumper.reportUniqueWarning( - createError("unable to read notes from the " + describe(Obj, S) + - ": " + toString(std::move(Err)))); + Dumper.reportUniqueWarning("unable to read notes from the " + + describe(Obj, S) + ": " + + toString(std::move(Err))); FinishNotesFn(); } return; @@ -5552,9 +5549,9 @@ Expected> PhdrsOrErr = Obj.program_headers(); if (!PhdrsOrErr) { - Dumper.reportUniqueWarning(createError( + Dumper.reportUniqueWarning( "unable to read program headers to locate the PT_NOTE segment: " + - toString(PhdrsOrErr.takeError()))); + toString(PhdrsOrErr.takeError())); return; } @@ -5568,9 +5565,9 @@ for (const typename ELFT::Note Note : Obj.notes(P, Err)) ProcessNoteFn(Note); if (Err) - Dumper.reportUniqueWarning(createError( + Dumper.reportUniqueWarning( "unable to read notes from the PT_NOTE segment with index " + - Twine(I) + ": " + toString(std::move(Err)))); + Twine(I) + ": " + toString(std::move(Err))); FinishNotesFn(); } } @@ -5649,9 +5646,8 @@ function_ref OnSectionStart, function_ref OnLibEntry) { auto Warn = [this](unsigned SecNdx, StringRef Msg) { - this->reportUniqueWarning( - createError("SHT_LLVM_DEPENDENT_LIBRARIES section at index " + - Twine(SecNdx) + " is broken: " + Msg)); + this->reportUniqueWarning("SHT_LLVM_DEPENDENT_LIBRARIES section at index " + + Twine(SecNdx) + " is broken: " + Msg); }; unsigned I = -1; @@ -5691,8 +5687,8 @@ llvm::function_ref RelrFn) { auto Warn = [&](Error &&E, const Twine &Prefix = "unable to read relocations from") { - this->reportUniqueWarning(createError(Prefix + " " + describe(Obj, Sec) + - ": " + toString(std::move(E)))); + this->reportUniqueWarning(Prefix + " " + describe(Obj, Sec) + ": " + + toString(std::move(E))); }; // SHT_RELR/SHT_ANDROID_RELR sections do not have an associated symbol table. @@ -5764,9 +5760,9 @@ Obj.getSectionName(Sec, this->dumper().WarningHandler)) Name = *SecNameOrErr; else - this->reportUniqueWarning(createError("unable to get the name of " + - describe(Obj, Sec) + ": " + - toString(SecNameOrErr.takeError()))); + this->reportUniqueWarning("unable to get the name of " + + describe(Obj, Sec) + ": " + + toString(SecNameOrErr.takeError())); return Name; } @@ -5892,10 +5888,9 @@ Expected> TargetOrErr = this->dumper().getRelocationTarget(R, SymTab); if (!TargetOrErr) - reportUniqueWarning( - createError("unable to get the target of relocation with index " + - Twine(Ndx) + " in " + describe(Obj, RelocSec) + ": " + - toString(TargetOrErr.takeError()))); + reportUniqueWarning("unable to get the target of relocation with index " + + Twine(Ndx) + " in " + describe(Obj, RelocSec) + ": " + + toString(TargetOrErr.takeError())); else Sym = TargetOrErr->Sym; @@ -5904,13 +5899,12 @@ Expected SectionOrErr = this->Obj.getSection(*Sym, SymTab, this->dumper().getShndxTable()); if (!SectionOrErr) { - reportUniqueWarning(createError( + reportUniqueWarning( "cannot identify the section for relocation symbol '" + - (*TargetOrErr).Name + "': " + toString(SectionOrErr.takeError()))); + (*TargetOrErr).Name + "': " + toString(SectionOrErr.takeError())); } else if (*SectionOrErr != FunctionSec) { - reportUniqueWarning(createError("relocation symbol '" + - (*TargetOrErr).Name + - "' is not in the expected section")); + reportUniqueWarning("relocation symbol '" + (*TargetOrErr).Name + + "' is not in the expected section"); // Pretend that the symbol is in the correct section and report its // stack size anyway. FunctionSec = *SectionOrErr; @@ -5921,11 +5915,10 @@ uint64_t Offset = R.Offset; if (!Data.isValidOffsetForDataOfSize(Offset, sizeof(Elf_Addr) + 1)) { - reportUniqueWarning(createStringError( - object_error::parse_failed, - "found invalid relocation offset (0x" + Twine::utohexstr(Offset) + - ") into " + describe(Obj, StackSizeSec) + - " while trying to extract a stack size entry")); + reportUniqueWarning("found invalid relocation offset (0x" + + Twine::utohexstr(Offset) + ") into " + + describe(Obj, StackSizeSec) + + " while trying to extract a stack size entry"); return; } @@ -5953,10 +5946,9 @@ // The function address is followed by a ULEB representing the stack // size. Check for an extra byte before we try to process the entry. if (!Data.isValidOffsetForDataOfSize(Offset, sizeof(Elf_Addr) + 1)) { - reportUniqueWarning(createStringError( - object_error::parse_failed, + reportUniqueWarning( describe(Obj, Sec) + - " ended while trying to extract a stack size entry")); + " ended while trying to extract a stack size entry"); break; } uint64_t SymValue = Data.getAddress(&Offset); @@ -5994,10 +5986,9 @@ Expected RelSecOrErr = Obj.getSection(Sec.sh_info); if (!RelSecOrErr) { - reportUniqueWarning(createStringError( - object_error::parse_failed, - describe(Obj, Sec) + ": failed to get a relocated section: " + - toString(RelSecOrErr.takeError()))); + reportUniqueWarning(describe(Obj, Sec) + + ": failed to get a relocated section: " + + toString(RelSecOrErr.takeError())); continue; } @@ -6042,11 +6033,10 @@ [&](const Relocation &R, unsigned Ndx, const Elf_Shdr &Sec, const Elf_Shdr *SymTab) { if (!IsSupportedFn || !IsSupportedFn(R.Type)) { - reportUniqueWarning(createStringError( - object_error::parse_failed, + reportUniqueWarning( describe(Obj, *RelocSec) + - " contains an unsupported relocation with index " + - Twine(Ndx) + ": " + Obj.getRelocationTypeName(R.Type))); + " contains an unsupported relocation with index " + Twine(Ndx) + + ": " + Obj.getRelocationTypeName(R.Type)); return; } @@ -6339,11 +6329,11 @@ const GroupSection *MainGroup = Map[GM.Index]; if (MainGroup != &G) this->reportUniqueWarning( - createError("section with index " + Twine(GM.Index) + - ", included in the group section with index " + - Twine(MainGroup->Index) + - ", was also found in the group section with index " + - Twine(G.Index))); + "section with index " + Twine(GM.Index) + + ", included in the group section with index " + + Twine(MainGroup->Index) + + ", was also found in the group section with index " + + Twine(G.Index)); W.startLine() << GM.Name << " (" << GM.Index << ")\n"; } } @@ -6379,9 +6369,9 @@ Expected> Target = this->dumper().getRelocationTarget(R, SymTab); if (!Target) { - this->reportUniqueWarning(createError( - "unable to print relocation " + Twine(RelIndex) + " in " + - describe(this->Obj, Sec) + ": " + toString(Target.takeError()))); + this->reportUniqueWarning("unable to print relocation " + Twine(RelIndex) + + " in " + describe(this->Obj, Sec) + ": " + + toString(Target.takeError())); return; } @@ -6633,8 +6623,8 @@ Expected> PhdrsOrErr = this->Obj.program_headers(); if (!PhdrsOrErr) { - this->reportUniqueWarning(createError("unable to dump program headers: " + - toString(PhdrsOrErr.takeError()))); + this->reportUniqueWarning("unable to dump program headers: " + + toString(PhdrsOrErr.takeError())); return; } @@ -6753,8 +6743,8 @@ *this->dumper().getDotCGProfileSec()); if (!CGProfileOrErr) { this->reportUniqueWarning( - createError("unable to dump the SHT_LLVM_CALL_GRAPH_PROFILE section: " + - toString(CGProfileOrErr.takeError()))); + "unable to dump the SHT_LLVM_CALL_GRAPH_PROFILE section: " + + toString(CGProfileOrErr.takeError())); return; } @@ -6903,31 +6893,30 @@ Expected> ContentsOrErr = this->Obj.getSectionContents(Shdr); if (!ContentsOrErr) { - this->reportUniqueWarning( - createError("unable to read the content of the " - "SHT_LLVM_LINKER_OPTIONS section: " + - toString(ContentsOrErr.takeError()))); + this->reportUniqueWarning("unable to read the content of the " + "SHT_LLVM_LINKER_OPTIONS section: " + + toString(ContentsOrErr.takeError())); continue; } if (ContentsOrErr->empty()) continue; if (ContentsOrErr->back() != 0) { - this->reportUniqueWarning( - createError("SHT_LLVM_LINKER_OPTIONS section at index " + Twine(I) + - " is broken: the " - "content is not null-terminated")); + this->reportUniqueWarning("SHT_LLVM_LINKER_OPTIONS section at index " + + Twine(I) + + " is broken: the " + "content is not null-terminated"); continue; } SmallVector Strings; toStringRef(ContentsOrErr->drop_back()).split(Strings, '\0'); if (Strings.size() % 2 != 0) { - this->reportUniqueWarning(createError( + this->reportUniqueWarning( "SHT_LLVM_LINKER_OPTIONS section at index " + Twine(I) + " is broken: an incomplete " "key-value pair was found. The last possible key was: \"" + - Strings.back() + "\"")); + Strings.back() + "\""); continue; } diff --git a/llvm/tools/llvm-readobj/ObjDumper.h b/llvm/tools/llvm-readobj/ObjDumper.h --- a/llvm/tools/llvm-readobj/ObjDumper.h +++ b/llvm/tools/llvm-readobj/ObjDumper.h @@ -113,6 +113,7 @@ std::function WarningHandler; void reportUniqueWarning(Error Err) const; + void reportUniqueWarning(const Twine &Msg) const; protected: ScopedPrinter &W; diff --git a/llvm/tools/llvm-readobj/ObjDumper.cpp b/llvm/tools/llvm-readobj/ObjDumper.cpp --- a/llvm/tools/llvm-readobj/ObjDumper.cpp +++ b/llvm/tools/llvm-readobj/ObjDumper.cpp @@ -39,10 +39,12 @@ ObjDumper::~ObjDumper() {} void ObjDumper::reportUniqueWarning(Error Err) const { - handleAllErrors(std::move(Err), [&](const ErrorInfoBase &EI) { - cantFail(WarningHandler(EI.message()), - "WarningHandler should always return ErrorSuccess"); - }); + reportUniqueWarning(toString(std::move(Err))); +} + +void ObjDumper::reportUniqueWarning(const Twine &Msg) const { + cantFail(WarningHandler(Msg), + "WarningHandler should always return ErrorSuccess"); } static void printAsPrintable(raw_ostream &W, const uint8_t *Start, size_t Len) {