[llvm] r239856 - [llvm-readobj] Print MIPS .reginfo section content

Simon Atanasyan simon at atanasyan.com
Tue Jun 16 14:47:44 PDT 2015


Author: atanasyan
Date: Tue Jun 16 16:47:43 2015
New Revision: 239856

URL: http://llvm.org/viewvc/llvm-project?rev=239856&view=rev
Log:
[llvm-readobj] Print MIPS .reginfo section content

Added:
    llvm/trunk/test/tools/llvm-readobj/Inputs/reginfo.obj.elf-mipsel
    llvm/trunk/test/tools/llvm-readobj/mips-reginfo.test
Modified:
    llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
    llvm/trunk/tools/llvm-readobj/ObjDumper.h
    llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp

Added: llvm/trunk/test/tools/llvm-readobj/Inputs/reginfo.obj.elf-mipsel
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/Inputs/reginfo.obj.elf-mipsel?rev=239856&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-readobj/Inputs/reginfo.obj.elf-mipsel (added) and llvm/trunk/test/tools/llvm-readobj/Inputs/reginfo.obj.elf-mipsel Tue Jun 16 16:47:43 2015 differ

Added: llvm/trunk/test/tools/llvm-readobj/mips-reginfo.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/mips-reginfo.test?rev=239856&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/mips-reginfo.test (added)
+++ llvm/trunk/test/tools/llvm-readobj/mips-reginfo.test Tue Jun 16 16:47:43 2015
@@ -0,0 +1,10 @@
+RUN: llvm-readobj -mips-reginfo %p/Inputs/reginfo.obj.elf-mipsel | FileCheck %s
+
+CHECK:      MIPS RegInfo {
+CHECK-NEXT:   GP: 0x7FEF
+CHECK-NEXT:   General Mask: 0xB00001F6
+CHECK-NEXT:   Co-Proc Mask0: 0x0
+CHECK-NEXT:   Co-Proc Mask1: 0x0
+CHECK-NEXT:   Co-Proc Mask2: 0x0
+CHECK-NEXT:   Co-Proc Mask3: 0x0
+CHECK-NEXT: }

Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=239856&r1=239855&r2=239856&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Tue Jun 16 16:47:43 2015
@@ -58,6 +58,7 @@ public:
   void printAttributes() override;
   void printMipsPLTGOT() override;
   void printMipsABIFlags() override;
+  void printMipsReginfo() override;
 
 private:
   typedef ELFFile<ELFT> ELFO;
@@ -1424,3 +1425,30 @@ template <class ELFT> void ELFDumper<ELF
   W.printFlags("Flags 1", Flags->flags1, makeArrayRef(ElfMipsFlags1));
   W.printHex("Flags 2", Flags->flags2);
 }
+
+template <class ELFT> void ELFDumper<ELFT>::printMipsReginfo() {
+  const Elf_Shdr *Shdr = findSectionByName(*Obj, ".reginfo");
+  if (!Shdr) {
+    W.startLine() << "There is no .reginfo section in the file.\n";
+    return;
+  }
+  ErrorOr<ArrayRef<uint8_t>> Sec = Obj->getSectionContents(Shdr);
+  if (!Sec) {
+    W.startLine() << "The .reginfo section is empty.\n";
+    return;
+  }
+  if (Sec->size() != sizeof(Elf_Mips_RegInfo<ELFT>)) {
+    W.startLine() << "The .reginfo section has a wrong size.\n";
+    return;
+  }
+
+  auto *Reginfo = reinterpret_cast<const Elf_Mips_RegInfo<ELFT> *>(Sec->data());
+
+  DictScope GS(W, "MIPS RegInfo");
+  W.printHex("GP", Reginfo->ri_gp_value);
+  W.printHex("General Mask", Reginfo->ri_gprmask);
+  W.printHex("Co-Proc Mask0", Reginfo->ri_cprmask[0]);
+  W.printHex("Co-Proc Mask1", Reginfo->ri_cprmask[1]);
+  W.printHex("Co-Proc Mask2", Reginfo->ri_cprmask[2]);
+  W.printHex("Co-Proc Mask3", Reginfo->ri_cprmask[3]);
+}

Modified: llvm/trunk/tools/llvm-readobj/ObjDumper.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ObjDumper.h?rev=239856&r1=239855&r2=239856&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ObjDumper.h (original)
+++ llvm/trunk/tools/llvm-readobj/ObjDumper.h Tue Jun 16 16:47:43 2015
@@ -43,6 +43,7 @@ public:
   // Only implemented for MIPS ELF at this time.
   virtual void printMipsPLTGOT() { }
   virtual void printMipsABIFlags() { }
+  virtual void printMipsReginfo() { }
 
   // Only implemented for PE/COFF.
   virtual void printCOFFImports() { }

Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=239856&r1=239855&r2=239856&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Tue Jun 16 16:47:43 2015
@@ -152,6 +152,10 @@ namespace opts {
   cl::opt<bool> MipsABIFlags("mips-abi-flags",
                              cl::desc("Display the MIPS.abiflags section"));
 
+  // -mips-reginfo
+  cl::opt<bool> MipsReginfo("mips-reginfo",
+                            cl::desc("Display the MIPS .reginfo section"));
+
   // -coff-imports
   cl::opt<bool>
   COFFImports("coff-imports", cl::desc("Display the PE/COFF import table"));
@@ -296,6 +300,8 @@ static void dumpObject(const ObjectFile
       Dumper->printMipsPLTGOT();
     if (opts::MipsABIFlags)
       Dumper->printMipsABIFlags();
+    if (opts::MipsReginfo)
+      Dumper->printMipsReginfo();
   }
   if (opts::COFFImports)
     Dumper->printCOFFImports();





More information about the llvm-commits mailing list