LLVM 17.0.0git
COFFYAML.h
Go to the documentation of this file.
1//===- COFFYAML.h - COFF YAMLIO implementation ------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares classes for handling the YAML representation of COFF.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_OBJECTYAML_COFFYAML_H
14#define LLVM_OBJECTYAML_COFFYAML_H
15
16#include "llvm/ADT/StringRef.h"
22#include <cstdint>
23#include <optional>
24#include <vector>
25
26namespace llvm {
27
28namespace COFF {
29
31 uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
32 return static_cast<Characteristics>(Ret);
33}
34
37 uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
38 return static_cast<SectionCharacteristics>(Ret);
39}
40
43 uint16_t Ret = static_cast<uint16_t>(a) | static_cast<uint16_t>(b);
44 return static_cast<DLLCharacteristics>(Ret);
45}
46
47} // end namespace COFF
48
49// The structure of the yaml files is not an exact 1:1 match to COFF. In order
50// to use yaml::IO, we use these structures which are closer to the source.
51namespace COFFYAML {
52
53LLVM_YAML_STRONG_TYPEDEF(uint8_t, COMDATType)
54LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics)
55LLVM_YAML_STRONG_TYPEDEF(uint8_t, AuxSymbolType)
56
57struct Relocation {
60
61 // Normally a Relocation can refer to the symbol via its name.
62 // It can also use a direct symbol table index instead (with no name
63 // specified), allowing disambiguating between multiple symbols with the
64 // same name or crafting intentionally broken files for testing.
66 std::optional<uint32_t> SymbolTableIndex;
67};
68
69struct Section {
71 unsigned Alignment = 0;
73 std::vector<CodeViewYAML::YAMLDebugSubsection> DebugS;
74 std::vector<CodeViewYAML::LeafRecord> DebugT;
75 std::vector<CodeViewYAML::LeafRecord> DebugP;
76 std::optional<CodeViewYAML::DebugHSection> DebugH;
77 std::vector<Relocation> Relocations;
79
80 Section();
81};
82
83struct Symbol {
87 std::optional<COFF::AuxiliaryFunctionDefinition> FunctionDefinition;
88 std::optional<COFF::AuxiliarybfAndefSymbol> bfAndefSymbol;
89 std::optional<COFF::AuxiliaryWeakExternal> WeakExternal;
91 std::optional<COFF::AuxiliarySectionDefinition> SectionDefinition;
92 std::optional<COFF::AuxiliaryCLRToken> CLRToken;
94
95 Symbol();
96};
97
98struct PEHeader {
100 std::optional<COFF::DataDirectory>
102};
103
104struct Object {
105 std::optional<PEHeader> OptionalHeader;
107 std::vector<Section> Sections;
108 std::vector<Symbol> Symbols;
109
110 Object();
111};
112
113} // end namespace COFFYAML
114
115} // end namespace llvm
116
117LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
118LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
119LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
120
121namespace llvm {
122namespace yaml {
123
124template <>
125struct ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics> {
126 static void enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value);
127};
128
129template <>
130struct ScalarEnumerationTraits<COFFYAML::AuxSymbolType> {
131 static void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value);
132};
133
134template <>
135struct ScalarEnumerationTraits<COFFYAML::COMDATType> {
136 static void enumeration(IO &IO, COFFYAML::COMDATType &Value);
137};
138
139template <>
140struct ScalarEnumerationTraits<COFF::MachineTypes> {
141 static void enumeration(IO &IO, COFF::MachineTypes &Value);
142};
143
144template <>
145struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
146 static void enumeration(IO &IO, COFF::SymbolBaseType &Value);
147};
148
149template <>
150struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
151 static void enumeration(IO &IO, COFF::SymbolStorageClass &Value);
152};
153
154template <>
155struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
156 static void enumeration(IO &IO, COFF::SymbolComplexType &Value);
157};
158
159template <>
160struct ScalarEnumerationTraits<COFF::RelocationTypeI386> {
161 static void enumeration(IO &IO, COFF::RelocationTypeI386 &Value);
162};
163
164template <>
165struct ScalarEnumerationTraits<COFF::RelocationTypeAMD64> {
166 static void enumeration(IO &IO, COFF::RelocationTypeAMD64 &Value);
167};
168
169template <>
170struct ScalarEnumerationTraits<COFF::RelocationTypesARM> {
171 static void enumeration(IO &IO, COFF::RelocationTypesARM &Value);
172};
173
174template <>
175struct ScalarEnumerationTraits<COFF::RelocationTypesARM64> {
176 static void enumeration(IO &IO, COFF::RelocationTypesARM64 &Value);
177};
178
179template <>
180struct ScalarEnumerationTraits<COFF::WindowsSubsystem> {
181 static void enumeration(IO &IO, COFF::WindowsSubsystem &Value);
182};
183
184template <>
185struct ScalarBitSetTraits<COFF::Characteristics> {
186 static void bitset(IO &IO, COFF::Characteristics &Value);
187};
188
189template <>
190struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
191 static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
192};
193
194template <>
195struct ScalarBitSetTraits<COFF::DLLCharacteristics> {
196 static void bitset(IO &IO, COFF::DLLCharacteristics &Value);
197};
198
199template <>
200struct MappingTraits<COFFYAML::Relocation> {
201 static void mapping(IO &IO, COFFYAML::Relocation &Rel);
202};
203
204template <>
205struct MappingTraits<COFFYAML::PEHeader> {
206 static void mapping(IO &IO, COFFYAML::PEHeader &PH);
207};
208
209template <>
210struct MappingTraits<COFF::DataDirectory> {
211 static void mapping(IO &IO, COFF::DataDirectory &DD);
212};
213
214template <>
215struct MappingTraits<COFF::header> {
216 static void mapping(IO &IO, COFF::header &H);
217};
218
219template <> struct MappingTraits<COFF::AuxiliaryFunctionDefinition> {
220 static void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD);
221};
222
223template <> struct MappingTraits<COFF::AuxiliarybfAndefSymbol> {
224 static void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS);
225};
226
227template <> struct MappingTraits<COFF::AuxiliaryWeakExternal> {
228 static void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE);
229};
230
231template <> struct MappingTraits<COFF::AuxiliarySectionDefinition> {
232 static void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD);
233};
234
235template <> struct MappingTraits<COFF::AuxiliaryCLRToken> {
236 static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT);
237};
238
239template <>
240struct MappingTraits<COFFYAML::Symbol> {
241 static void mapping(IO &IO, COFFYAML::Symbol &S);
242};
243
244template <>
245struct MappingTraits<COFFYAML::Section> {
246 static void mapping(IO &IO, COFFYAML::Section &Sec);
247};
248
249template <>
250struct MappingTraits<COFFYAML::Object> {
251 static void mapping(IO &IO, COFFYAML::Object &Obj);
252};
253
254} // end namespace yaml
255} // end namespace llvm
256
257#endif // LLVM_OBJECTYAML_COFFYAML_H
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:330
#define H(x, y, z)
Definition: MD5.cpp:57
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
#define LLVM_YAML_STRONG_TYPEDEF(_base, _type)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
LLVM Value Representation.
Definition: Value.h:74
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:63
DLLCharacteristics
Definition: COFF.h:621
Characteristics operator|(Characteristics a, Characteristics b)
Definition: COFFYAML.h:30
MachineTypes
Definition: COFF.h:92
SectionCharacteristics
Definition: COFF.h:283
RelocationTypesARM64
Definition: COFF.h:385
RelocationTypeAMD64
Definition: COFF.h:345
@ NUM_DATA_DIRECTORIES
Definition: COFF.h:599
SymbolStorageClass
Storage class tells where and what the symbol represents.
Definition: COFF.h:203
WindowsSubsystem
Definition: COFF.h:602
RelocationTypesARM
Definition: COFF.h:365
RelocationTypeI386
Definition: COFF.h:331
SymbolBaseType
Definition: COFF.h:239
@ IMAGE_SYM_TYPE_NULL
No type information or unknown base type.
Definition: COFF.h:240
Characteristics
Definition: COFF.h:123
SymbolComplexType
Definition: COFF.h:258
@ IMAGE_SYM_DTYPE_NULL
No complex type; simple scalar variable.
Definition: COFF.h:259
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::optional< PEHeader > OptionalHeader
Definition: COFFYAML.h:105
std::vector< Section > Sections
Definition: COFFYAML.h:107
std::vector< Symbol > Symbols
Definition: COFFYAML.h:108
COFF::header Header
Definition: COFFYAML.h:106
std::optional< COFF::DataDirectory > DataDirectories[COFF::NUM_DATA_DIRECTORIES]
Definition: COFFYAML.h:101
COFF::PE32Header Header
Definition: COFFYAML.h:99
std::optional< uint32_t > SymbolTableIndex
Definition: COFFYAML.h:66
std::vector< CodeViewYAML::YAMLDebugSubsection > DebugS
Definition: COFFYAML.h:73
std::vector< CodeViewYAML::LeafRecord > DebugT
Definition: COFFYAML.h:74
yaml::BinaryRef SectionData
Definition: COFFYAML.h:72
std::optional< CodeViewYAML::DebugHSection > DebugH
Definition: COFFYAML.h:76
std::vector< CodeViewYAML::LeafRecord > DebugP
Definition: COFFYAML.h:75
COFF::section Header
Definition: COFFYAML.h:70
std::vector< Relocation > Relocations
Definition: COFFYAML.h:77
std::optional< COFF::AuxiliaryWeakExternal > WeakExternal
Definition: COFFYAML.h:89
std::optional< COFF::AuxiliarybfAndefSymbol > bfAndefSymbol
Definition: COFFYAML.h:88
COFF::SymbolComplexType ComplexType
Definition: COFFYAML.h:86
std::optional< COFF::AuxiliarySectionDefinition > SectionDefinition
Definition: COFFYAML.h:91
std::optional< COFF::AuxiliaryFunctionDefinition > FunctionDefinition
Definition: COFFYAML.h:87
COFF::symbol Header
Definition: COFFYAML.h:84
COFF::SymbolBaseType SimpleType
Definition: COFFYAML.h:85
std::optional< COFF::AuxiliaryCLRToken > CLRToken
Definition: COFFYAML.h:92