From a6cfd822915f38465cddc693f5ea20c05d091ea2 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Fri, 4 Oct 2019 11:59:06 +0000 Subject: [PATCH] [llvm-readobj] Replace arch-specific ObjDumper methods by the single `printArchSpecificInfo` Initially llvm-readobj supports multiple command line options like `--arm-attributes` and `--mips-plt-got` for display ELF arch-specific information. Now all these options are superseded by the `--arch-specific` one. It makes sense to have a single `printArchSpecificInfo` method in the base `ObjDumper`, and hide all ELF/target specific details in the `ELFDumper::printArchSpecificInfo` override. Differential Revision: https://reviews.llvm.org/D68385 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373731 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-readobj/ELFDumper.cpp | 29 ++++++++++++++++++++++++----- tools/llvm-readobj/ObjDumper.h | 10 +--------- tools/llvm-readobj/llvm-readobj.cpp | 23 ++--------------------- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 2a591848685..bf50fa5935a 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -173,11 +173,7 @@ public: void printVersionInfo() override; void printGroupSections() override; - void printAttributes() override; - void printMipsPLTGOT() override; - void printMipsABIFlags() override; - void printMipsReginfo() override; - void printMipsOptions() override; + void printArchSpecificInfo() override; void printStackMap() const override; @@ -218,6 +214,12 @@ private: S->sh_entsize, ObjF->getFileName()}); } + void printAttributes(); + void printMipsPLTGOT(); + void printMipsABIFlags(); + void printMipsReginfo(); + void printMipsOptions(); + std::pair findDynamic(const ELFFile *Obj); void loadDynamicTable(const ELFFile *Obj); @@ -2210,6 +2212,23 @@ template void ELFDumper::printLoadName() { W.printString("LoadName", SOName); } +template void ELFDumper::printArchSpecificInfo() { + const ELFFile *Obj = ObjF->getELFFile(); + switch (Obj->getHeader()->e_machine) { + case EM_ARM: + printAttributes(); + break; + case EM_MIPS: + printMipsABIFlags(); + printMipsOptions(); + printMipsReginfo(); + printMipsPLTGOT(); + break; + default: + break; + } +} + template void ELFDumper::printAttributes() { W.startLine() << "Attributes not implemented.\n"; } diff --git a/tools/llvm-readobj/ObjDumper.h b/tools/llvm-readobj/ObjDumper.h index e2c7e833320..2ba44134249 100644 --- a/tools/llvm-readobj/ObjDumper.h +++ b/tools/llvm-readobj/ObjDumper.h @@ -69,15 +69,7 @@ public: virtual void printNotes() {} virtual void printELFLinkerOptions() {} virtual void printStackSizes() {} - - // Only implemented for ARM ELF at this time. - virtual void printAttributes() { } - - // Only implemented for MIPS ELF at this time. - virtual void printMipsPLTGOT() { } - virtual void printMipsABIFlags() { } - virtual void printMipsReginfo() { } - virtual void printMipsOptions() { } + virtual void printArchSpecificInfo() { } // Only implemented for PE/COFF. virtual void printCOFFImports() { } diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp index dfcda999631..b85df6bae05 100644 --- a/tools/llvm-readobj/llvm-readobj.cpp +++ b/tools/llvm-readobj/llvm-readobj.cpp @@ -397,17 +397,6 @@ void reportWarning(Error Err, StringRef Input) { } // namespace llvm -static bool isMipsArch(unsigned Arch) { - switch (Arch) { - case llvm::Triple::mips: - case llvm::Triple::mipsel: - case llvm::Triple::mips64: - case llvm::Triple::mips64el: - return true; - default: - return false; - } -} namespace { struct ReadObjTypeTableBuilder { ReadObjTypeTableBuilder() @@ -502,16 +491,8 @@ static void dumpObject(const ObjectFile *Obj, ScopedPrinter &Writer, if (Obj->isELF()) { if (opts::ELFLinkerOptions) Dumper->printELFLinkerOptions(); - if (opts::ArchSpecificInfo) { - if (Obj->getArch() == llvm::Triple::arm) - Dumper->printAttributes(); - else if (isMipsArch(Obj->getArch())) { - Dumper->printMipsABIFlags(); - Dumper->printMipsOptions(); - Dumper->printMipsReginfo(); - Dumper->printMipsPLTGOT(); - } - } + if (opts::ArchSpecificInfo) + Dumper->printArchSpecificInfo(); if (opts::SectionGroups) Dumper->printGroupSections(); if (opts::HashHistogram) -- 2.40.0