ARMAttributeParser.cpp revision 36b56886974eae4f9c5ebc96befd3e7bfe5de338
1//===--- ARMAttributeParser.cpp - ARM Attribute Information Printer -------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#include "ARMAttributeParser.h" 11#include "StreamWriter.h" 12#include "llvm/ADT/StringExtras.h" 13#include "llvm/Support/LEB128.h" 14 15using namespace llvm; 16using namespace llvm::ARMBuildAttrs; 17 18 19static const EnumEntry<unsigned> TagNames[] = { 20 { "Tag_File", ARMBuildAttrs::File }, 21 { "Tag_Section", ARMBuildAttrs::Section }, 22 { "Tag_Symbol", ARMBuildAttrs::Symbol }, 23}; 24 25template <typename type_, size_t size_> 26size_t countof(const type_ (&)[size_]) { 27 return size_; 28} 29 30namespace llvm { 31#define ATTRIBUTE_HANDLER(Attr_) \ 32 { ARMBuildAttrs::Attr_, &ARMAttributeParser::Attr_ } 33 34const ARMAttributeParser::DisplayHandler 35ARMAttributeParser::DisplayRoutines[] = { 36 { ARMBuildAttrs::CPU_raw_name, &ARMAttributeParser::StringAttribute, }, 37 { ARMBuildAttrs::CPU_name, &ARMAttributeParser::StringAttribute }, 38 ATTRIBUTE_HANDLER(CPU_arch), 39 ATTRIBUTE_HANDLER(CPU_arch_profile), 40 ATTRIBUTE_HANDLER(ARM_ISA_use), 41 ATTRIBUTE_HANDLER(THUMB_ISA_use), 42 ATTRIBUTE_HANDLER(FP_arch), 43 ATTRIBUTE_HANDLER(WMMX_arch), 44 ATTRIBUTE_HANDLER(Advanced_SIMD_arch), 45 ATTRIBUTE_HANDLER(PCS_config), 46 ATTRIBUTE_HANDLER(ABI_PCS_R9_use), 47 ATTRIBUTE_HANDLER(ABI_PCS_RW_data), 48 ATTRIBUTE_HANDLER(ABI_PCS_RO_data), 49 ATTRIBUTE_HANDLER(ABI_PCS_GOT_use), 50 ATTRIBUTE_HANDLER(ABI_PCS_wchar_t), 51 ATTRIBUTE_HANDLER(ABI_FP_rounding), 52 ATTRIBUTE_HANDLER(ABI_FP_denormal), 53 ATTRIBUTE_HANDLER(ABI_FP_exceptions), 54 ATTRIBUTE_HANDLER(ABI_FP_user_exceptions), 55 ATTRIBUTE_HANDLER(ABI_FP_number_model), 56 ATTRIBUTE_HANDLER(ABI_align_needed), 57 ATTRIBUTE_HANDLER(ABI_align_preserved), 58 ATTRIBUTE_HANDLER(ABI_enum_size), 59 ATTRIBUTE_HANDLER(ABI_HardFP_use), 60 ATTRIBUTE_HANDLER(ABI_VFP_args), 61 ATTRIBUTE_HANDLER(ABI_WMMX_args), 62 ATTRIBUTE_HANDLER(ABI_optimization_goals), 63 ATTRIBUTE_HANDLER(ABI_FP_optimization_goals), 64 ATTRIBUTE_HANDLER(compatibility), 65 ATTRIBUTE_HANDLER(CPU_unaligned_access), 66 ATTRIBUTE_HANDLER(FP_HP_extension), 67 ATTRIBUTE_HANDLER(ABI_FP_16bit_format), 68 ATTRIBUTE_HANDLER(MPextension_use), 69 ATTRIBUTE_HANDLER(DIV_use), 70 ATTRIBUTE_HANDLER(T2EE_use), 71 ATTRIBUTE_HANDLER(Virtualization_use), 72 ATTRIBUTE_HANDLER(nodefaults) 73}; 74 75#undef ATTRIBUTE_HANDLER 76 77uint64_t ARMAttributeParser::ParseInteger(const uint8_t *Data, 78 uint32_t &Offset) { 79 unsigned Length; 80 uint64_t Value = decodeULEB128(Data + Offset, &Length); 81 Offset = Offset + Length; 82 return Value; 83} 84 85StringRef ARMAttributeParser::ParseString(const uint8_t *Data, 86 uint32_t &Offset) { 87 const char *String = reinterpret_cast<const char*>(Data + Offset); 88 size_t Length = std::strlen(String); 89 Offset = Offset + Length + 1; 90 return StringRef(String, Length); 91} 92 93void ARMAttributeParser::IntegerAttribute(AttrType Tag, const uint8_t *Data, 94 uint32_t &Offset) { 95 SW.printNumber(ARMBuildAttrs::AttrTypeAsString(Tag), 96 ParseInteger(Data, Offset)); 97} 98 99void ARMAttributeParser::StringAttribute(AttrType Tag, const uint8_t *Data, 100 uint32_t &Offset) { 101 StringRef TagName = ARMBuildAttrs::AttrTypeAsString(Tag, /*TagPrefix*/false); 102 103 DictScope AS(SW, "Attribute"); 104 SW.printNumber("Tag", Tag); 105 if (!TagName.empty()) 106 SW.printString("TagName", TagName); 107 SW.printString("Value", ParseString(Data, Offset)); 108} 109 110void ARMAttributeParser::PrintAttribute(unsigned Tag, unsigned Value, 111 StringRef ValueDesc) { 112 StringRef TagName = ARMBuildAttrs::AttrTypeAsString(Tag, /*TagPrefix*/false); 113 114 DictScope AS(SW, "Attribute"); 115 SW.printNumber("Tag", Tag); 116 SW.printNumber("Value", Value); 117 if (!TagName.empty()) 118 SW.printString("TagName", TagName); 119 if (!ValueDesc.empty()) 120 SW.printString("Description", ValueDesc); 121} 122 123void ARMAttributeParser::CPU_arch(AttrType Tag, const uint8_t *Data, 124 uint32_t &Offset) { 125 static const char *Strings[] = { 126 "Pre-v4", "ARM v4", "ARM v4T", "ARM v5T", "ARM v5TE", "ARM v5TEJ", "ARM v6", 127 "ARM v6KZ", "ARM v6T2", "ARM v6K", "ARM v7", "ARM v6-M", "ARM v6S-M", 128 "ARM v7E-M", "ARM v8" 129 }; 130 131 uint64_t Value = ParseInteger(Data, Offset); 132 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 133 PrintAttribute(Tag, Value, ValueDesc); 134} 135 136void ARMAttributeParser::CPU_arch_profile(AttrType Tag, const uint8_t *Data, 137 uint32_t &Offset) { 138 uint64_t Encoded = ParseInteger(Data, Offset); 139 140 StringRef Profile; 141 switch (Encoded) { 142 default: Profile = "Unknown"; break; 143 case 'A': Profile = "Application"; break; 144 case 'R': Profile = "Real-time"; break; 145 case 'M': Profile = "Microcontroller"; break; 146 case 'S': Profile = "Classic"; break; 147 case '0': Profile = "None"; break; 148 } 149 150 PrintAttribute(Tag, Encoded, Profile); 151} 152 153void ARMAttributeParser::ARM_ISA_use(AttrType Tag, const uint8_t *Data, 154 uint32_t &Offset) { 155 static const char *Strings[] = { "Not Permitted", "Permitted" }; 156 157 uint64_t Value = ParseInteger(Data, Offset); 158 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 159 PrintAttribute(Tag, Value, ValueDesc); 160} 161 162void ARMAttributeParser::THUMB_ISA_use(AttrType Tag, const uint8_t *Data, 163 uint32_t &Offset) { 164 static const char *Strings[] = { "Not Permitted", "Thumb-1", "Thumb-2" }; 165 166 uint64_t Value = ParseInteger(Data, Offset); 167 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 168 PrintAttribute(Tag, Value, ValueDesc); 169} 170 171void ARMAttributeParser::FP_arch(AttrType Tag, const uint8_t *Data, 172 uint32_t &Offset) { 173 static const char *Strings[] = { 174 "Not Permitted", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", 175 "VFPv4-D16", "ARMv8-a FP", "ARMv8-a FP-D16" 176 }; 177 178 uint64_t Value = ParseInteger(Data, Offset); 179 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 180 PrintAttribute(Tag, Value, ValueDesc); 181} 182 183void ARMAttributeParser::WMMX_arch(AttrType Tag, const uint8_t *Data, 184 uint32_t &Offset) { 185 static const char *Strings[] = { "Not Permitted", "WMMXv1", "WMMXv2" }; 186 187 uint64_t Value = ParseInteger(Data, Offset); 188 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 189 PrintAttribute(Tag, Value, ValueDesc); 190} 191 192void ARMAttributeParser::Advanced_SIMD_arch(AttrType Tag, const uint8_t *Data, 193 uint32_t &Offset) { 194 static const char *Strings[] = { 195 "Not Permitted", "NEONv1", "NEONv2+FMA", "ARMv8-a NEON" 196 }; 197 198 uint64_t Value = ParseInteger(Data, Offset); 199 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 200 PrintAttribute(Tag, Value, ValueDesc); 201} 202 203void ARMAttributeParser::PCS_config(AttrType Tag, const uint8_t *Data, 204 uint32_t &Offset) { 205 static const char *Strings[] = { 206 "None", "Bare Platform", "Linux Application", "Linux DSO", "Palm OS 2004", 207 "Reserved (Palm OS)", "Symbian OS 2004", "Reserved (Symbian OS)" 208 }; 209 210 uint64_t Value = ParseInteger(Data, Offset); 211 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 212 PrintAttribute(Tag, Value, ValueDesc); 213} 214 215void ARMAttributeParser::ABI_PCS_R9_use(AttrType Tag, const uint8_t *Data, 216 uint32_t &Offset) { 217 static const char *Strings[] = { "v6", "Static Base", "TLS", "Unused" }; 218 219 uint64_t Value = ParseInteger(Data, Offset); 220 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 221 PrintAttribute(Tag, Value, ValueDesc); 222} 223 224void ARMAttributeParser::ABI_PCS_RW_data(AttrType Tag, const uint8_t *Data, 225 uint32_t &Offset) { 226 static const char *Strings[] = { 227 "Absolute", "PC-relative", "SB-relative", "Not Permitted" 228 }; 229 230 uint64_t Value = ParseInteger(Data, Offset); 231 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 232 PrintAttribute(Tag, Value, ValueDesc); 233} 234 235void ARMAttributeParser::ABI_PCS_RO_data(AttrType Tag, const uint8_t *Data, 236 uint32_t &Offset) { 237 static const char *Strings[] = { "Absolute", "PC-relative", "Not Permitted" }; 238 239 uint64_t Value = ParseInteger(Data, Offset); 240 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 241 PrintAttribute(Tag, Value, ValueDesc); 242} 243 244void ARMAttributeParser::ABI_PCS_GOT_use(AttrType Tag, const uint8_t *Data, 245 uint32_t &Offset) { 246 static const char *Strings[] = { "Not Permitted", "Direct", "GOT-Indirect" }; 247 248 uint64_t Value = ParseInteger(Data, Offset); 249 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 250 PrintAttribute(Tag, Value, ValueDesc); 251} 252 253void ARMAttributeParser::ABI_PCS_wchar_t(AttrType Tag, const uint8_t *Data, 254 uint32_t &Offset) { 255 static const char *Strings[] = { 256 "Not Permitted", "Unknown", "2-byte", "Unknown", "4-byte" 257 }; 258 259 uint64_t Value = ParseInteger(Data, Offset); 260 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 261 PrintAttribute(Tag, Value, ValueDesc); 262} 263 264void ARMAttributeParser::ABI_FP_rounding(AttrType Tag, const uint8_t *Data, 265 uint32_t &Offset) { 266 static const char *Strings[] = { "IEEE-754", "Runtime" }; 267 268 uint64_t Value = ParseInteger(Data, Offset); 269 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 270 PrintAttribute(Tag, Value, ValueDesc); 271} 272 273void ARMAttributeParser::ABI_FP_denormal(AttrType Tag, const uint8_t *Data, 274 uint32_t &Offset) { 275 static const char *Strings[] = { "Unsupported", "IEEE-754", "Sign Only" }; 276 277 uint64_t Value = ParseInteger(Data, Offset); 278 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 279 PrintAttribute(Tag, Value, ValueDesc); 280} 281 282void ARMAttributeParser::ABI_FP_exceptions(AttrType Tag, const uint8_t *Data, 283 uint32_t &Offset) { 284 static const char *Strings[] = { "Not Permitted", "IEEE-754" }; 285 286 uint64_t Value = ParseInteger(Data, Offset); 287 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 288 PrintAttribute(Tag, Value, ValueDesc); 289} 290 291void ARMAttributeParser::ABI_FP_user_exceptions(AttrType Tag, 292 const uint8_t *Data, 293 uint32_t &Offset) { 294 static const char *Strings[] = { "Not Permitted", "IEEE-754" }; 295 296 uint64_t Value = ParseInteger(Data, Offset); 297 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 298 PrintAttribute(Tag, Value, ValueDesc); 299} 300 301void ARMAttributeParser::ABI_FP_number_model(AttrType Tag, const uint8_t *Data, 302 uint32_t &Offset) { 303 static const char *Strings[] = { 304 "Not Permitted", "Finite Only", "RTABI", "IEEE-754" 305 }; 306 307 uint64_t Value = ParseInteger(Data, Offset); 308 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 309 PrintAttribute(Tag, Value, ValueDesc); 310} 311 312void ARMAttributeParser::ABI_align_needed(AttrType Tag, const uint8_t *Data, 313 uint32_t &Offset) { 314 static const char *Strings[] = { 315 "Not Permitted", "8-byte alignment", "4-byte alignment", "Reserved" 316 }; 317 318 uint64_t Value = ParseInteger(Data, Offset); 319 320 std::string Description; 321 if (Value < countof(Strings)) 322 Description = std::string(Strings[Value]); 323 else if (Value <= 12) 324 Description = std::string("8-byte alignment, ") + utostr(1 << Value) 325 + std::string("-byte extended alignment"); 326 else 327 Description = "Invalid"; 328 329 PrintAttribute(Tag, Value, Description); 330} 331 332void ARMAttributeParser::ABI_align_preserved(AttrType Tag, const uint8_t *Data, 333 uint32_t &Offset) { 334 static const char *Strings[] = { 335 "Not Required", "8-byte data alignment", "8-byte data and code alignment", 336 "Reserved" 337 }; 338 339 uint64_t Value = ParseInteger(Data, Offset); 340 341 std::string Description; 342 if (Value < countof(Strings)) 343 Description = std::string(Strings[Value]); 344 else if (Value <= 12) 345 Description = std::string("8-byte stack alignment, ") + utostr(1 << Value) 346 + std::string("-byte data alignment"); 347 else 348 Description = "Invalid"; 349 350 PrintAttribute(Tag, Value, Description); 351} 352 353void ARMAttributeParser::ABI_enum_size(AttrType Tag, const uint8_t *Data, 354 uint32_t &Offset) { 355 static const char *Strings[] = { 356 "Not Permitted", "Packed", "Int32", "External Int32" 357 }; 358 359 uint64_t Value = ParseInteger(Data, Offset); 360 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 361 PrintAttribute(Tag, Value, ValueDesc); 362} 363 364void ARMAttributeParser::ABI_HardFP_use(AttrType Tag, const uint8_t *Data, 365 uint32_t &Offset) { 366 static const char *Strings[] = { 367 "Tag_FP_arch", "Single-Precision", "Reserved", "Tag_FP_arch (deprecated)" 368 }; 369 370 uint64_t Value = ParseInteger(Data, Offset); 371 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 372 PrintAttribute(Tag, Value, ValueDesc); 373} 374 375void ARMAttributeParser::ABI_VFP_args(AttrType Tag, const uint8_t *Data, 376 uint32_t &Offset) { 377 static const char *Strings[] = { 378 "AAPCS", "AAPCS VFP", "Custom", "Not Permitted" 379 }; 380 381 uint64_t Value = ParseInteger(Data, Offset); 382 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 383 PrintAttribute(Tag, Value, ValueDesc); 384} 385 386void ARMAttributeParser::ABI_WMMX_args(AttrType Tag, const uint8_t *Data, 387 uint32_t &Offset) { 388 static const char *Strings[] = { "AAPCS", "iWMMX", "Custom" }; 389 390 uint64_t Value = ParseInteger(Data, Offset); 391 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 392 PrintAttribute(Tag, Value, ValueDesc); 393} 394 395void ARMAttributeParser::ABI_optimization_goals(AttrType Tag, 396 const uint8_t *Data, 397 uint32_t &Offset) { 398 static const char *Strings[] = { 399 "None", "Speed", "Aggressive Speed", "Size", "Aggressive Size", "Debugging", 400 "Best Debugging" 401 }; 402 403 uint64_t Value = ParseInteger(Data, Offset); 404 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 405 PrintAttribute(Tag, Value, ValueDesc); 406} 407 408void ARMAttributeParser::ABI_FP_optimization_goals(AttrType Tag, 409 const uint8_t *Data, 410 uint32_t &Offset) { 411 static const char *Strings[] = { 412 "None", "Speed", "Aggressive Speed", "Size", "Aggressive Size", "Accuracy", 413 "Best Accuracy" 414 }; 415 416 uint64_t Value = ParseInteger(Data, Offset); 417 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 418 PrintAttribute(Tag, Value, ValueDesc); 419} 420 421void ARMAttributeParser::compatibility(AttrType Tag, const uint8_t *Data, 422 uint32_t &Offset) { 423 uint64_t Integer = ParseInteger(Data, Offset); 424 StringRef String = ParseString(Data, Offset); 425 426 DictScope AS(SW, "Attribute"); 427 SW.printNumber("Tag", Tag); 428 SW.startLine() << "Value: " << Integer << ", " << String << '\n'; 429 SW.printString("TagName", AttrTypeAsString(Tag, /*TagPrefix*/false)); 430 switch (Integer) { 431 case 0: 432 SW.printString("Description", StringRef("No Specific Requirements")); 433 break; 434 case 1: 435 SW.printString("Description", StringRef("AEABI Conformant")); 436 break; 437 default: 438 SW.printString("Description", StringRef("AEABI Non-Conformant")); 439 break; 440 } 441} 442 443void ARMAttributeParser::CPU_unaligned_access(AttrType Tag, const uint8_t *Data, 444 uint32_t &Offset) { 445 static const char *Strings[] = { "Not Permitted", "v6-style" }; 446 447 uint64_t Value = ParseInteger(Data, Offset); 448 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 449 PrintAttribute(Tag, Value, ValueDesc); 450} 451 452void ARMAttributeParser::FP_HP_extension(AttrType Tag, const uint8_t *Data, 453 uint32_t &Offset) { 454 static const char *Strings[] = { "If Available", "Permitted" }; 455 456 uint64_t Value = ParseInteger(Data, Offset); 457 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 458 PrintAttribute(Tag, Value, ValueDesc); 459} 460 461void ARMAttributeParser::ABI_FP_16bit_format(AttrType Tag, const uint8_t *Data, 462 uint32_t &Offset) { 463 static const char *Strings[] = { "Not Permitted", "IEEE-754", "VFPv3" }; 464 465 uint64_t Value = ParseInteger(Data, Offset); 466 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 467 PrintAttribute(Tag, Value, ValueDesc); 468} 469 470void ARMAttributeParser::MPextension_use(AttrType Tag, const uint8_t *Data, 471 uint32_t &Offset) { 472 static const char *Strings[] = { "Not Permitted", "Permitted" }; 473 474 uint64_t Value = ParseInteger(Data, Offset); 475 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 476 PrintAttribute(Tag, Value, ValueDesc); 477} 478 479void ARMAttributeParser::DIV_use(AttrType Tag, const uint8_t *Data, 480 uint32_t &Offset) { 481 static const char *Strings[] = { 482 "If Available", "Not Permitted", "Permitted" 483 }; 484 485 uint64_t Value = ParseInteger(Data, Offset); 486 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 487 PrintAttribute(Tag, Value, ValueDesc); 488} 489 490void ARMAttributeParser::T2EE_use(AttrType Tag, const uint8_t *Data, 491 uint32_t &Offset) { 492 static const char *Strings[] = { "Not Permitted", "Permitted" }; 493 494 uint64_t Value = ParseInteger(Data, Offset); 495 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 496 PrintAttribute(Tag, Value, ValueDesc); 497} 498 499void ARMAttributeParser::Virtualization_use(AttrType Tag, const uint8_t *Data, 500 uint32_t &Offset) { 501 static const char *Strings[] = { 502 "Not Permitted", "TrustZone", "Virtualization Extensions", 503 "TrustZone + Virtualization Extensions" 504 }; 505 506 uint64_t Value = ParseInteger(Data, Offset); 507 StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL; 508 PrintAttribute(Tag, Value, ValueDesc); 509} 510 511void ARMAttributeParser::nodefaults(AttrType Tag, const uint8_t *Data, 512 uint32_t &Offset) { 513 uint64_t Value = ParseInteger(Data, Offset); 514 PrintAttribute(Tag, Value, "Unspecified Tags UNDEFINED"); 515} 516 517void ARMAttributeParser::ParseIndexList(const uint8_t *Data, uint32_t &Offset, 518 SmallVectorImpl<uint8_t> &IndexList) { 519 for (;;) { 520 unsigned Length; 521 uint64_t Value = decodeULEB128(Data + Offset, &Length); 522 Offset = Offset + Length; 523 if (Value == 0) 524 break; 525 IndexList.push_back(Value); 526 } 527} 528 529void ARMAttributeParser::ParseAttributeList(const uint8_t *Data, 530 uint32_t &Offset, uint32_t Length) { 531 while (Offset < Length) { 532 unsigned Length; 533 uint64_t Tag = decodeULEB128(Data + Offset, &Length); 534 Offset += Length; 535 536 bool Handled = false; 537 for (unsigned AHI = 0, AHE = countof(DisplayRoutines); 538 AHI != AHE && !Handled; ++AHI) { 539 if (DisplayRoutines[AHI].Attribute == Tag) { 540 (this->*DisplayRoutines[AHI].Routine)(ARMBuildAttrs::AttrType(Tag), 541 Data, Offset); 542 Handled = true; 543 break; 544 } 545 } 546 if (!Handled) { 547 if (Tag < 32) { 548 errs() << "unhandled AEABI Tag " << Tag 549 << " (" << ARMBuildAttrs::AttrTypeAsString(Tag) << ")\n"; 550 continue; 551 } 552 553 if (Tag % 2 == 0) 554 IntegerAttribute(ARMBuildAttrs::AttrType(Tag), Data, Offset); 555 else 556 StringAttribute(ARMBuildAttrs::AttrType(Tag), Data, Offset); 557 } 558 } 559} 560 561void ARMAttributeParser::ParseSubsection(const uint8_t *Data, uint32_t Length) { 562 uint32_t Offset = sizeof(uint32_t); /* SectionLength */ 563 564 SW.printNumber("SectionLength", Length); 565 566 const char *VendorName = reinterpret_cast<const char*>(Data + Offset); 567 size_t VendorNameLength = std::strlen(VendorName); 568 SW.printString("Vendor", StringRef(VendorName, VendorNameLength)); 569 Offset = Offset + VendorNameLength + 1; 570 571 if (StringRef(VendorName, VendorNameLength).lower() != "aeabi") 572 return; 573 574 while (Offset < Length) { 575 /// Tag_File | Tag_Section | Tag_Symbol uleb128:byte-size 576 uint8_t Tag = Data[Offset]; 577 SW.printEnum("Tag", Tag, makeArrayRef(TagNames)); 578 Offset = Offset + sizeof(Tag); 579 580 uint32_t Size = 581 *reinterpret_cast<const support::ulittle32_t*>(Data + Offset); 582 SW.printNumber("Size", Size); 583 Offset = Offset + sizeof(Size); 584 585 if (Size > Length) { 586 errs() << "subsection length greater than section length\n"; 587 return; 588 } 589 590 StringRef ScopeName, IndexName; 591 SmallVector<uint8_t, 8> Indicies; 592 switch (Tag) { 593 case ARMBuildAttrs::File: 594 ScopeName = "FileAttributes"; 595 break; 596 case ARMBuildAttrs::Section: 597 ScopeName = "SectionAttributes"; 598 IndexName = "Sections"; 599 ParseIndexList(Data, Offset, Indicies); 600 break; 601 case ARMBuildAttrs::Symbol: 602 ScopeName = "SymbolAttributes"; 603 IndexName = "Symbols"; 604 ParseIndexList(Data, Offset, Indicies); 605 break; 606 default: 607 errs() << "unrecognised tag: 0x" << utohexstr(Tag) << '\n'; 608 return; 609 } 610 611 DictScope ASS(SW, ScopeName); 612 613 if (!Indicies.empty()) 614 SW.printList(IndexName, Indicies); 615 616 ParseAttributeList(Data, Offset, Length); 617 } 618} 619 620void ARMAttributeParser::Parse(ArrayRef<uint8_t> Section) { 621 size_t Offset = 1; 622 unsigned SectionNumber = 0; 623 624 while (Offset < Section.size()) { 625 uint32_t SectionLength = 626 *reinterpret_cast<const support::ulittle32_t*>(Section.data() + Offset); 627 628 SW.startLine() << "Section " << ++SectionNumber << " {\n"; 629 SW.indent(); 630 631 ParseSubsection(Section.data() + Offset, SectionLength); 632 Offset = Offset + SectionLength; 633 634 SW.unindent(); 635 SW.startLine() << "}\n"; 636 } 637} 638} 639 640