const object::ELFFile<ELFT> &Obj;
ArrayRef<Elf_Word> ShndxTable;
- Error dumpSymbols(const Elf_Shdr *Symtab,
- std::vector<ELFYAML::Symbol> &Symbols);
- Error dumpSymbol(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
- StringRef StrTable, ELFYAML::Symbol &S);
- Error dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S);
- Error dumpCommonRelocationSection(const Elf_Shdr *Shdr,
- ELFYAML::RelocationSection &S);
+ std::error_code dumpSymbols(const Elf_Shdr *Symtab,
+ std::vector<ELFYAML::Symbol> &Symbols);
+ std::error_code dumpSymbol(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
+ StringRef StrTable, ELFYAML::Symbol &S);
+ std::error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S);
+ std::error_code dumpCommonRelocationSection(const Elf_Shdr *Shdr,
+ ELFYAML::RelocationSection &S);
template <class RelT>
- Error dumpRelocation(const RelT *Rel, const Elf_Shdr *SymTab,
- ELFYAML::Relocation &R);
-
- Expected<ELFYAML::DynamicSection *> dumpDynamicSection(const Elf_Shdr *Shdr);
- Expected<ELFYAML::RelocationSection *> dumpRelocSection(const Elf_Shdr *Shdr);
- Expected<ELFYAML::RawContentSection *>
+ std::error_code dumpRelocation(const RelT *Rel, const Elf_Shdr *SymTab,
+ ELFYAML::Relocation &R);
+
+ ErrorOr<ELFYAML::DynamicSection *> dumpDynamicSection(const Elf_Shdr *Shdr);
+ ErrorOr<ELFYAML::RelocationSection *> dumpRelocSection(const Elf_Shdr *Shdr);
+ ErrorOr<ELFYAML::RawContentSection *>
dumpContentSection(const Elf_Shdr *Shdr);
- Expected<ELFYAML::NoBitsSection *> dumpNoBitsSection(const Elf_Shdr *Shdr);
- Expected<ELFYAML::VerdefSection *> dumpVerdefSection(const Elf_Shdr *Shdr);
- Expected<ELFYAML::SymverSection *> dumpSymverSection(const Elf_Shdr *Shdr);
- Expected<ELFYAML::VerneedSection *> dumpVerneedSection(const Elf_Shdr *Shdr);
- Expected<ELFYAML::Group *> dumpGroup(const Elf_Shdr *Shdr);
- Expected<ELFYAML::MipsABIFlags *> dumpMipsABIFlags(const Elf_Shdr *Shdr);
+ ErrorOr<ELFYAML::NoBitsSection *> dumpNoBitsSection(const Elf_Shdr *Shdr);
+ ErrorOr<ELFYAML::VerdefSection *> dumpVerdefSection(const Elf_Shdr *Shdr);
+ ErrorOr<ELFYAML::SymverSection *> dumpSymverSection(const Elf_Shdr *Shdr);
+ ErrorOr<ELFYAML::VerneedSection *> dumpVerneedSection(const Elf_Shdr *Shdr);
+ ErrorOr<ELFYAML::Group *> dumpGroup(const Elf_Shdr *Shdr);
+ ErrorOr<ELFYAML::MipsABIFlags *> dumpMipsABIFlags(const Elf_Shdr *Shdr);
public:
ELFDumper(const object::ELFFile<ELFT> &O);
- Expected<ELFYAML::Object *> dump();
+ ErrorOr<ELFYAML::Object *> dump();
};
}
return Name;
}
-template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
+template <class ELFT> ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
auto Y = make_unique<ELFYAML::Object>();
// Dump header. We do not dump SHEntSize, SHOffset, SHNum and SHStrNdx field.
// Dump sections
auto SectionsOrErr = Obj.sections();
if (!SectionsOrErr)
- return SectionsOrErr.takeError();
+ return errorToErrorCode(SectionsOrErr.takeError());
Sections = *SectionsOrErr;
SectionNames.resize(Sections.size());
// to access the deduplicated symbol names that we also create here.
for (const Elf_Shdr &Sec : Sections) {
if (Sec.sh_type == ELF::SHT_SYMTAB)
- if (Error E = dumpSymbols(&Sec, Y->Symbols))
- return std::move(E);
+ if (auto EC = dumpSymbols(&Sec, Y->Symbols))
+ return EC;
if (Sec.sh_type == ELF::SHT_DYNSYM)
- if (Error E = dumpSymbols(&Sec, Y->DynamicSymbols))
- return std::move(E);
+ if (auto EC = dumpSymbols(&Sec, Y->DynamicSymbols))
+ return EC;
}
for (const Elf_Shdr &Sec : Sections) {
switch (Sec.sh_type) {
case ELF::SHT_DYNAMIC: {
- Expected<ELFYAML::DynamicSection *> SecOrErr = dumpDynamicSection(&Sec);
- if (!SecOrErr)
- return SecOrErr.takeError();
- Y->Sections.emplace_back(*SecOrErr);
+ ErrorOr<ELFYAML::DynamicSection *> S = dumpDynamicSection(&Sec);
+ if (std::error_code EC = S.getError())
+ return EC;
+ Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
break;
}
case ELF::SHT_NULL:
case ELF::SHT_SYMTAB_SHNDX: {
auto TableOrErr = Obj.getSHNDXTable(Sec);
if (!TableOrErr)
- return TableOrErr.takeError();
+ return errorToErrorCode(TableOrErr.takeError());
ShndxTable = *TableOrErr;
break;
}
case ELF::SHT_REL:
case ELF::SHT_RELA: {
- Expected<ELFYAML::RelocationSection *> SecOrErr = dumpRelocSection(&Sec);
- if (!SecOrErr)
- return SecOrErr.takeError();
- Y->Sections.emplace_back(*SecOrErr);
+ ErrorOr<ELFYAML::RelocationSection *> S = dumpRelocSection(&Sec);
+ if (std::error_code EC = S.getError())
+ return EC;
+ Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
break;
}
case ELF::SHT_GROUP: {
- Expected<ELFYAML::Group *> GroupOrErr = dumpGroup(&Sec);
- if (!GroupOrErr)
- return GroupOrErr.takeError();
- Y->Sections.emplace_back(*GroupOrErr);
+ ErrorOr<ELFYAML::Group *> G = dumpGroup(&Sec);
+ if (std::error_code EC = G.getError())
+ return EC;
+ Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(G.get()));
break;
}
case ELF::SHT_MIPS_ABIFLAGS: {
- Expected<ELFYAML::MipsABIFlags *> SecOrErr = dumpMipsABIFlags(&Sec);
- if (!SecOrErr)
- return SecOrErr.takeError();
- Y->Sections.emplace_back(*SecOrErr);
+ ErrorOr<ELFYAML::MipsABIFlags *> G = dumpMipsABIFlags(&Sec);
+ if (std::error_code EC = G.getError())
+ return EC;
+ Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(G.get()));
break;
}
case ELF::SHT_NOBITS: {
- Expected<ELFYAML::NoBitsSection *> SecOrErr = dumpNoBitsSection(&Sec);
- if (!SecOrErr)
- return SecOrErr.takeError();
- Y->Sections.emplace_back(*SecOrErr);
+ ErrorOr<ELFYAML::NoBitsSection *> S = dumpNoBitsSection(&Sec);
+ if (std::error_code EC = S.getError())
+ return EC;
+ Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
break;
}
case ELF::SHT_GNU_verdef: {
- Expected<ELFYAML::VerdefSection *> SecOrErr = dumpVerdefSection(&Sec);
- if (!SecOrErr)
- return SecOrErr.takeError();
- Y->Sections.emplace_back(*SecOrErr);
+ ErrorOr<ELFYAML::VerdefSection *> S = dumpVerdefSection(&Sec);
+ if (std::error_code EC = S.getError())
+ return EC;
+ Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
break;
}
case ELF::SHT_GNU_versym: {
- Expected<ELFYAML::SymverSection *> SecOrErr = dumpSymverSection(&Sec);
- if (!SecOrErr)
- return SecOrErr.takeError();
- Y->Sections.emplace_back(*SecOrErr);
+ ErrorOr<ELFYAML::SymverSection *> S = dumpSymverSection(&Sec);
+ if (std::error_code EC = S.getError())
+ return EC;
+ Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
break;
}
case ELF::SHT_GNU_verneed: {
- Expected<ELFYAML::VerneedSection *> SecOrErr = dumpVerneedSection(&Sec);
- if (!SecOrErr)
- return SecOrErr.takeError();
- Y->Sections.emplace_back(*SecOrErr);
+ ErrorOr<ELFYAML::VerneedSection *> S = dumpVerneedSection(&Sec);
+ if (std::error_code EC = S.getError())
+ return EC;
+ Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
break;
}
default: {
- Expected<ELFYAML::RawContentSection *> SecOrErr =
- dumpContentSection(&Sec);
- if (!SecOrErr)
- return SecOrErr.takeError();
- Y->Sections.emplace_back(*SecOrErr);
+ ErrorOr<ELFYAML::RawContentSection *> S = dumpContentSection(&Sec);
+ if (std::error_code EC = S.getError())
+ return EC;
+ Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
}
}
}
}
template <class ELFT>
-Error ELFDumper<ELFT>::dumpSymbols(const Elf_Shdr *Symtab,
+std::error_code
+ELFDumper<ELFT>::dumpSymbols(const Elf_Shdr *Symtab,
std::vector<ELFYAML::Symbol> &Symbols) {
if (!Symtab)
- return Error::success();
+ return std::error_code();
auto StrTableOrErr = Obj.getStringTableForSymtab(*Symtab);
if (!StrTableOrErr)
- return StrTableOrErr.takeError();
+ return errorToErrorCode(StrTableOrErr.takeError());
StringRef StrTable = *StrTableOrErr;
auto SymtabOrErr = Obj.symbols(Symtab);
if (!SymtabOrErr)
- return SymtabOrErr.takeError();
+ return errorToErrorCode(SymtabOrErr.takeError());
if (Symtab->sh_type == ELF::SHT_SYMTAB) {
SymTable = *SymtabOrErr;
Symbols.push_back(S);
}
- return Error::success();
+ return std::error_code();
}
template <class ELFT>
-Error ELFDumper<ELFT>::dumpSymbol(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
- StringRef StrTable, ELFYAML::Symbol &S) {
+std::error_code
+ELFDumper<ELFT>::dumpSymbol(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
+ StringRef StrTable, ELFYAML::Symbol &S) {
S.Type = Sym->getType();
S.Value = Sym->st_value;
S.Size = Sym->st_size;
Expected<StringRef> SymbolNameOrErr =
getUniquedSymbolName(Sym, StrTable, SymTab);
if (!SymbolNameOrErr)
- return SymbolNameOrErr.takeError();
+ return errorToErrorCode(SymbolNameOrErr.takeError());
S.Name = SymbolNameOrErr.get();
if (Sym->st_shndx >= ELF::SHN_LORESERVE) {
if (Sym->st_shndx == ELF::SHN_XINDEX)
- return createStringError(obj2yaml_error::not_implemented,
- "SHN_XINDEX symbols are not supported");
+ return obj2yaml_error::not_implemented;
S.Index = (ELFYAML::ELF_SHN)Sym->st_shndx;
- return Error::success();
+ return obj2yaml_error::success;
}
auto ShdrOrErr = Obj.getSection(Sym, SymTab, ShndxTable);
if (!ShdrOrErr)
- return ShdrOrErr.takeError();
+ return errorToErrorCode(ShdrOrErr.takeError());
const Elf_Shdr *Shdr = *ShdrOrErr;
if (!Shdr)
- return Error::success();
+ return obj2yaml_error::success;
auto NameOrErr = getUniquedSectionName(Shdr);
if (!NameOrErr)
- return NameOrErr.takeError();
+ return errorToErrorCode(NameOrErr.takeError());
S.Section = NameOrErr.get();
- return Error::success();
+ return obj2yaml_error::success;
}
template <class ELFT>
template <class RelT>
-Error ELFDumper<ELFT>::dumpRelocation(const RelT *Rel, const Elf_Shdr *SymTab,
- ELFYAML::Relocation &R) {
+std::error_code ELFDumper<ELFT>::dumpRelocation(const RelT *Rel,
+ const Elf_Shdr *SymTab,
+ ELFYAML::Relocation &R) {
R.Type = Rel->getType(Obj.isMips64EL());
R.Offset = Rel->r_offset;
R.Addend = 0;
auto SymOrErr = Obj.getRelocationSymbol(Rel, SymTab);
if (!SymOrErr)
- return SymOrErr.takeError();
+ return errorToErrorCode(SymOrErr.takeError());
const Elf_Sym *Sym = *SymOrErr;
auto StrTabSec = Obj.getSection(SymTab->sh_link);
if (!StrTabSec)
- return StrTabSec.takeError();
+ return errorToErrorCode(StrTabSec.takeError());
auto StrTabOrErr = Obj.getStringTable(*StrTabSec);
if (!StrTabOrErr)
- return StrTabOrErr.takeError();
+ return errorToErrorCode(StrTabOrErr.takeError());
StringRef StrTab = *StrTabOrErr;
if (Sym) {
Expected<StringRef> NameOrErr = getUniquedSymbolName(Sym, StrTab, SymTab);
if (!NameOrErr)
- return NameOrErr.takeError();
+ return errorToErrorCode(NameOrErr.takeError());
R.Symbol = NameOrErr.get();
} else {
// We have some edge cases of relocations without a symbol associated,
R.Symbol = "";
}
- return Error::success();
+ return obj2yaml_error::success;
}
template <class ELFT>
-Error ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr,
- ELFYAML::Section &S) {
+std::error_code ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr,
+ ELFYAML::Section &S) {
// Dump fields. We do not dump the ShOffset field. When not explicitly
// set, the value is set by yaml2obj automatically.
S.Type = Shdr->sh_type;
auto NameOrErr = getUniquedSectionName(Shdr);
if (!NameOrErr)
- return NameOrErr.takeError();
+ return errorToErrorCode(NameOrErr.takeError());
S.Name = NameOrErr.get();
if (Shdr->sh_link != ELF::SHN_UNDEF) {
auto LinkSection = Obj.getSection(Shdr->sh_link);
if (LinkSection.takeError())
- return LinkSection.takeError();
+ return errorToErrorCode(LinkSection.takeError());
NameOrErr = getUniquedSectionName(*LinkSection);
if (!NameOrErr)
- return NameOrErr.takeError();
+ return errorToErrorCode(NameOrErr.takeError());
S.Link = NameOrErr.get();
}
- return Error::success();
+ return obj2yaml_error::success;
}
template <class ELFT>
-Error ELFDumper<ELFT>::dumpCommonRelocationSection(
- const Elf_Shdr *Shdr, ELFYAML::RelocationSection &S) {
- if (Error E = dumpCommonSection(Shdr, S))
- return E;
+std::error_code
+ELFDumper<ELFT>::dumpCommonRelocationSection(const Elf_Shdr *Shdr,
+ ELFYAML::RelocationSection &S) {
+ if (std::error_code EC = dumpCommonSection(Shdr, S))
+ return EC;
auto InfoSection = Obj.getSection(Shdr->sh_info);
if (!InfoSection)
- return InfoSection.takeError();
+ return errorToErrorCode(InfoSection.takeError());
auto NameOrErr = getUniquedSectionName(*InfoSection);
if (!NameOrErr)
- return NameOrErr.takeError();
+ return errorToErrorCode(NameOrErr.takeError());
S.RelocatableSec = NameOrErr.get();
- return Error::success();
+ return obj2yaml_error::success;
}
template <class ELFT>
-Expected<ELFYAML::DynamicSection *>
+ErrorOr<ELFYAML::DynamicSection *>
ELFDumper<ELFT>::dumpDynamicSection(const Elf_Shdr *Shdr) {
auto S = make_unique<ELFYAML::DynamicSection>();
- if (Error E = dumpCommonSection(Shdr, *S))
- return std::move(E);
+ if (std::error_code EC = dumpCommonSection(Shdr, *S))
+ return EC;
auto DynTagsOrErr = Obj.template getSectionContentsAsArray<Elf_Dyn>(Shdr);
if (!DynTagsOrErr)
- return DynTagsOrErr.takeError();
+ return errorToErrorCode(DynTagsOrErr.takeError());
for (const Elf_Dyn &Dyn : *DynTagsOrErr)
S->Entries.push_back({(ELFYAML::ELF_DYNTAG)Dyn.getTag(), Dyn.getVal()});
}
template <class ELFT>
-Expected<ELFYAML::RelocationSection *>
+ErrorOr<ELFYAML::RelocationSection *>
ELFDumper<ELFT>::dumpRelocSection(const Elf_Shdr *Shdr) {
auto S = make_unique<ELFYAML::RelocationSection>();
- if (auto E = dumpCommonRelocationSection(Shdr, *S))
- return std::move(E);
+ if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S))
+ return EC;
auto SymTabOrErr = Obj.getSection(Shdr->sh_link);
if (!SymTabOrErr)
- return SymTabOrErr.takeError();
+ return errorToErrorCode(SymTabOrErr.takeError());
const Elf_Shdr *SymTab = *SymTabOrErr;
if (Shdr->sh_type == ELF::SHT_REL) {
auto Rels = Obj.rels(Shdr);
if (!Rels)
- return Rels.takeError();
+ return errorToErrorCode(Rels.takeError());
for (const Elf_Rel &Rel : *Rels) {
ELFYAML::Relocation R;
- if (Error E = dumpRelocation(&Rel, SymTab, R))
- return std::move(E);
+ if (std::error_code EC = dumpRelocation(&Rel, SymTab, R))
+ return EC;
S->Relocations.push_back(R);
}
} else {
auto Rels = Obj.relas(Shdr);
if (!Rels)
- return Rels.takeError();
+ return errorToErrorCode(Rels.takeError());
for (const Elf_Rela &Rel : *Rels) {
ELFYAML::Relocation R;
- if (Error E = dumpRelocation(&Rel, SymTab, R))
- return std::move(E);
+ if (std::error_code EC = dumpRelocation(&Rel, SymTab, R))
+ return EC;
R.Addend = Rel.r_addend;
S->Relocations.push_back(R);
}
}
template <class ELFT>
-Expected<ELFYAML::RawContentSection *>
+ErrorOr<ELFYAML::RawContentSection *>
ELFDumper<ELFT>::dumpContentSection(const Elf_Shdr *Shdr) {
auto S = make_unique<ELFYAML::RawContentSection>();
- if (Error E = dumpCommonSection(Shdr, *S))
- return std::move(E);
+
+ if (std::error_code EC = dumpCommonSection(Shdr, *S))
+ return EC;
auto ContentOrErr = Obj.getSectionContents(Shdr);
if (!ContentOrErr)
- return ContentOrErr.takeError();
+ return errorToErrorCode(ContentOrErr.takeError());
ArrayRef<uint8_t> Content = *ContentOrErr;
if (!Content.empty())
S->Content = yaml::BinaryRef(Content);
}
template <class ELFT>
-Expected<ELFYAML::NoBitsSection *>
+ErrorOr<ELFYAML::NoBitsSection *>
ELFDumper<ELFT>::dumpNoBitsSection(const Elf_Shdr *Shdr) {
auto S = make_unique<ELFYAML::NoBitsSection>();
- if (Error E = dumpCommonSection(Shdr, *S))
- return std::move(E);
+
+ if (std::error_code EC = dumpCommonSection(Shdr, *S))
+ return EC;
S->Size = Shdr->sh_size;
return S.release();
}
template <class ELFT>
-Expected<ELFYAML::VerdefSection *>
+ErrorOr<ELFYAML::VerdefSection *>
ELFDumper<ELFT>::dumpVerdefSection(const Elf_Shdr *Shdr) {
typedef typename ELFT::Verdef Elf_Verdef;
typedef typename ELFT::Verdaux Elf_Verdaux;
auto S = make_unique<ELFYAML::VerdefSection>();
- if (Error E = dumpCommonSection(Shdr, *S))
- return std::move(E);
+ if (std::error_code EC = dumpCommonSection(Shdr, *S))
+ return EC;
S->Info = Shdr->sh_info;
auto StringTableShdrOrErr = Obj.getSection(Shdr->sh_link);
if (!StringTableShdrOrErr)
- return StringTableShdrOrErr.takeError();
+ return errorToErrorCode(StringTableShdrOrErr.takeError());
auto StringTableOrErr = Obj.getStringTable(*StringTableShdrOrErr);
if (!StringTableOrErr)
- return StringTableOrErr.takeError();
+ return errorToErrorCode(StringTableOrErr.takeError());
auto Contents = Obj.getSectionContents(Shdr);
if (!Contents)
- return Contents.takeError();
+ return errorToErrorCode(Contents.takeError());
llvm::ArrayRef<uint8_t> Data = *Contents;
const uint8_t *Buf = Data.data();
}
template <class ELFT>
-Expected<ELFYAML::SymverSection *>
+ErrorOr<ELFYAML::SymverSection *>
ELFDumper<ELFT>::dumpSymverSection(const Elf_Shdr *Shdr) {
typedef typename ELFT::Half Elf_Half;
auto S = make_unique<ELFYAML::SymverSection>();
- if (Error E = dumpCommonSection(Shdr, *S))
- return std::move(E);
+ if (std::error_code EC = dumpCommonSection(Shdr, *S))
+ return EC;
auto VersionsOrErr = Obj.template getSectionContentsAsArray<Elf_Half>(Shdr);
if (!VersionsOrErr)
- return VersionsOrErr.takeError();
+ return errorToErrorCode(VersionsOrErr.takeError());
for (const Elf_Half &E : *VersionsOrErr)
S->Entries.push_back(E);
}
template <class ELFT>
-Expected<ELFYAML::VerneedSection *>
+ErrorOr<ELFYAML::VerneedSection *>
ELFDumper<ELFT>::dumpVerneedSection(const Elf_Shdr *Shdr) {
typedef typename ELFT::Verneed Elf_Verneed;
typedef typename ELFT::Vernaux Elf_Vernaux;
auto S = make_unique<ELFYAML::VerneedSection>();
- if (Error E = dumpCommonSection(Shdr, *S))
- return std::move(E);
+ if (std::error_code EC = dumpCommonSection(Shdr, *S))
+ return EC;
S->Info = Shdr->sh_info;
auto Contents = Obj.getSectionContents(Shdr);
if (!Contents)
- return Contents.takeError();
+ return errorToErrorCode(Contents.takeError());
auto StringTableShdrOrErr = Obj.getSection(Shdr->sh_link);
if (!StringTableShdrOrErr)
- return StringTableShdrOrErr.takeError();
+ return errorToErrorCode(StringTableShdrOrErr.takeError());
auto StringTableOrErr = Obj.getStringTable(*StringTableShdrOrErr);
if (!StringTableOrErr)
- return StringTableOrErr.takeError();
+ return errorToErrorCode(StringTableOrErr.takeError());
llvm::ArrayRef<uint8_t> Data = *Contents;
const uint8_t *Buf = Data.data();
}
template <class ELFT>
-Expected<ELFYAML::Group *> ELFDumper<ELFT>::dumpGroup(const Elf_Shdr *Shdr) {
+ErrorOr<ELFYAML::Group *> ELFDumper<ELFT>::dumpGroup(const Elf_Shdr *Shdr) {
auto S = make_unique<ELFYAML::Group>();
- if (Error E = dumpCommonSection(Shdr, *S))
- return std::move(E);
+ if (std::error_code EC = dumpCommonSection(Shdr, *S))
+ return EC;
auto SymtabOrErr = Obj.getSection(Shdr->sh_link);
if (!SymtabOrErr)
- return SymtabOrErr.takeError();
+ return errorToErrorCode(SymtabOrErr.takeError());
// Get symbol with index sh_info which name is the signature of the group.
const Elf_Shdr *Symtab = *SymtabOrErr;
auto SymOrErr = Obj.getSymbol(Symtab, Shdr->sh_info);
if (!SymOrErr)
- return SymOrErr.takeError();
+ return errorToErrorCode(SymOrErr.takeError());
auto StrTabOrErr = Obj.getStringTableForSymtab(*Symtab);
if (!StrTabOrErr)
- return StrTabOrErr.takeError();
+ return errorToErrorCode(StrTabOrErr.takeError());
Expected<StringRef> SymbolName =
getUniquedSymbolName(*SymOrErr, *StrTabOrErr, Symtab);
if (!SymbolName)
- return SymbolName.takeError();
+ return errorToErrorCode(SymbolName.takeError());
S->Signature = *SymbolName;
auto MembersOrErr = Obj.template getSectionContentsAsArray<Elf_Word>(Shdr);
if (!MembersOrErr)
- return MembersOrErr.takeError();
+ return errorToErrorCode(MembersOrErr.takeError());
for (Elf_Word Member : *MembersOrErr) {
if (Member == llvm::ELF::GRP_COMDAT) {
auto SHdrOrErr = Obj.getSection(Member);
if (!SHdrOrErr)
- return SHdrOrErr.takeError();
+ return errorToErrorCode(SHdrOrErr.takeError());
auto NameOrErr = getUniquedSectionName(*SHdrOrErr);
if (!NameOrErr)
- return NameOrErr.takeError();
+ return errorToErrorCode(NameOrErr.takeError());
S->Members.push_back({*NameOrErr});
}
return S.release();
}
template <class ELFT>
-Expected<ELFYAML::MipsABIFlags *>
+ErrorOr<ELFYAML::MipsABIFlags *>
ELFDumper<ELFT>::dumpMipsABIFlags(const Elf_Shdr *Shdr) {
assert(Shdr->sh_type == ELF::SHT_MIPS_ABIFLAGS &&
"Section type is not SHT_MIPS_ABIFLAGS");
auto S = make_unique<ELFYAML::MipsABIFlags>();
- if (Error E = dumpCommonSection(Shdr, *S))
- return std::move(E);
+ if (std::error_code EC = dumpCommonSection(Shdr, *S))
+ return EC;
auto ContentOrErr = Obj.getSectionContents(Shdr);
if (!ContentOrErr)
- return ContentOrErr.takeError();
+ return errorToErrorCode(ContentOrErr.takeError());
auto *Flags = reinterpret_cast<const object::Elf_Mips_ABIFlags<ELFT> *>(
ContentOrErr.get().data());
}
template <class ELFT>
-static Error elf2yaml(raw_ostream &Out, const object::ELFFile<ELFT> &Obj) {
+static std::error_code elf2yaml(raw_ostream &Out,
+ const object::ELFFile<ELFT> &Obj) {
ELFDumper<ELFT> Dumper(Obj);
- Expected<ELFYAML::Object *> YAMLOrErr = Dumper.dump();
- if (!YAMLOrErr)
- return YAMLOrErr.takeError();
+ ErrorOr<ELFYAML::Object *> YAMLOrErr = Dumper.dump();
+ if (std::error_code EC = YAMLOrErr.getError())
+ return EC;
std::unique_ptr<ELFYAML::Object> YAML(YAMLOrErr.get());
yaml::Output Yout(Out);
Yout << *YAML;
- return Error::success();
+ return std::error_code();
}
-Error elf2yaml(raw_ostream &Out, const object::ObjectFile &Obj) {
+std::error_code elf2yaml(raw_ostream &Out, const object::ObjectFile &Obj) {
if (const auto *ELFObj = dyn_cast<object::ELF32LEObjectFile>(&Obj))
return elf2yaml(Out, *ELFObj->getELFFile());
if (const auto *ELFObj = dyn_cast<object::ELF64BEObjectFile>(&Obj))
return elf2yaml(Out, *ELFObj->getELFFile());
- llvm_unreachable("unknown ELF file format");
+ return obj2yaml_error::unsupported_obj_file_format;
}