llvm.org GIT mirror llvm / ef7c256
[llvm-readobj] Print .MIPS.abiflags section content This change adds new flag -mips-abi-flags to the llvm-readobj. This flag forces printing of .MIPS.abiflags section content. https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking#10.2.1._.MIPS.abiflags git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236737 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Atanasyan 5 years ago
7 changed file(s) with 188 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
488488 Elf_Xword p_align; // Segment alignment constraint
489489 };
490490
491 // .MIPS.abiflags section content
492 template struct Elf_Mips_ABIFlags {
493 LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
494 Elf_Half version; // Version of the structure
495 uint8_t isa_level; // ISA level: 1-5, 32, and 64
496 uint8_t isa_rev; // ISA revision (0 for MIPS I - MIPS V)
497 uint8_t gpr_size; // General purpose registers size
498 uint8_t cpr1_size; // Co-processor 1 registers size
499 uint8_t cpr2_size; // Co-processor 2 registers size
500 uint8_t fp_abi; // Floating-point ABI flag
501 Elf_Word isa_ext; // Processor-specific extension
502 Elf_Word ases; // ASEs flags
503 Elf_Word flags1; // General flags
504 Elf_Word flags2; // General flags
505 };
506
491507 } // end namespace object.
492508 } // end namespace llvm.
493509
0 RUN: llvm-readobj -mips-abi-flags %p/Inputs/abiflags.obj.elf-mipsel | \
1 RUN: FileCheck -check-prefix=EL64 %s
2 RUN: llvm-readobj -mips-abi-flags %p/Inputs/abiflags.obj.elf-mips | \
3 RUN: FileCheck -check-prefix=BE32 %s
4
5 EL64: MIPS ABI Flags {
6 EL64-NEXT: Version: 0
7 EL64-NEXT: ISA: MIPS64r5
8 EL64-NEXT: ISA Extension: Cavium Networks Octeon3 (0x13)
9 EL64-NEXT: ASEs [ (0x103)
10 EL64-NEXT: DSP (0x1)
11 EL64-NEXT: DSPR2 (0x2)
12 EL64-NEXT: VZ (0x100)
13 EL64-NEXT: ]
14 EL64-NEXT: FP ABI: Hard float (double precision) (0x1)
15 EL64-NEXT: GPR size: 64
16 EL64-NEXT: CPR1 size: 64
17 EL64-NEXT: CPR2 size: 0
18 EL64-NEXT: Flags 1 [ (0x1)
19 EL64-NEXT: ODDSPREG (0x1)
20 EL64-NEXT: ]
21 EL64-NEXT: Flags 2: 0x0
22 EL64-NEXT: }
23
24 BE32: MIPS ABI Flags {
25 BE32-NEXT: Version: 0
26 BE32-NEXT: ISA: MIPS32r2
27 BE32-NEXT: ISA Extension: None (0x0)
28 BE32-NEXT: ASEs [ (0x803)
29 BE32-NEXT: DSP (0x1)
30 BE32-NEXT: DSPR2 (0x2)
31 BE32-NEXT: microMIPS (0x800)
32 BE32-NEXT: ]
33 BE32-NEXT: FP ABI: Soft float (0x3)
34 BE32-NEXT: GPR size: 32
35 BE32-NEXT: CPR1 size: 0
36 BE32-NEXT: CPR2 size: 0
37 BE32-NEXT: Flags 1 [ (0x1)
38 BE32-NEXT: ODDSPREG (0x1)
39 BE32-NEXT: ]
40 BE32-NEXT: Flags 2: 0x0
41 BE32-NEXT: }
2525 #include "llvm/Support/Compiler.h"
2626 #include "llvm/Support/Format.h"
2727 #include "llvm/Support/MathExtras.h"
28 #include "llvm/Support/MipsABIFlags.h"
2829 #include "llvm/Support/raw_ostream.h"
2930
3031 using namespace llvm;
5556
5657 void printAttributes() override;
5758 void printMipsPLTGOT() override;
59 void printMipsABIFlags() override;
5860
5961 private:
6062 typedef ELFFile ELFO;
166168 for (const auto &Shdr : Obj->sections())
167169 if (Shdr.sh_addr == Addr)
168170 return &Shdr;
171 return nullptr;
172 }
173
174 template
175 static const typename ELFFile::Elf_Shdr *
176 findSectionByName(const ELFFile &Obj, StringRef Name) {
177 for (const auto &Shdr : Obj.sections()) {
178 if (Name == errorOrDefault(Obj.getSectionName(&Shdr)))
179 return &Shdr;
180 }
169181 return nullptr;
170182 }
171183
12481260
12491261 MipsGOTParser(Obj, W).parseGOT(*GotShdr);
12501262 }
1263
1264 static const EnumEntry ElfMipsISAExtType[] = {
1265 {"None", Mips::AFL_EXT_NONE},
1266 {"Broadcom SB-1", Mips::AFL_EXT_SB1},
1267 {"Cavium Networks Octeon", Mips::AFL_EXT_OCTEON},
1268 {"Cavium Networks Octeon2", Mips::AFL_EXT_OCTEON2},
1269 {"Cavium Networks OcteonP", Mips::AFL_EXT_OCTEONP},
1270 {"Cavium Networks Octeon3", Mips::AFL_EXT_OCTEON3},
1271 {"LSI R4010", Mips::AFL_EXT_4010},
1272 {"Loongson 2E", Mips::AFL_EXT_LOONGSON_2E},
1273 {"Loongson 2F", Mips::AFL_EXT_LOONGSON_2F},
1274 {"Loongson 3A", Mips::AFL_EXT_LOONGSON_3A},
1275 {"MIPS R4650", Mips::AFL_EXT_4650},
1276 {"MIPS R5900", Mips::AFL_EXT_5900},
1277 {"MIPS R10000", Mips::AFL_EXT_10000},
1278 {"NEC VR4100", Mips::AFL_EXT_4100},
1279 {"NEC VR4111/VR4181", Mips::AFL_EXT_4111},
1280 {"NEC VR4120", Mips::AFL_EXT_4120},
1281 {"NEC VR5400", Mips::AFL_EXT_5400},
1282 {"NEC VR5500", Mips::AFL_EXT_5500},
1283 {"RMI Xlr", Mips::AFL_EXT_XLR},
1284 {"Toshiba R3900", Mips::AFL_EXT_3900}
1285 };
1286
1287 static const EnumEntry ElfMipsASEFlags[] = {
1288 {"DSP", Mips::AFL_ASE_DSP},
1289 {"DSPR2", Mips::AFL_ASE_DSPR2},
1290 {"Enhanced VA Scheme", Mips::AFL_ASE_EVA},
1291 {"MCU", Mips::AFL_ASE_MCU},
1292 {"MDMX", Mips::AFL_ASE_MDMX},
1293 {"MIPS-3D", Mips::AFL_ASE_MIPS3D},
1294 {"MT", Mips::AFL_ASE_MT},
1295 {"SmartMIPS", Mips::AFL_ASE_SMARTMIPS},
1296 {"VZ", Mips::AFL_ASE_VIRT},
1297 {"MSA", Mips::AFL_ASE_MSA},
1298 {"MIPS16", Mips::AFL_ASE_MIPS16},
1299 {"microMIPS", Mips::AFL_ASE_MICROMIPS},
1300 {"XPA", Mips::AFL_ASE_XPA}
1301 };
1302
1303 static const EnumEntry ElfMipsFpABIType[] = {
1304 {"Hard or soft float", Mips::Val_GNU_MIPS_ABI_FP_ANY},
1305 {"Hard float (double precision)", Mips::Val_GNU_MIPS_ABI_FP_DOUBLE},
1306 {"Hard float (single precision)", Mips::Val_GNU_MIPS_ABI_FP_SINGLE},
1307 {"Soft float", Mips::Val_GNU_MIPS_ABI_FP_SOFT},
1308 {"Hard float (MIPS32r2 64-bit FPU 12 callee-saved)",
1309 Mips::Val_GNU_MIPS_ABI_FP_OLD_64},
1310 {"Hard float (32-bit CPU, Any FPU)", Mips::Val_GNU_MIPS_ABI_FP_XX},
1311 {"Hard float (32-bit CPU, 64-bit FPU)", Mips::Val_GNU_MIPS_ABI_FP_64},
1312 {"Hard float compat (32-bit CPU, 64-bit FPU)",
1313 Mips::Val_GNU_MIPS_ABI_FP_64A}
1314 };
1315
1316 static const EnumEntry ElfMipsFlags1[] {
1317 {"ODDSPREG", Mips::AFL_FLAGS1_ODDSPREG},
1318 };
1319
1320 static int getMipsRegisterSize(uint8_t Flag) {
1321 switch (Flag) {
1322 case Mips::AFL_REG_NONE:
1323 return 0;
1324 case Mips::AFL_REG_32:
1325 return 32;
1326 case Mips::AFL_REG_64:
1327 return 64;
1328 case Mips::AFL_REG_128:
1329 return 128;
1330 default:
1331 return -1;
1332 }
1333 }
1334
1335 template void ELFDumper::printMipsABIFlags() {
1336 const Elf_Shdr *Shdr = findSectionByName(*Obj, ".MIPS.abiflags");
1337 if (!Shdr) {
1338 W.startLine() << "There is no .MIPS.abiflags section in the file.\n";
1339 return;
1340 }
1341 ErrorOr> Sec = Obj->getSectionContents(Shdr);
1342 if (!Sec) {
1343 W.startLine() << "The .MIPS.abiflags section is empty.\n";
1344 return;
1345 }
1346 if (Sec->size() != sizeof(Elf_Mips_ABIFlags)) {
1347 W.startLine() << "The .MIPS.abiflags section has a wrong size.\n";
1348 return;
1349 }
1350
1351 auto *Flags = reinterpret_cast *>(Sec->data());
1352
1353 raw_ostream &OS = W.getOStream();
1354 DictScope GS(W, "MIPS ABI Flags");
1355
1356 W.printNumber("Version", Flags->version);
1357 W.startLine() << "ISA: ";
1358 if (Flags->isa_rev <= 1)
1359 OS << format("MIPS%u", Flags->isa_level);
1360 else
1361 OS << format("MIPS%ur%u", Flags->isa_level, Flags->isa_rev);
1362 OS << "\n";
1363 W.printEnum("ISA Extension", Flags->isa_ext, makeArrayRef(ElfMipsISAExtType));
1364 W.printFlags("ASEs", Flags->ases, makeArrayRef(ElfMipsASEFlags));
1365 W.printEnum("FP ABI", Flags->fp_abi, makeArrayRef(ElfMipsFpABIType));
1366 W.printNumber("GPR size", getMipsRegisterSize(Flags->gpr_size));
1367 W.printNumber("CPR1 size", getMipsRegisterSize(Flags->cpr1_size));
1368 W.printNumber("CPR2 size", getMipsRegisterSize(Flags->cpr2_size));
1369 W.printFlags("Flags 1", Flags->flags1, makeArrayRef(ElfMipsFlags1));
1370 W.printHex("Flags 2", Flags->flags2);
1371 }
4141
4242 // Only implemented for MIPS ELF at this time.
4343 virtual void printMipsPLTGOT() { }
44 virtual void printMipsABIFlags() { }
4445
4546 // Only implemented for PE/COFF.
4647 virtual void printCOFFImports() { }
146146 cl::opt
147147 MipsPLTGOT("mips-plt-got",
148148 cl::desc("Display the MIPS GOT and PLT GOT sections"));
149
150 // -mips-abi-flags
151 cl::opt MipsABIFlags("mips-abi-flags",
152 cl::desc("Display the MIPS.abiflags section"));
149153
150154 // -coff-imports
151155 cl::opt
286290 if (Obj->getArch() == llvm::Triple::arm && Obj->isELF())
287291 if (opts::ARMAttributes)
288292 Dumper->printAttributes();
289 if (isMipsArch(Obj->getArch()) && Obj->isELF())
293 if (isMipsArch(Obj->getArch()) && Obj->isELF()) {
290294 if (opts::MipsPLTGOT)
291295 Dumper->printMipsPLTGOT();
296 if (opts::MipsABIFlags)
297 Dumper->printMipsABIFlags();
298 }
292299 if (opts::COFFImports)
293300 Dumper->printCOFFImports();
294301 if (opts::COFFExports)