return DynRegionInfo(ObjF, *this, Obj.base() + Offset, Size, EntSize);
}
- void printAttributes();
+ void printAttributes(unsigned, std::unique_ptr<ELFAttributeParser>,
+ support::endianness);
void printMipsReginfo();
void printMipsOptions();
template <class ELFT> void ELFDumper<ELFT>::printArchSpecificInfo() {
switch (Obj.getHeader().e_machine) {
case EM_ARM:
+ if (Obj.isLE())
+ printAttributes(ELF::SHT_ARM_ATTRIBUTES,
+ std::make_unique<ARMAttributeParser>(&W),
+ support::little);
+ else
+ reportUniqueWarning("attribute printing not implemented for big-endian "
+ "ARM objects");
+ break;
case EM_RISCV:
- printAttributes();
+ if (Obj.isLE())
+ printAttributes(ELF::SHT_RISCV_ATTRIBUTES,
+ std::make_unique<RISCVAttributeParser>(&W),
+ support::little);
+ else
+ reportUniqueWarning("attribute printing not implemented for big-endian "
+ "RISC-V objects");
break;
case EM_MIPS: {
printMipsABIFlags();
}
}
-template <class ELFT> void ELFDumper<ELFT>::printAttributes() {
- if (!Obj.isLE()) {
- W.startLine() << "Attributes not implemented.\n";
- return;
- }
-
- const unsigned Machine = Obj.getHeader().e_machine;
- assert((Machine == EM_ARM || Machine == EM_RISCV) &&
- "Attributes not implemented.");
-
+template <class ELFT>
+void ELFDumper<ELFT>::printAttributes(
+ unsigned AttrShType, std::unique_ptr<ELFAttributeParser> AttrParser,
+ support::endianness Endianness) {
+ assert((AttrShType != ELF::SHT_NULL) && AttrParser &&
+ "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<uint8_t> Contents;
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, Endianness))
reportUniqueWarning("unable to dump attributes from the " +
describe(Sec) + ": " + toString(std::move(E)));
}