Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:22

0001 //===----- XCOFFYAML.h - XCOFF YAMLIO implementation ------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file declares classes for handling the YAML representation of XCOFF.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 #ifndef LLVM_OBJECTYAML_XCOFFYAML_H
0013 #define LLVM_OBJECTYAML_XCOFFYAML_H
0014 
0015 #include "llvm/BinaryFormat/XCOFF.h"
0016 #include "llvm/ObjectYAML/YAML.h"
0017 #include <optional>
0018 #include <vector>
0019 
0020 namespace llvm {
0021 namespace XCOFFYAML {
0022 
0023 struct FileHeader {
0024   llvm::yaml::Hex16 Magic;
0025   uint16_t NumberOfSections;
0026   int32_t TimeStamp;
0027   llvm::yaml::Hex64 SymbolTableOffset;
0028   int32_t NumberOfSymTableEntries;
0029   uint16_t AuxHeaderSize;
0030   llvm::yaml::Hex16 Flags;
0031 };
0032 
0033 struct AuxiliaryHeader {
0034   std::optional<llvm::yaml::Hex16> Magic;
0035   std::optional<llvm::yaml::Hex16> Version;
0036   std::optional<llvm::yaml::Hex64> TextStartAddr;
0037   std::optional<llvm::yaml::Hex64> DataStartAddr;
0038   std::optional<llvm::yaml::Hex64> TOCAnchorAddr;
0039   std::optional<uint16_t> SecNumOfEntryPoint;
0040   std::optional<uint16_t> SecNumOfText;
0041   std::optional<uint16_t> SecNumOfData;
0042   std::optional<uint16_t> SecNumOfTOC;
0043   std::optional<uint16_t> SecNumOfLoader;
0044   std::optional<uint16_t> SecNumOfBSS;
0045   std::optional<llvm::yaml::Hex16> MaxAlignOfText;
0046   std::optional<llvm::yaml::Hex16> MaxAlignOfData;
0047   std::optional<llvm::yaml::Hex16> ModuleType;
0048   std::optional<llvm::yaml::Hex8> CpuFlag;
0049   std::optional<llvm::yaml::Hex8> CpuType;
0050   std::optional<llvm::yaml::Hex8> TextPageSize;
0051   std::optional<llvm::yaml::Hex8> DataPageSize;
0052   std::optional<llvm::yaml::Hex8> StackPageSize;
0053   std::optional<llvm::yaml::Hex8> FlagAndTDataAlignment;
0054   std::optional<llvm::yaml::Hex64> TextSize;
0055   std::optional<llvm::yaml::Hex64> InitDataSize;
0056   std::optional<llvm::yaml::Hex64> BssDataSize;
0057   std::optional<llvm::yaml::Hex64> EntryPointAddr;
0058   std::optional<llvm::yaml::Hex64> MaxStackSize;
0059   std::optional<llvm::yaml::Hex64> MaxDataSize;
0060   std::optional<uint16_t> SecNumOfTData;
0061   std::optional<uint16_t> SecNumOfTBSS;
0062   std::optional<llvm::yaml::Hex16> Flag;
0063 };
0064 
0065 struct Relocation {
0066   llvm::yaml::Hex64 VirtualAddress;
0067   llvm::yaml::Hex64 SymbolIndex;
0068   llvm::yaml::Hex8 Info;
0069   llvm::yaml::Hex8 Type;
0070 };
0071 
0072 struct Section {
0073   StringRef SectionName;
0074   llvm::yaml::Hex64 Address;
0075   llvm::yaml::Hex64 Size;
0076   llvm::yaml::Hex64 FileOffsetToData;
0077   llvm::yaml::Hex64 FileOffsetToRelocations;
0078   llvm::yaml::Hex64 FileOffsetToLineNumbers; // Line number pointer. Not supported yet.
0079   llvm::yaml::Hex16 NumberOfRelocations;
0080   llvm::yaml::Hex16 NumberOfLineNumbers; // Line number counts. Not supported yet.
0081   uint32_t Flags;
0082   std::optional<XCOFF::DwarfSectionSubtypeFlags> SectionSubtype;
0083   yaml::BinaryRef SectionData;
0084   std::vector<Relocation> Relocations;
0085 };
0086 
0087 enum AuxSymbolType : uint8_t {
0088   AUX_EXCEPT = 255,
0089   AUX_FCN = 254,
0090   AUX_SYM = 253,
0091   AUX_FILE = 252,
0092   AUX_CSECT = 251,
0093   AUX_SECT = 250,
0094   AUX_STAT = 249
0095 };
0096 
0097 struct AuxSymbolEnt {
0098   AuxSymbolType Type;
0099 
0100   explicit AuxSymbolEnt(AuxSymbolType T) : Type(T) {}
0101   virtual ~AuxSymbolEnt();
0102 };
0103 
0104 struct FileAuxEnt : AuxSymbolEnt {
0105   std::optional<StringRef> FileNameOrString;
0106   std::optional<XCOFF::CFileStringType> FileStringType;
0107 
0108   FileAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_FILE) {}
0109   static bool classof(const AuxSymbolEnt *S) {
0110     return S->Type == AuxSymbolType::AUX_FILE;
0111   }
0112 };
0113 
0114 struct CsectAuxEnt : AuxSymbolEnt {
0115   // Only for XCOFF32.
0116   std::optional<uint32_t> SectionOrLength;
0117   std::optional<uint32_t> StabInfoIndex;
0118   std::optional<uint16_t> StabSectNum;
0119   // Only for XCOFF64.
0120   std::optional<uint32_t> SectionOrLengthLo;
0121   std::optional<uint32_t> SectionOrLengthHi;
0122   // Common fields for both XCOFF32 and XCOFF64.
0123   std::optional<uint32_t> ParameterHashIndex;
0124   std::optional<uint16_t> TypeChkSectNum;
0125   std::optional<XCOFF::SymbolType> SymbolType;
0126   std::optional<uint8_t> SymbolAlignment;
0127   // The two previous values can be encoded as a single value.
0128   std::optional<uint8_t> SymbolAlignmentAndType;
0129   std::optional<XCOFF::StorageMappingClass> StorageMappingClass;
0130 
0131   CsectAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_CSECT) {}
0132   static bool classof(const AuxSymbolEnt *S) {
0133     return S->Type == AuxSymbolType::AUX_CSECT;
0134   }
0135 };
0136 
0137 struct FunctionAuxEnt : AuxSymbolEnt {
0138   std::optional<uint32_t> OffsetToExceptionTbl; // Only for XCOFF32.
0139   std::optional<uint64_t> PtrToLineNum;
0140   std::optional<uint32_t> SizeOfFunction;
0141   std::optional<int32_t> SymIdxOfNextBeyond;
0142 
0143   FunctionAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_FCN) {}
0144   static bool classof(const AuxSymbolEnt *S) {
0145     return S->Type == AuxSymbolType::AUX_FCN;
0146   }
0147 };
0148 
0149 struct ExcpetionAuxEnt : AuxSymbolEnt {
0150   std::optional<uint64_t> OffsetToExceptionTbl;
0151   std::optional<uint32_t> SizeOfFunction;
0152   std::optional<int32_t> SymIdxOfNextBeyond;
0153 
0154   ExcpetionAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_EXCEPT) {}
0155   static bool classof(const AuxSymbolEnt *S) {
0156     return S->Type == AuxSymbolType::AUX_EXCEPT;
0157   }
0158 }; // Only for XCOFF64.
0159 
0160 struct BlockAuxEnt : AuxSymbolEnt {
0161   // Only for XCOFF32.
0162   std::optional<uint16_t> LineNumHi;
0163   std::optional<uint16_t> LineNumLo;
0164   // Only for XCOFF64.
0165   std::optional<uint32_t> LineNum;
0166 
0167   BlockAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_SYM) {}
0168   static bool classof(const AuxSymbolEnt *S) {
0169     return S->Type == AuxSymbolType::AUX_SYM;
0170   }
0171 };
0172 
0173 struct SectAuxEntForDWARF : AuxSymbolEnt {
0174   std::optional<uint32_t> LengthOfSectionPortion;
0175   std::optional<uint32_t> NumberOfRelocEnt;
0176 
0177   SectAuxEntForDWARF() : AuxSymbolEnt(AuxSymbolType::AUX_SECT) {}
0178   static bool classof(const AuxSymbolEnt *S) {
0179     return S->Type == AuxSymbolType::AUX_SECT;
0180   }
0181 };
0182 
0183 struct SectAuxEntForStat : AuxSymbolEnt {
0184   std::optional<uint32_t> SectionLength;
0185   std::optional<uint16_t> NumberOfRelocEnt;
0186   std::optional<uint16_t> NumberOfLineNum;
0187 
0188   SectAuxEntForStat() : AuxSymbolEnt(AuxSymbolType::AUX_STAT) {}
0189   static bool classof(const AuxSymbolEnt *S) {
0190     return S->Type == AuxSymbolType::AUX_STAT;
0191   }
0192 }; // Only for XCOFF32.
0193 
0194 struct Symbol {
0195   StringRef SymbolName;
0196   llvm::yaml::Hex64 Value; // Symbol value; storage class-dependent.
0197   std::optional<StringRef> SectionName;
0198   std::optional<uint16_t> SectionIndex;
0199   llvm::yaml::Hex16 Type;
0200   XCOFF::StorageClass StorageClass;
0201   std::optional<uint8_t> NumberOfAuxEntries;
0202   std::vector<std::unique_ptr<AuxSymbolEnt>> AuxEntries;
0203 };
0204 
0205 struct StringTable {
0206   std::optional<uint32_t> ContentSize; // The total size of the string table.
0207   std::optional<uint32_t> Length; // The value of the length field for the first
0208                                   // 4 bytes of the table.
0209   std::optional<std::vector<StringRef>> Strings;
0210   std::optional<yaml::BinaryRef> RawContent;
0211 };
0212 
0213 struct Object {
0214   FileHeader Header;
0215   std::optional<AuxiliaryHeader> AuxHeader;
0216   std::vector<Section> Sections;
0217   std::vector<Symbol> Symbols;
0218   StringTable StrTbl;
0219   Object();
0220 };
0221 } // namespace XCOFFYAML
0222 } // namespace llvm
0223 
0224 LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Symbol)
0225 LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Relocation)
0226 LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Section)
0227 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::XCOFFYAML::AuxSymbolEnt>)
0228 
0229 namespace llvm {
0230 namespace yaml {
0231 
0232 template <> struct ScalarBitSetTraits<XCOFF::SectionTypeFlags> {
0233   static void bitset(IO &IO, XCOFF::SectionTypeFlags &Value);
0234 };
0235 
0236 template <> struct ScalarEnumerationTraits<XCOFF::DwarfSectionSubtypeFlags> {
0237   static void enumeration(IO &IO, XCOFF::DwarfSectionSubtypeFlags &Value);
0238 };
0239 
0240 template <> struct ScalarEnumerationTraits<XCOFF::StorageClass> {
0241   static void enumeration(IO &IO, XCOFF::StorageClass &Value);
0242 };
0243 
0244 template <> struct ScalarEnumerationTraits<XCOFF::StorageMappingClass> {
0245   static void enumeration(IO &IO, XCOFF::StorageMappingClass &Value);
0246 };
0247 
0248 template <> struct ScalarEnumerationTraits<XCOFF::SymbolType> {
0249   static void enumeration(IO &IO, XCOFF::SymbolType &Value);
0250 };
0251 
0252 template <> struct ScalarEnumerationTraits<XCOFF::CFileStringType> {
0253   static void enumeration(IO &IO, XCOFF::CFileStringType &Type);
0254 };
0255 
0256 template <> struct ScalarEnumerationTraits<XCOFFYAML::AuxSymbolType> {
0257   static void enumeration(IO &IO, XCOFFYAML::AuxSymbolType &Type);
0258 };
0259 
0260 template <> struct MappingTraits<XCOFFYAML::FileHeader> {
0261   static void mapping(IO &IO, XCOFFYAML::FileHeader &H);
0262 };
0263 
0264 template <> struct MappingTraits<XCOFFYAML::AuxiliaryHeader> {
0265   static void mapping(IO &IO, XCOFFYAML::AuxiliaryHeader &AuxHdr);
0266 };
0267 
0268 template <> struct MappingTraits<std::unique_ptr<XCOFFYAML::AuxSymbolEnt>> {
0269   static void mapping(IO &IO, std::unique_ptr<XCOFFYAML::AuxSymbolEnt> &AuxSym);
0270 };
0271 
0272 template <> struct MappingTraits<XCOFFYAML::Symbol> {
0273   static void mapping(IO &IO, XCOFFYAML::Symbol &S);
0274 };
0275 
0276 template <> struct MappingTraits<XCOFFYAML::Relocation> {
0277   static void mapping(IO &IO, XCOFFYAML::Relocation &R);
0278 };
0279 
0280 template <> struct MappingTraits<XCOFFYAML::Section> {
0281   static void mapping(IO &IO, XCOFFYAML::Section &Sec);
0282 };
0283 
0284 template <> struct MappingTraits<XCOFFYAML::StringTable> {
0285   static void mapping(IO &IO, XCOFFYAML::StringTable &Str);
0286 };
0287 
0288 template <> struct MappingTraits<XCOFFYAML::Object> {
0289   static void mapping(IO &IO, XCOFFYAML::Object &Obj);
0290 };
0291 
0292 } // namespace yaml
0293 } // namespace llvm
0294 
0295 #endif // LLVM_OBJECTYAML_XCOFFYAML_H