From 3bcfd461f61a6cd5b4088c3be7f5d227973cb108 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Tue, 16 Jun 2015 21:47:43 +0000 Subject: [PATCH] [llvm-readobj] Print MIPS .reginfo section content git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239856 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Inputs/reginfo.obj.elf-mipsel | Bin 0 -> 490 bytes test/tools/llvm-readobj/mips-reginfo.test | 10 +++++++ tools/llvm-readobj/ELFDumper.cpp | 28 ++++++++++++++++++ tools/llvm-readobj/ObjDumper.h | 1 + tools/llvm-readobj/llvm-readobj.cpp | 6 ++++ 5 files changed, 45 insertions(+) create mode 100644 test/tools/llvm-readobj/Inputs/reginfo.obj.elf-mipsel create mode 100644 test/tools/llvm-readobj/mips-reginfo.test diff --git a/test/tools/llvm-readobj/Inputs/reginfo.obj.elf-mipsel b/test/tools/llvm-readobj/Inputs/reginfo.obj.elf-mipsel new file mode 100644 index 0000000000000000000000000000000000000000..5cd09809f8bb52dacb3bff3f294001fbcc71e561 GIT binary patch literal 490 zcma)2yAFat5S#-93Lqouz-tEl?~a(Vse4hYRsWDo^}p8P0o2-;;j$~F*OQ) zEn_ax^rCbSUnG%Un}UGenJmMpmE!Z5G~g_P-mdR0g=JN#H{M6XR`E9;&!q@MU6uYn;5a{@+5oB?4y`LWl@=LBWeLP8K;_F8K1MiC&qyPW_ literal 0 HcmV?d00001 diff --git a/test/tools/llvm-readobj/mips-reginfo.test b/test/tools/llvm-readobj/mips-reginfo.test new file mode 100644 index 00000000000..d983d0a6344 --- /dev/null +++ b/test/tools/llvm-readobj/mips-reginfo.test @@ -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: } diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 85363f152bf..3a1f1ddcd40 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -58,6 +58,7 @@ public: void printAttributes() override; void printMipsPLTGOT() override; void printMipsABIFlags() override; + void printMipsReginfo() override; private: typedef ELFFile ELFO; @@ -1424,3 +1425,30 @@ template void ELFDumper::printMipsABIFlags() { W.printFlags("Flags 1", Flags->flags1, makeArrayRef(ElfMipsFlags1)); W.printHex("Flags 2", Flags->flags2); } + +template void ELFDumper::printMipsReginfo() { + const Elf_Shdr *Shdr = findSectionByName(*Obj, ".reginfo"); + if (!Shdr) { + W.startLine() << "There is no .reginfo section in the file.\n"; + return; + } + ErrorOr> Sec = Obj->getSectionContents(Shdr); + if (!Sec) { + W.startLine() << "The .reginfo section is empty.\n"; + return; + } + if (Sec->size() != sizeof(Elf_Mips_RegInfo)) { + W.startLine() << "The .reginfo section has a wrong size.\n"; + return; + } + + auto *Reginfo = reinterpret_cast *>(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]); +} diff --git a/tools/llvm-readobj/ObjDumper.h b/tools/llvm-readobj/ObjDumper.h index 5750d6ffd28..323f5e319cf 100644 --- a/tools/llvm-readobj/ObjDumper.h +++ b/tools/llvm-readobj/ObjDumper.h @@ -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() { } diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp index be7bbe94d9e..f960796a4cb 100644 --- a/tools/llvm-readobj/llvm-readobj.cpp +++ b/tools/llvm-readobj/llvm-readobj.cpp @@ -152,6 +152,10 @@ namespace opts { cl::opt MipsABIFlags("mips-abi-flags", cl::desc("Display the MIPS.abiflags section")); + // -mips-reginfo + cl::opt MipsReginfo("mips-reginfo", + cl::desc("Display the MIPS .reginfo section")); + // -coff-imports cl::opt COFFImports("coff-imports", cl::desc("Display the PE/COFF import table")); @@ -296,6 +300,8 @@ static void dumpObject(const ObjectFile *Obj) { Dumper->printMipsPLTGOT(); if (opts::MipsABIFlags) Dumper->printMipsABIFlags(); + if (opts::MipsReginfo) + Dumper->printMipsReginfo(); } if (opts::COFFImports) Dumper->printCOFFImports();