llvm.org GIT mirror llvm / 125d646
[llvm-readobj] Print MIPS .MIPS.options section content .MIPS.options section specifies miscellaneous options to be applied to an object file. LLVM as well as modern versions of GNU tools emit the only type of the options - ODK_REGINFO. The patch teaches llvm-readobj to print details of the ODK_REGINFO and skip contents of other options. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268478 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Atanasyan 4 years ago
5 changed file(s) with 81 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
0 RUN: llvm-readobj -mips-options %p/Inputs/options.obj.elf-mipsel | FileCheck %s
1
2 CHECK: MIPS Options {
3 CHECK-NEXT: ODK_REGINFO {
4 CHECK-NEXT: GP: 0x0
5 CHECK-NEXT: General Mask: 0xF2000017
6 CHECK-NEXT: Co-Proc Mask0: 0x0
7 CHECK-NEXT: Co-Proc Mask1: 0x0
8 CHECK-NEXT: Co-Proc Mask2: 0x0
9 CHECK-NEXT: Co-Proc Mask3: 0x0
10 CHECK-NEXT: }
11 CHECK-NEXT: }
119119 void printMipsPLTGOT() override;
120120 void printMipsABIFlags() override;
121121 void printMipsReginfo() override;
122 void printMipsOptions() override;
122123
123124 void printStackMap() const override;
124125
12131214 LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_MIPS16)
12141215 };
12151216
1217 static const char *getElfMipsOptionsOdkType(unsigned Odk) {
1218 switch (Odk) {
1219 LLVM_READOBJ_ENUM_CASE(ELF, ODK_NULL);
1220 LLVM_READOBJ_ENUM_CASE(ELF, ODK_REGINFO);
1221 LLVM_READOBJ_ENUM_CASE(ELF, ODK_EXCEPTIONS);
1222 LLVM_READOBJ_ENUM_CASE(ELF, ODK_PAD);
1223 LLVM_READOBJ_ENUM_CASE(ELF, ODK_HWPATCH);
1224 LLVM_READOBJ_ENUM_CASE(ELF, ODK_FILL);
1225 LLVM_READOBJ_ENUM_CASE(ELF, ODK_TAGS);
1226 LLVM_READOBJ_ENUM_CASE(ELF, ODK_HWAND);
1227 LLVM_READOBJ_ENUM_CASE(ELF, ODK_HWOR);
1228 LLVM_READOBJ_ENUM_CASE(ELF, ODK_GP_GROUP);
1229 LLVM_READOBJ_ENUM_CASE(ELF, ODK_IDENT);
1230 LLVM_READOBJ_ENUM_CASE(ELF, ODK_PAGESIZE);
1231 default:
1232 return "Unknown";
1233 }
1234 }
1235
12161236 template
12171237 ELFDumper::ELFDumper(const ELFFile *Obj, ScopedPrinter &Writer)
12181238 : ObjDumper(Writer), Obj(Obj) {
21862206 W.printHex("Flags 2", Flags->flags2);
21872207 }
21882208
2209 template
2210 static void printMipsReginfoData(ScopedPrinter &W,
2211 const Elf_Mips_RegInfo &Reginfo) {
2212 W.printHex("GP", Reginfo.ri_gp_value);
2213 W.printHex("General Mask", Reginfo.ri_gprmask);
2214 W.printHex("Co-Proc Mask0", Reginfo.ri_cprmask[0]);
2215 W.printHex("Co-Proc Mask1", Reginfo.ri_cprmask[1]);
2216 W.printHex("Co-Proc Mask2", Reginfo.ri_cprmask[2]);
2217 W.printHex("Co-Proc Mask3", Reginfo.ri_cprmask[3]);
2218 }
2219
21892220 template void ELFDumper::printMipsReginfo() {
21902221 const Elf_Shdr *Shdr = findSectionByName(*Obj, ".reginfo");
21912222 if (!Shdr) {
21982229 return;
21992230 }
22002231
2232 DictScope GS(W, "MIPS RegInfo");
22012233 auto *Reginfo = reinterpret_cast *>(Sec.data());
2202
2203 DictScope GS(W, "MIPS RegInfo");
2204 W.printHex("GP", Reginfo->ri_gp_value);
2205 W.printHex("General Mask", Reginfo->ri_gprmask);
2206 W.printHex("Co-Proc Mask0", Reginfo->ri_cprmask[0]);
2207 W.printHex("Co-Proc Mask1", Reginfo->ri_cprmask[1]);
2208 W.printHex("Co-Proc Mask2", Reginfo->ri_cprmask[2]);
2209 W.printHex("Co-Proc Mask3", Reginfo->ri_cprmask[3]);
2234 printMipsReginfoData(W, *Reginfo);
2235 }
2236
2237 template void ELFDumper::printMipsOptions() {
2238 const Elf_Shdr *Shdr = findSectionByName(*Obj, ".MIPS.options");
2239 if (!Shdr) {
2240 W.startLine() << "There is no .MIPS.options section in the file.\n";
2241 return;
2242 }
2243
2244 DictScope GS(W, "MIPS Options");
2245
2246 ArrayRef Sec = unwrapOrError(Obj->getSectionContents(Shdr));
2247 while (!Sec.empty()) {
2248 if (Sec.size() < sizeof(Elf_Mips_Options)) {
2249 W.startLine() << "The .MIPS.options section has a wrong size.\n";
2250 return;
2251 }
2252 auto *O = reinterpret_cast *>(Sec.data());
2253 DictScope GS(W, getElfMipsOptionsOdkType(O->kind));
2254 switch (O->kind) {
2255 case ODK_REGINFO:
2256 printMipsReginfoData(W, O->getRegInfo());
2257 break;
2258 default:
2259 W.startLine() << "Unsupported MIPS options tag.\n";
2260 break;
2261 }
2262 Sec = Sec.slice(O->size);
2263 }
22102264 }
22112265
22122266 template void ELFDumper::printStackMap() const {
5151 virtual void printMipsPLTGOT() { }
5252 virtual void printMipsABIFlags() { }
5353 virtual void printMipsReginfo() { }
54 virtual void printMipsOptions() { }
5455
5556 // Only implemented for PE/COFF.
5657 virtual void printCOFFImports() { }
166166 // -mips-reginfo
167167 cl::opt MipsReginfo("mips-reginfo",
168168 cl::desc("Display the MIPS .reginfo section"));
169
170 // -mips-options
171 cl::opt MipsOptions("mips-options",
172 cl::desc("Display the MIPS .MIPS.options section"));
169173
170174 // -coff-imports
171175 cl::opt
362366 Dumper->printMipsABIFlags();
363367 if (opts::MipsReginfo)
364368 Dumper->printMipsReginfo();
369 if (opts::MipsOptions)
370 Dumper->printMipsOptions();
365371 }
366372 if (opts::SectionGroups)
367373 Dumper->printGroupSections();