ARMAttributeParser.cpp 23 KB

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