XCOFFYAML.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===----- XCOFFYAML.h - XCOFF YAMLIO implementation ------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file declares classes for handling the YAML representation of XCOFF.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_OBJECTYAML_XCOFFYAML_H
  18. #define LLVM_OBJECTYAML_XCOFFYAML_H
  19. #include "llvm/BinaryFormat/XCOFF.h"
  20. #include "llvm/ObjectYAML/YAML.h"
  21. #include <vector>
  22. namespace llvm {
  23. namespace XCOFFYAML {
  24. struct FileHeader {
  25. llvm::yaml::Hex16 Magic;
  26. uint16_t NumberOfSections;
  27. int32_t TimeStamp;
  28. llvm::yaml::Hex64 SymbolTableOffset;
  29. int32_t NumberOfSymTableEntries;
  30. uint16_t AuxHeaderSize;
  31. llvm::yaml::Hex16 Flags;
  32. };
  33. struct AuxiliaryHeader {
  34. Optional<llvm::yaml::Hex16> Magic;
  35. Optional<llvm::yaml::Hex16> Version;
  36. Optional<llvm::yaml::Hex64> TextStartAddr;
  37. Optional<llvm::yaml::Hex64> DataStartAddr;
  38. Optional<llvm::yaml::Hex64> TOCAnchorAddr;
  39. Optional<uint16_t> SecNumOfEntryPoint;
  40. Optional<uint16_t> SecNumOfText;
  41. Optional<uint16_t> SecNumOfData;
  42. Optional<uint16_t> SecNumOfTOC;
  43. Optional<uint16_t> SecNumOfLoader;
  44. Optional<uint16_t> SecNumOfBSS;
  45. Optional<llvm::yaml::Hex16> MaxAlignOfText;
  46. Optional<llvm::yaml::Hex16> MaxAlignOfData;
  47. Optional<llvm::yaml::Hex16> ModuleType;
  48. Optional<llvm::yaml::Hex8> CpuFlag;
  49. Optional<llvm::yaml::Hex8> CpuType;
  50. Optional<llvm::yaml::Hex8> TextPageSize;
  51. Optional<llvm::yaml::Hex8> DataPageSize;
  52. Optional<llvm::yaml::Hex8> StackPageSize;
  53. Optional<llvm::yaml::Hex8> FlagAndTDataAlignment;
  54. Optional<llvm::yaml::Hex64> TextSize;
  55. Optional<llvm::yaml::Hex64> InitDataSize;
  56. Optional<llvm::yaml::Hex64> BssDataSize;
  57. Optional<llvm::yaml::Hex64> EntryPointAddr;
  58. Optional<llvm::yaml::Hex64> MaxStackSize;
  59. Optional<llvm::yaml::Hex64> MaxDataSize;
  60. Optional<uint16_t> SecNumOfTData;
  61. Optional<uint16_t> SecNumOfTBSS;
  62. Optional<llvm::yaml::Hex16> Flag;
  63. };
  64. struct Relocation {
  65. llvm::yaml::Hex64 VirtualAddress;
  66. llvm::yaml::Hex64 SymbolIndex;
  67. llvm::yaml::Hex8 Info;
  68. llvm::yaml::Hex8 Type;
  69. };
  70. struct Section {
  71. StringRef SectionName;
  72. llvm::yaml::Hex64 Address;
  73. llvm::yaml::Hex64 Size;
  74. llvm::yaml::Hex64 FileOffsetToData;
  75. llvm::yaml::Hex64 FileOffsetToRelocations;
  76. llvm::yaml::Hex64 FileOffsetToLineNumbers; // Line number pointer. Not supported yet.
  77. llvm::yaml::Hex16 NumberOfRelocations;
  78. llvm::yaml::Hex16 NumberOfLineNumbers; // Line number counts. Not supported yet.
  79. uint32_t Flags;
  80. yaml::BinaryRef SectionData;
  81. std::vector<Relocation> Relocations;
  82. };
  83. enum AuxSymbolType : uint8_t {
  84. AUX_EXCEPT = 255,
  85. AUX_FCN = 254,
  86. AUX_SYM = 253,
  87. AUX_FILE = 252,
  88. AUX_CSECT = 251,
  89. AUX_SECT = 250,
  90. AUX_STAT = 249
  91. };
  92. struct AuxSymbolEnt {
  93. AuxSymbolType Type;
  94. explicit AuxSymbolEnt(AuxSymbolType T) : Type(T) {}
  95. virtual ~AuxSymbolEnt();
  96. };
  97. struct FileAuxEnt : AuxSymbolEnt {
  98. Optional<StringRef> FileNameOrString;
  99. Optional<XCOFF::CFileStringType> FileStringType;
  100. FileAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_FILE) {}
  101. static bool classof(const AuxSymbolEnt *S) {
  102. return S->Type == AuxSymbolType::AUX_FILE;
  103. }
  104. };
  105. struct CsectAuxEnt : AuxSymbolEnt {
  106. // Only for XCOFF32.
  107. Optional<uint32_t> SectionOrLength;
  108. Optional<uint32_t> StabInfoIndex;
  109. Optional<uint16_t> StabSectNum;
  110. // Only for XCOFF64.
  111. Optional<uint32_t> SectionOrLengthLo;
  112. Optional<uint32_t> SectionOrLengthHi;
  113. // Common fields for both XCOFF32 and XCOFF64.
  114. Optional<uint32_t> ParameterHashIndex;
  115. Optional<uint16_t> TypeChkSectNum;
  116. Optional<uint8_t> SymbolAlignmentAndType;
  117. Optional<XCOFF::StorageMappingClass> StorageMappingClass;
  118. CsectAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_CSECT) {}
  119. static bool classof(const AuxSymbolEnt *S) {
  120. return S->Type == AuxSymbolType::AUX_CSECT;
  121. }
  122. };
  123. struct FunctionAuxEnt : AuxSymbolEnt {
  124. Optional<uint32_t> OffsetToExceptionTbl; // Only for XCOFF32.
  125. Optional<uint64_t> PtrToLineNum;
  126. Optional<uint32_t> SizeOfFunction;
  127. Optional<int32_t> SymIdxOfNextBeyond;
  128. FunctionAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_FCN) {}
  129. static bool classof(const AuxSymbolEnt *S) {
  130. return S->Type == AuxSymbolType::AUX_FCN;
  131. }
  132. };
  133. struct ExcpetionAuxEnt : AuxSymbolEnt {
  134. Optional<uint64_t> OffsetToExceptionTbl;
  135. Optional<uint32_t> SizeOfFunction;
  136. Optional<int32_t> SymIdxOfNextBeyond;
  137. ExcpetionAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_EXCEPT) {}
  138. static bool classof(const AuxSymbolEnt *S) {
  139. return S->Type == AuxSymbolType::AUX_EXCEPT;
  140. }
  141. }; // Only for XCOFF64.
  142. struct BlockAuxEnt : AuxSymbolEnt {
  143. // Only for XCOFF32.
  144. Optional<uint16_t> LineNumHi;
  145. Optional<uint16_t> LineNumLo;
  146. // Only for XCOFF64.
  147. Optional<uint32_t> LineNum;
  148. BlockAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_SYM) {}
  149. static bool classof(const AuxSymbolEnt *S) {
  150. return S->Type == AuxSymbolType::AUX_SYM;
  151. }
  152. };
  153. struct SectAuxEntForDWARF : AuxSymbolEnt {
  154. Optional<uint32_t> LengthOfSectionPortion;
  155. Optional<uint32_t> NumberOfRelocEnt;
  156. SectAuxEntForDWARF() : AuxSymbolEnt(AuxSymbolType::AUX_SECT) {}
  157. static bool classof(const AuxSymbolEnt *S) {
  158. return S->Type == AuxSymbolType::AUX_SECT;
  159. }
  160. };
  161. struct SectAuxEntForStat : AuxSymbolEnt {
  162. Optional<uint32_t> SectionLength;
  163. Optional<uint16_t> NumberOfRelocEnt;
  164. Optional<uint16_t> NumberOfLineNum;
  165. SectAuxEntForStat() : AuxSymbolEnt(AuxSymbolType::AUX_STAT) {}
  166. static bool classof(const AuxSymbolEnt *S) {
  167. return S->Type == AuxSymbolType::AUX_STAT;
  168. }
  169. }; // Only for XCOFF32.
  170. struct Symbol {
  171. StringRef SymbolName;
  172. llvm::yaml::Hex64 Value; // Symbol value; storage class-dependent.
  173. Optional<StringRef> SectionName;
  174. Optional<uint16_t> SectionIndex;
  175. llvm::yaml::Hex16 Type;
  176. XCOFF::StorageClass StorageClass;
  177. Optional<uint8_t> NumberOfAuxEntries;
  178. std::vector<std::unique_ptr<AuxSymbolEnt>> AuxEntries;
  179. };
  180. struct StringTable {
  181. Optional<uint32_t> ContentSize; // The total size of the string table.
  182. Optional<uint32_t> Length; // The value of the length field for the first
  183. // 4 bytes of the table.
  184. Optional<std::vector<StringRef>> Strings;
  185. Optional<yaml::BinaryRef> RawContent;
  186. };
  187. struct Object {
  188. FileHeader Header;
  189. Optional<AuxiliaryHeader> AuxHeader;
  190. std::vector<Section> Sections;
  191. std::vector<Symbol> Symbols;
  192. StringTable StrTbl;
  193. Object();
  194. };
  195. } // namespace XCOFFYAML
  196. } // namespace llvm
  197. LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Symbol)
  198. LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Relocation)
  199. LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Section)
  200. LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::XCOFFYAML::AuxSymbolEnt>)
  201. namespace llvm {
  202. namespace yaml {
  203. template <> struct ScalarBitSetTraits<XCOFF::SectionTypeFlags> {
  204. static void bitset(IO &IO, XCOFF::SectionTypeFlags &Value);
  205. };
  206. template <> struct ScalarEnumerationTraits<XCOFF::StorageClass> {
  207. static void enumeration(IO &IO, XCOFF::StorageClass &Value);
  208. };
  209. template <> struct ScalarEnumerationTraits<XCOFF::StorageMappingClass> {
  210. static void enumeration(IO &IO, XCOFF::StorageMappingClass &Value);
  211. };
  212. template <> struct ScalarEnumerationTraits<XCOFF::CFileStringType> {
  213. static void enumeration(IO &IO, XCOFF::CFileStringType &Type);
  214. };
  215. template <> struct ScalarEnumerationTraits<XCOFFYAML::AuxSymbolType> {
  216. static void enumeration(IO &IO, XCOFFYAML::AuxSymbolType &Type);
  217. };
  218. template <> struct MappingTraits<XCOFFYAML::FileHeader> {
  219. static void mapping(IO &IO, XCOFFYAML::FileHeader &H);
  220. };
  221. template <> struct MappingTraits<XCOFFYAML::AuxiliaryHeader> {
  222. static void mapping(IO &IO, XCOFFYAML::AuxiliaryHeader &AuxHdr);
  223. };
  224. template <> struct MappingTraits<std::unique_ptr<XCOFFYAML::AuxSymbolEnt>> {
  225. static void mapping(IO &IO, std::unique_ptr<XCOFFYAML::AuxSymbolEnt> &AuxSym);
  226. };
  227. template <> struct MappingTraits<XCOFFYAML::Symbol> {
  228. static void mapping(IO &IO, XCOFFYAML::Symbol &S);
  229. };
  230. template <> struct MappingTraits<XCOFFYAML::Relocation> {
  231. static void mapping(IO &IO, XCOFFYAML::Relocation &R);
  232. };
  233. template <> struct MappingTraits<XCOFFYAML::Section> {
  234. static void mapping(IO &IO, XCOFFYAML::Section &Sec);
  235. };
  236. template <> struct MappingTraits<XCOFFYAML::StringTable> {
  237. static void mapping(IO &IO, XCOFFYAML::StringTable &Str);
  238. };
  239. template <> struct MappingTraits<XCOFFYAML::Object> {
  240. static void mapping(IO &IO, XCOFFYAML::Object &Obj);
  241. };
  242. } // namespace yaml
  243. } // namespace llvm
  244. #endif // LLVM_OBJECTYAML_XCOFFYAML_H
  245. #ifdef __GNUC__
  246. #pragma GCC diagnostic pop
  247. #endif