30 changes: 15 additions & 15 deletions llvm/tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,22 +608,22 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,

const ELFFile<ELFT> &EF = *Obj->getELFFile();

ErrorOr<const Elf_Shdr *> SecOrErr = EF.getSection(Rel.d.a);
if (std::error_code EC = SecOrErr.getError())
return EC;
auto SecOrErr = EF.getSection(Rel.d.a);
if (!SecOrErr)
return errorToErrorCode(SecOrErr.takeError());
const Elf_Shdr *Sec = *SecOrErr;
ErrorOr<const Elf_Shdr *> SymTabOrErr = EF.getSection(Sec->sh_link);
if (std::error_code EC = SymTabOrErr.getError())
return EC;
auto SymTabOrErr = EF.getSection(Sec->sh_link);
if (!SymTabOrErr)
return errorToErrorCode(SymTabOrErr.takeError());
const Elf_Shdr *SymTab = *SymTabOrErr;
assert(SymTab->sh_type == ELF::SHT_SYMTAB ||
SymTab->sh_type == ELF::SHT_DYNSYM);
ErrorOr<const Elf_Shdr *> StrTabSec = EF.getSection(SymTab->sh_link);
if (std::error_code EC = StrTabSec.getError())
return EC;
ErrorOr<StringRef> StrTabOrErr = EF.getStringTable(*StrTabSec);
if (std::error_code EC = StrTabOrErr.getError())
return EC;
auto StrTabSec = EF.getSection(SymTab->sh_link);
if (!StrTabSec)
return errorToErrorCode(StrTabSec.takeError());
auto StrTabOrErr = EF.getStringTable(*StrTabSec);
if (!StrTabOrErr)
return errorToErrorCode(StrTabOrErr.takeError());
StringRef StrTab = *StrTabOrErr;
uint8_t type = RelRef.getType();
StringRef res;
Expand All @@ -649,9 +649,9 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
if (!SymSI)
return errorToErrorCode(SymSI.takeError());
const Elf_Shdr *SymSec = Obj->getSection((*SymSI)->getRawDataRefImpl());
ErrorOr<StringRef> SecName = EF.getSectionName(SymSec);
if (std::error_code EC = SecName.getError())
return EC;
auto SecName = EF.getSectionName(SymSec);
if (!SecName)
return errorToErrorCode(SecName.takeError());
Target = *SecName;
} else {
Expected<StringRef> SymName = symb->getName(StrTab);
Expand Down
25 changes: 13 additions & 12 deletions llvm/tools/llvm-readobj/ARMEHABIPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,9 @@ template <typename ET>
ErrorOr<StringRef>
PrinterContext<ET>::FunctionAtAddress(unsigned Section,
uint64_t Address) const {
ErrorOr<StringRef> StrTableOrErr = ELF->getStringTableForSymtab(*Symtab);
error(StrTableOrErr.getError());
auto StrTableOrErr = ELF->getStringTableForSymtab(*Symtab);
if (!StrTableOrErr)
error(StrTableOrErr.takeError());
StringRef StrTable = *StrTableOrErr;

for (const Elf_Sym &Sym : unwrapOrError(ELF->symbols(Symtab)))
Expand Down Expand Up @@ -383,8 +384,9 @@ PrinterContext<ET>::FindExceptionTable(unsigned IndexSectionIndex,
if (Sec.sh_type != ELF::SHT_REL || Sec.sh_info != IndexSectionIndex)
continue;

ErrorOr<const Elf_Shdr *> SymTabOrErr = ELF->getSection(Sec.sh_link);
error(SymTabOrErr.getError());
auto SymTabOrErr = ELF->getSection(Sec.sh_link);
if (!SymTabOrErr)
error(SymTabOrErr.takeError());
const Elf_Shdr *SymTab = *SymTabOrErr;

for (const Elf_Rel &R : unwrapOrError(ELF->rels(&Sec))) {
Expand All @@ -399,10 +401,9 @@ PrinterContext<ET>::FindExceptionTable(unsigned IndexSectionIndex,
const Elf_Sym *Symbol =
unwrapOrError(ELF->getRelocationSymbol(&RelA, SymTab));

ErrorOr<const Elf_Shdr *> Ret =
ELF->getSection(Symbol, SymTab, ShndxTable);
if (std::error_code EC = Ret.getError())
report_fatal_error(EC.message());
auto Ret = ELF->getSection(Symbol, SymTab, ShndxTable);
if (!Ret)
report_fatal_error(errorToErrorCode(Ret.takeError()).message());
return *Ret;
}
}
Expand All @@ -413,7 +414,7 @@ template <typename ET>
void PrinterContext<ET>::PrintExceptionTable(const Elf_Shdr *IT,
const Elf_Shdr *EHT,
uint64_t TableEntryOffset) const {
ErrorOr<ArrayRef<uint8_t> > Contents = ELF->getSectionContents(EHT);
Expected<ArrayRef<uint8_t>> Contents = ELF->getSectionContents(EHT);
if (!Contents)
return;

Expand Down Expand Up @@ -480,7 +481,7 @@ void PrinterContext<ET>::PrintOpcodes(const uint8_t *Entry,
template <typename ET>
void PrinterContext<ET>::PrintIndexTable(unsigned SectionIndex,
const Elf_Shdr *IT) const {
ErrorOr<ArrayRef<uint8_t> > Contents = ELF->getSectionContents(IT);
Expected<ArrayRef<uint8_t>> Contents = ELF->getSectionContents(IT);
if (!Contents)
return;

Expand Down Expand Up @@ -533,7 +534,7 @@ void PrinterContext<ET>::PrintIndexTable(unsigned SectionIndex,
const Elf_Shdr *EHT =
FindExceptionTable(SectionIndex, Entry * IndexTableEntrySize + 4);

if (ErrorOr<StringRef> Name = ELF->getSectionName(EHT))
if (auto Name = ELF->getSectionName(EHT))
SW.printString("ExceptionHandlingTable", *Name);

uint64_t TableEntryOffset = PREL31(Word1, IT->sh_addr);
Expand All @@ -554,7 +555,7 @@ void PrinterContext<ET>::PrintUnwindInformation() const {
DictScope UIT(SW, "UnwindIndexTable");

SW.printNumber("SectionIndex", SectionIndex);
if (ErrorOr<StringRef> SectionName = ELF->getSectionName(&Sec))
if (auto SectionName = ELF->getSectionName(&Sec))
SW.printString("SectionName", *SectionName);
SW.printHex("SectionOffset", Sec.sh_offset);

Expand Down
142 changes: 71 additions & 71 deletions llvm/tools/obj2yaml/elf2yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {

// Dump sections
auto SectionsOrErr = Obj.sections();
if (std::error_code EC = SectionsOrErr.getError())
return EC;
if (!SectionsOrErr)
return errorToErrorCode(SectionsOrErr.takeError());
for (const Elf_Shdr &Sec : *SectionsOrErr) {
switch (Sec.sh_type) {
case ELF::SHT_NULL:
Expand All @@ -88,9 +88,9 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
Symtab = &Sec;
break;
case ELF::SHT_SYMTAB_SHNDX: {
ErrorOr<ArrayRef<Elf_Word>> TableOrErr = Obj.getSHNDXTable(Sec);
if (std::error_code EC = TableOrErr.getError())
return EC;
auto TableOrErr = Obj.getSHNDXTable(Sec);
if (!TableOrErr)
return errorToErrorCode(TableOrErr.takeError());
ShndxTable = *TableOrErr;
break;
}
Expand Down Expand Up @@ -139,15 +139,15 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
}

// Dump symbols
ErrorOr<StringRef> StrTableOrErr = Obj.getStringTableForSymtab(*Symtab);
if (std::error_code EC = StrTableOrErr.getError())
return EC;
auto StrTableOrErr = Obj.getStringTableForSymtab(*Symtab);
if (!StrTableOrErr)
return errorToErrorCode(StrTableOrErr.takeError());
StringRef StrTable = *StrTableOrErr;

bool IsFirstSym = true;
auto SymtabOrErr = Obj.symbols(Symtab);
if (std::error_code EC = SymtabOrErr.getError())
return EC;
if (!SymtabOrErr)
return errorToErrorCode(SymtabOrErr.takeError());
for (const Elf_Sym &Sym : *SymtabOrErr) {
if (IsFirstSym) {
IsFirstSym = false;
Expand Down Expand Up @@ -192,16 +192,16 @@ ELFDumper<ELFT>::dumpSymbol(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
return errorToErrorCode(SymbolNameOrErr.takeError());
S.Name = SymbolNameOrErr.get();

ErrorOr<const Elf_Shdr *> ShdrOrErr = Obj.getSection(Sym, SymTab, ShndxTable);
if (std::error_code EC = ShdrOrErr.getError())
return EC;
auto ShdrOrErr = Obj.getSection(Sym, SymTab, ShndxTable);
if (!ShdrOrErr)
return errorToErrorCode(ShdrOrErr.takeError());
const Elf_Shdr *Shdr = *ShdrOrErr;
if (!Shdr)
return obj2yaml_error::success;

ErrorOr<StringRef> NameOrErr = Obj.getSectionName(Shdr);
if (std::error_code EC = NameOrErr.getError())
return EC;
auto NameOrErr = Obj.getSectionName(Shdr);
if (!NameOrErr)
return errorToErrorCode(NameOrErr.takeError());
S.Section = NameOrErr.get();

return obj2yaml_error::success;
Expand All @@ -217,15 +217,15 @@ std::error_code ELFDumper<ELFT>::dumpRelocation(const RelT *Rel,
R.Addend = 0;

auto SymOrErr = Obj.getRelocationSymbol(Rel, SymTab);
if (std::error_code EC = SymOrErr.getError())
return EC;
if (!SymOrErr)
return errorToErrorCode(SymOrErr.takeError());
const Elf_Sym *Sym = *SymOrErr;
ErrorOr<const Elf_Shdr *> StrTabSec = Obj.getSection(SymTab->sh_link);
if (std::error_code EC = StrTabSec.getError())
return EC;
ErrorOr<StringRef> StrTabOrErr = Obj.getStringTable(*StrTabSec);
if (std::error_code EC = StrTabOrErr.getError())
return EC;
auto StrTabSec = Obj.getSection(SymTab->sh_link);
if (!StrTabSec)
return errorToErrorCode(StrTabSec.takeError());
auto StrTabOrErr = Obj.getStringTable(*StrTabSec);
if (!StrTabOrErr)
return errorToErrorCode(StrTabOrErr.takeError());
StringRef StrTab = *StrTabOrErr;

Expected<StringRef> NameOrErr = Sym->getName(StrTab);
Expand All @@ -244,18 +244,18 @@ std::error_code ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr,
S.Address = Shdr->sh_addr;
S.AddressAlign = Shdr->sh_addralign;

ErrorOr<StringRef> NameOrErr = Obj.getSectionName(Shdr);
if (std::error_code EC = NameOrErr.getError())
return EC;
auto NameOrErr = Obj.getSectionName(Shdr);
if (!NameOrErr)
return errorToErrorCode(NameOrErr.takeError());
S.Name = NameOrErr.get();

if (Shdr->sh_link != ELF::SHN_UNDEF) {
ErrorOr<const Elf_Shdr *> LinkSection = Obj.getSection(Shdr->sh_link);
if (std::error_code EC = LinkSection.getError())
return EC;
auto LinkSection = Obj.getSection(Shdr->sh_link);
if (LinkSection.takeError())
return errorToErrorCode(LinkSection.takeError());
NameOrErr = Obj.getSectionName(*LinkSection);
if (std::error_code EC = NameOrErr.getError())
return EC;
if (!NameOrErr)
return errorToErrorCode(NameOrErr.takeError());
S.Link = NameOrErr.get();
}

Expand All @@ -269,13 +269,13 @@ ELFDumper<ELFT>::dumpCommonRelocationSection(const Elf_Shdr *Shdr,
if (std::error_code EC = dumpCommonSection(Shdr, S))
return EC;

ErrorOr<const Elf_Shdr *> InfoSection = Obj.getSection(Shdr->sh_info);
if (std::error_code EC = InfoSection.getError())
return EC;
auto InfoSection = Obj.getSection(Shdr->sh_info);
if (!InfoSection)
return errorToErrorCode(InfoSection.takeError());

ErrorOr<StringRef> NameOrErr = Obj.getSectionName(*InfoSection);
if (std::error_code EC = NameOrErr.getError())
return EC;
auto NameOrErr = Obj.getSectionName(*InfoSection);
if (!NameOrErr)
return errorToErrorCode(NameOrErr.takeError());
S.Info = NameOrErr.get();

return obj2yaml_error::success;
Expand All @@ -290,14 +290,14 @@ ELFDumper<ELFT>::dumpRelSection(const Elf_Shdr *Shdr) {
if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S))
return EC;

ErrorOr<const Elf_Shdr *> SymTabOrErr = Obj.getSection(Shdr->sh_link);
if (std::error_code EC = SymTabOrErr.getError())
return EC;
auto SymTabOrErr = Obj.getSection(Shdr->sh_link);
if (!SymTabOrErr)
return errorToErrorCode(SymTabOrErr.takeError());
const Elf_Shdr *SymTab = *SymTabOrErr;

auto Rels = Obj.rels(Shdr);
if (std::error_code EC = Rels.getError())
return EC;
if (!Rels)
return errorToErrorCode(Rels.takeError());
for (const Elf_Rel &Rel : *Rels) {
ELFYAML::Relocation R;
if (std::error_code EC = dumpRelocation(&Rel, SymTab, R))
Expand All @@ -317,14 +317,14 @@ ELFDumper<ELFT>::dumpRelaSection(const Elf_Shdr *Shdr) {
if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S))
return EC;

ErrorOr<const Elf_Shdr *> SymTabOrErr = Obj.getSection(Shdr->sh_link);
if (std::error_code EC = SymTabOrErr.getError())
return EC;
auto SymTabOrErr = Obj.getSection(Shdr->sh_link);
if (!SymTabOrErr)
return errorToErrorCode(SymTabOrErr.takeError());
const Elf_Shdr *SymTab = *SymTabOrErr;

auto Rels = Obj.relas(Shdr);
if (std::error_code EC = Rels.getError())
return EC;
if (!Rels)
return errorToErrorCode(Rels.takeError());
for (const Elf_Rela &Rel : *Rels) {
ELFYAML::Relocation R;
if (std::error_code EC = dumpRelocation(&Rel, SymTab, R))
Expand All @@ -344,9 +344,9 @@ ELFDumper<ELFT>::dumpContentSection(const Elf_Shdr *Shdr) {
if (std::error_code EC = dumpCommonSection(Shdr, *S))
return EC;

ErrorOr<ArrayRef<uint8_t>> ContentOrErr = Obj.getSectionContents(Shdr);
if (std::error_code EC = ContentOrErr.getError())
return EC;
auto ContentOrErr = Obj.getSectionContents(Shdr);
if (!ContentOrErr)
return errorToErrorCode(ContentOrErr.takeError());
S->Content = yaml::BinaryRef(ContentOrErr.get());
S->Size = S->Content.binary_size();

Expand All @@ -372,21 +372,21 @@ ErrorOr<ELFYAML::Group *> ELFDumper<ELFT>::dumpGroup(const Elf_Shdr *Shdr) {
if (std::error_code EC = dumpCommonSection(Shdr, *S))
return EC;
// Get sh_info which is the signature.
ErrorOr<const Elf_Shdr *> SymtabOrErr = Obj.getSection(Shdr->sh_link);
if (std::error_code EC = SymtabOrErr.getError())
return EC;
auto SymtabOrErr = Obj.getSection(Shdr->sh_link);
if (!SymtabOrErr)
return errorToErrorCode(SymtabOrErr.takeError());
const Elf_Shdr *Symtab = *SymtabOrErr;
ErrorOr<const Elf_Sym *> SymOrErr = Obj.getSymbol(Symtab, Shdr->sh_info);
if (std::error_code EC = SymOrErr.getError())
return EC;
auto SymOrErr = Obj.getSymbol(Symtab, Shdr->sh_info);
if (!SymOrErr)
return errorToErrorCode(SymOrErr.takeError());
const Elf_Sym *symbol = *SymOrErr;
ErrorOr<StringRef> StrTabOrErr = Obj.getStringTableForSymtab(*Symtab);
if (std::error_code EC = StrTabOrErr.getError())
return EC;
auto StrTabOrErr = Obj.getStringTableForSymtab(*Symtab);
if (!StrTabOrErr)
return errorToErrorCode(StrTabOrErr.takeError());
StringRef StrTab = *StrTabOrErr;
auto sectionContents = Obj.getSectionContents(Shdr);
if (std::error_code ec = sectionContents.getError())
return ec;
if (!sectionContents)
return errorToErrorCode(sectionContents.takeError());
Expected<StringRef> symbolName = symbol->getName(StrTab);
if (!symbolName)
return errorToErrorCode(symbolName.takeError());
Expand All @@ -399,12 +399,12 @@ ErrorOr<ELFYAML::Group *> ELFDumper<ELFT>::dumpGroup(const Elf_Shdr *Shdr) {
if (groupMembers[i] == llvm::ELF::GRP_COMDAT) {
s.sectionNameOrType = "GRP_COMDAT";
} else {
ErrorOr<const Elf_Shdr *> sHdr = Obj.getSection(groupMembers[i]);
if (std::error_code EC = sHdr.getError())
return EC;
ErrorOr<StringRef> sectionName = Obj.getSectionName(*sHdr);
if (std::error_code ec = sectionName.getError())
return ec;
auto sHdr = Obj.getSection(groupMembers[i]);
if (!sHdr)
return errorToErrorCode(sHdr.takeError());
auto sectionName = Obj.getSectionName(*sHdr);
if (!sectionName)
return errorToErrorCode(sectionName.takeError());
s.sectionNameOrType = *sectionName;
}
S->Members.push_back(s);
Expand All @@ -421,9 +421,9 @@ ELFDumper<ELFT>::dumpMipsABIFlags(const Elf_Shdr *Shdr) {
if (std::error_code EC = dumpCommonSection(Shdr, *S))
return EC;

ErrorOr<ArrayRef<uint8_t>> ContentOrErr = Obj.getSectionContents(Shdr);
if (std::error_code EC = ContentOrErr.getError())
return EC;
auto ContentOrErr = Obj.getSectionContents(Shdr);
if (!ContentOrErr)
return errorToErrorCode(ContentOrErr.takeError());

auto *Flags = reinterpret_cast<const object::Elf_Mips_ABIFlags<ELFT> *>(
ContentOrErr.get().data());
Expand Down