public:
ELFDumper(const ELFObjectFile<ELFT> &O) : Dumper(O), Obj(O) {}
void printPrivateHeaders(bool MachOOnlyFirst) override;
+ void printDynamicRelocations() override;
private:
const ELFObjectFile<ELFT> &Obj;
}
}
+template <typename ELFT> void ELFDumper<ELFT>::printDynamicRelocations() {
+ if (!any_of(Obj.sections(), [](const ELFSectionRef Sec) {
+ return Sec.getType() == ELF::SHT_DYNAMIC;
+ })) {
+ reportError(Obj.getFileName(), "not a dynamic object");
+ return;
+ }
+
+ std::vector<SectionRef> DynRelSec =
+ cast<ObjectFile>(Obj).dynamic_relocation_sections();
+ if (DynRelSec.empty())
+ return;
+
+ outs() << "\nDYNAMIC RELOCATION RECORDS\n";
+ const uint32_t OffsetPadding = (Obj.getBytesInAddress() > 4 ? 16 : 8);
+ const uint32_t TypePadding = 24;
+ outs() << left_justify("OFFSET", OffsetPadding) << ' '
+ << left_justify("TYPE", TypePadding) << " VALUE\n";
+
+ StringRef Fmt = Obj.getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64;
+ for (const SectionRef &Section : DynRelSec)
+ for (const RelocationRef &Reloc : Section.relocations()) {
+ uint64_t Address = Reloc.getOffset();
+ SmallString<32> RelocName;
+ SmallString<32> ValueStr;
+ Reloc.getTypeName(RelocName);
+ if (Error E = getELFRelocationValueString(&Obj, Reloc, ValueStr))
+ reportError(std::move(E), Obj.getFileName());
+ outs() << format(Fmt.data(), Address) << ' '
+ << left_justify(RelocName, TypePadding) << ' ' << ValueStr << '\n';
+ }
+}
+
template <class ELFT>
static void printSymbolVersionDependency(StringRef FileName,
const ELFFile<ELFT> &Obj,
}
}
-void objdump::printDynamicRelocations(const ObjectFile *Obj) {
- // For the moment, this option is for ELF only
- if (!Obj->isELF())
- return;
-
- const auto *Elf = dyn_cast<ELFObjectFileBase>(Obj);
- if (!Elf || !any_of(Elf->sections(), [](const ELFSectionRef Sec) {
- return Sec.getType() == ELF::SHT_DYNAMIC;
- })) {
- reportError(Obj->getFileName(), "not a dynamic object");
- return;
- }
-
- std::vector<SectionRef> DynRelSec = Obj->dynamic_relocation_sections();
- if (DynRelSec.empty())
- return;
-
- outs() << "\nDYNAMIC RELOCATION RECORDS\n";
- const uint32_t OffsetPadding = (Obj->getBytesInAddress() > 4 ? 16 : 8);
- const uint32_t TypePadding = 24;
- outs() << left_justify("OFFSET", OffsetPadding) << ' '
- << left_justify("TYPE", TypePadding) << " VALUE\n";
-
- StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64;
- for (const SectionRef &Section : DynRelSec)
- for (const RelocationRef &Reloc : Section.relocations()) {
- uint64_t Address = Reloc.getOffset();
- SmallString<32> RelocName;
- SmallString<32> ValueStr;
- Reloc.getTypeName(RelocName);
- if (Error E = getRelocationValueString(Reloc, ValueStr))
- reportError(std::move(E), Obj->getFileName());
- outs() << format(Fmt.data(), Address) << ' '
- << left_justify(RelocName, TypePadding) << ' ' << ValueStr << '\n';
- }
-}
-
// Returns true if we need to show LMA column when dumping section headers. We
// show it only when the platform is ELF and either we have at least one section
// whose VMA and LMA are different and/or when --show-lma flag is used.
if (Relocations && !Disassemble)
D.printRelocations();
if (DynamicRelocations)
- printDynamicRelocations(O);
+ D.printDynamicRelocations();
if (SectionContents)
printSectionContents(O);
if (Disassemble)
void reportUniqueWarning(const Twine &Msg);
virtual void printPrivateHeaders(bool MachOOnlyFirst);
+ virtual void printDynamicRelocations() {}
void printSymbolTable(StringRef ArchiveName,
StringRef ArchitectureName = StringRef(),
bool DumpDynamic = false);
uint64_t *Idx = nullptr);
bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B);
-void printDynamicRelocations(const object::ObjectFile *O);
void printSectionHeaders(object::ObjectFile &O);
void printSectionContents(const object::ObjectFile *O);
[[noreturn]] void reportError(StringRef File, const Twine &Message);