diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp --- a/llvm/tools/obj2yaml/elf2yaml.cpp +++ b/llvm/tools/obj2yaml/elf2yaml.cpp @@ -55,6 +55,7 @@ std::vector &Symbols); Error dumpSymbol(const Elf_Sym *Sym, const Elf_Shdr *SymTab, StringRef StrTable, ELFYAML::Symbol &S); + Expected>> dumpSections(); Error dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S); Error dumpCommonRelocationSection(const Elf_Shdr *Shdr, ELFYAML::RelocationSection &S); @@ -228,13 +229,27 @@ return std::move(E); } + if (Expected>> ChunksOrErr = + dumpSections()) + Y->Chunks = std::move(*ChunksOrErr); + else + return ChunksOrErr.takeError(); + + return Y.release(); +} + +template +Expected>> +ELFDumper::dumpSections() { + std::vector> Ret; + for (const Elf_Shdr &Sec : Sections) { switch (Sec.sh_type) { case ELF::SHT_DYNAMIC: { Expected SecOrErr = dumpDynamicSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_STRTAB: @@ -247,7 +262,7 @@ dumpSymtabShndxSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_REL: @@ -255,84 +270,84 @@ Expected SecOrErr = dumpRelocSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_RELR: { Expected SecOrErr = dumpRelrSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_GROUP: { Expected GroupOrErr = dumpGroup(&Sec); if (!GroupOrErr) return GroupOrErr.takeError(); - Y->Chunks.emplace_back(*GroupOrErr); + Ret.emplace_back(*GroupOrErr); break; } case ELF::SHT_MIPS_ABIFLAGS: { Expected SecOrErr = dumpMipsABIFlags(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_NOBITS: { Expected SecOrErr = dumpNoBitsSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_NOTE: { Expected SecOrErr = dumpNoteSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_HASH: { Expected SecOrErr = dumpHashSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_GNU_HASH: { Expected SecOrErr = dumpGnuHashSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_GNU_verdef: { Expected SecOrErr = dumpVerdefSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_GNU_versym: { Expected SecOrErr = dumpSymverSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_GNU_verneed: { Expected SecOrErr = dumpVerneedSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_LLVM_ADDRSIG: { Expected SecOrErr = dumpAddrsigSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_LLVM_LINKER_OPTIONS: { @@ -340,7 +355,7 @@ dumpLinkerOptionsSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_LLVM_DEPENDENT_LIBRARIES: { @@ -348,7 +363,7 @@ dumpDependentLibrariesSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_LLVM_CALL_GRAPH_PROFILE: { @@ -356,7 +371,7 @@ dumpCallGraphProfileSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); break; } case ELF::SHT_NULL: { @@ -378,7 +393,7 @@ if (!SpecialSecOrErr) return SpecialSecOrErr.takeError(); if (*SpecialSecOrErr) { - Y->Chunks.emplace_back(*SpecialSecOrErr); + Ret.emplace_back(*SpecialSecOrErr); break; } } @@ -387,12 +402,11 @@ dumpContentSection(&Sec); if (!SecOrErr) return SecOrErr.takeError(); - Y->Chunks.emplace_back(*SecOrErr); + Ret.emplace_back(*SecOrErr); } } } - - return Y.release(); + return std::move(Ret); } template