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 @@ -2587,14 +2587,27 @@ return; } - const unsigned Machine = Obj.getHeader().e_machine; - assert((Machine == EM_ARM || Machine == EM_RISCV) && - "Attributes not implemented."); + auto AttrShType = ELF::SHT_NULL; + std::unique_ptr AttrParser; + switch (Obj.getHeader().e_machine) { + case EM_ARM: + AttrShType = ELF::SHT_ARM_ATTRIBUTES; + AttrParser = std::make_unique(&W); + break; + case EM_RISCV: + AttrShType = ELF::SHT_RISCV_ATTRIBUTES; + AttrParser = std::make_unique(&W); + break; + default: + llvm_unreachable("ELF attributes not implemented for target"); + return; + } + assert((AttrShType != ELF::SHT_NULL && AttrParser != nullptr) && + "Incomplete ELF attribute implementation"); DictScope BA(W, "BuildAttributes"); for (const Elf_Shdr &Sec : cantFail(Obj.sections())) { - if (Sec.sh_type != ELF::SHT_ARM_ATTRIBUTES && - Sec.sh_type != ELF::SHT_RISCV_ATTRIBUTES) + if (Sec.sh_type != AttrShType) continue; ArrayRef Contents; @@ -2613,13 +2626,7 @@ W.printHex("FormatVersion", Contents[0]); - auto ParseAttrubutes = [&]() { - if (Machine == EM_ARM) - return ARMAttributeParser(&W).parse(Contents, support::little); - return RISCVAttributeParser(&W).parse(Contents, support::little); - }; - - if (Error E = ParseAttrubutes()) + if (Error E = AttrParser->parse(Contents, support::little)) reportUniqueWarning("unable to dump attributes from the " + describe(Sec) + ": " + toString(std::move(E))); }