#pragma once #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" #endif //===----- XCOFFYAML.h - XCOFF YAMLIO implementation ------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file declares classes for handling the YAML representation of XCOFF. // //===----------------------------------------------------------------------===// #ifndef LLVM_OBJECTYAML_XCOFFYAML_H #define LLVM_OBJECTYAML_XCOFFYAML_H #include "llvm/BinaryFormat/XCOFF.h" #include "llvm/ObjectYAML/YAML.h" #include #include namespace llvm { namespace XCOFFYAML { struct FileHeader { llvm::yaml::Hex16 Magic; uint16_t NumberOfSections; int32_t TimeStamp; llvm::yaml::Hex64 SymbolTableOffset; int32_t NumberOfSymTableEntries; uint16_t AuxHeaderSize; llvm::yaml::Hex16 Flags; }; struct AuxiliaryHeader { std::optional Magic; std::optional Version; std::optional TextStartAddr; std::optional DataStartAddr; std::optional TOCAnchorAddr; std::optional SecNumOfEntryPoint; std::optional SecNumOfText; std::optional SecNumOfData; std::optional SecNumOfTOC; std::optional SecNumOfLoader; std::optional SecNumOfBSS; std::optional MaxAlignOfText; std::optional MaxAlignOfData; std::optional ModuleType; std::optional CpuFlag; std::optional CpuType; std::optional TextPageSize; std::optional DataPageSize; std::optional StackPageSize; std::optional FlagAndTDataAlignment; std::optional TextSize; std::optional InitDataSize; std::optional BssDataSize; std::optional EntryPointAddr; std::optional MaxStackSize; std::optional MaxDataSize; std::optional SecNumOfTData; std::optional SecNumOfTBSS; std::optional Flag; }; struct Relocation { llvm::yaml::Hex64 VirtualAddress; llvm::yaml::Hex64 SymbolIndex; llvm::yaml::Hex8 Info; llvm::yaml::Hex8 Type; }; struct Section { StringRef SectionName; llvm::yaml::Hex64 Address; llvm::yaml::Hex64 Size; llvm::yaml::Hex64 FileOffsetToData; llvm::yaml::Hex64 FileOffsetToRelocations; llvm::yaml::Hex64 FileOffsetToLineNumbers; // Line number pointer. Not supported yet. llvm::yaml::Hex16 NumberOfRelocations; llvm::yaml::Hex16 NumberOfLineNumbers; // Line number counts. Not supported yet. uint32_t Flags; yaml::BinaryRef SectionData; std::vector Relocations; }; enum AuxSymbolType : uint8_t { AUX_EXCEPT = 255, AUX_FCN = 254, AUX_SYM = 253, AUX_FILE = 252, AUX_CSECT = 251, AUX_SECT = 250, AUX_STAT = 249 }; struct AuxSymbolEnt { AuxSymbolType Type; explicit AuxSymbolEnt(AuxSymbolType T) : Type(T) {} virtual ~AuxSymbolEnt(); }; struct FileAuxEnt : AuxSymbolEnt { std::optional FileNameOrString; std::optional FileStringType; FileAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_FILE) {} static bool classof(const AuxSymbolEnt *S) { return S->Type == AuxSymbolType::AUX_FILE; } }; struct CsectAuxEnt : AuxSymbolEnt { // Only for XCOFF32. std::optional SectionOrLength; std::optional StabInfoIndex; std::optional StabSectNum; // Only for XCOFF64. std::optional SectionOrLengthLo; std::optional SectionOrLengthHi; // Common fields for both XCOFF32 and XCOFF64. std::optional ParameterHashIndex; std::optional TypeChkSectNum; std::optional SymbolAlignmentAndType; std::optional StorageMappingClass; CsectAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_CSECT) {} static bool classof(const AuxSymbolEnt *S) { return S->Type == AuxSymbolType::AUX_CSECT; } }; struct FunctionAuxEnt : AuxSymbolEnt { std::optional OffsetToExceptionTbl; // Only for XCOFF32. std::optional PtrToLineNum; std::optional SizeOfFunction; std::optional SymIdxOfNextBeyond; FunctionAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_FCN) {} static bool classof(const AuxSymbolEnt *S) { return S->Type == AuxSymbolType::AUX_FCN; } }; struct ExcpetionAuxEnt : AuxSymbolEnt { std::optional OffsetToExceptionTbl; std::optional SizeOfFunction; std::optional SymIdxOfNextBeyond; ExcpetionAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_EXCEPT) {} static bool classof(const AuxSymbolEnt *S) { return S->Type == AuxSymbolType::AUX_EXCEPT; } }; // Only for XCOFF64. struct BlockAuxEnt : AuxSymbolEnt { // Only for XCOFF32. std::optional LineNumHi; std::optional LineNumLo; // Only for XCOFF64. std::optional LineNum; BlockAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_SYM) {} static bool classof(const AuxSymbolEnt *S) { return S->Type == AuxSymbolType::AUX_SYM; } }; struct SectAuxEntForDWARF : AuxSymbolEnt { std::optional LengthOfSectionPortion; std::optional NumberOfRelocEnt; SectAuxEntForDWARF() : AuxSymbolEnt(AuxSymbolType::AUX_SECT) {} static bool classof(const AuxSymbolEnt *S) { return S->Type == AuxSymbolType::AUX_SECT; } }; struct SectAuxEntForStat : AuxSymbolEnt { std::optional SectionLength; std::optional NumberOfRelocEnt; std::optional NumberOfLineNum; SectAuxEntForStat() : AuxSymbolEnt(AuxSymbolType::AUX_STAT) {} static bool classof(const AuxSymbolEnt *S) { return S->Type == AuxSymbolType::AUX_STAT; } }; // Only for XCOFF32. struct Symbol { StringRef SymbolName; llvm::yaml::Hex64 Value; // Symbol value; storage class-dependent. std::optional SectionName; std::optional SectionIndex; llvm::yaml::Hex16 Type; XCOFF::StorageClass StorageClass; std::optional NumberOfAuxEntries; std::vector> AuxEntries; }; struct StringTable { std::optional ContentSize; // The total size of the string table. std::optional Length; // The value of the length field for the first // 4 bytes of the table. std::optional> Strings; std::optional RawContent; }; struct Object { FileHeader Header; std::optional AuxHeader; std::vector
Sections; std::vector Symbols; StringTable StrTbl; Object(); }; } // namespace XCOFFYAML } // namespace llvm LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Symbol) LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Relocation) LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Section) LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr) namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits { static void bitset(IO &IO, XCOFF::SectionTypeFlags &Value); }; template <> struct ScalarEnumerationTraits { static void enumeration(IO &IO, XCOFF::StorageClass &Value); }; template <> struct ScalarEnumerationTraits { static void enumeration(IO &IO, XCOFF::StorageMappingClass &Value); }; template <> struct ScalarEnumerationTraits { static void enumeration(IO &IO, XCOFF::CFileStringType &Type); }; template <> struct ScalarEnumerationTraits { static void enumeration(IO &IO, XCOFFYAML::AuxSymbolType &Type); }; template <> struct MappingTraits { static void mapping(IO &IO, XCOFFYAML::FileHeader &H); }; template <> struct MappingTraits { static void mapping(IO &IO, XCOFFYAML::AuxiliaryHeader &AuxHdr); }; template <> struct MappingTraits> { static void mapping(IO &IO, std::unique_ptr &AuxSym); }; template <> struct MappingTraits { static void mapping(IO &IO, XCOFFYAML::Symbol &S); }; template <> struct MappingTraits { static void mapping(IO &IO, XCOFFYAML::Relocation &R); }; template <> struct MappingTraits { static void mapping(IO &IO, XCOFFYAML::Section &Sec); }; template <> struct MappingTraits { static void mapping(IO &IO, XCOFFYAML::StringTable &Str); }; template <> struct MappingTraits { static void mapping(IO &IO, XCOFFYAML::Object &Obj); }; } // namespace yaml } // namespace llvm #endif // LLVM_OBJECTYAML_XCOFFYAML_H #ifdef __GNUC__ #pragma GCC diagnostic pop #endif