LLVM 24.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"
18#include "llvm/Object/COFF.h"
23#include <cstdint>
24#include <optional>
25#include <vector>
26
27namespace llvm {
28
29namespace yaml {
31}
32
33namespace COFF {
34
36 uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
37 return static_cast<Characteristics>(Ret);
38}
39
42 uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
43 return static_cast<SectionCharacteristics>(Ret);
44}
45
48 uint16_t Ret = static_cast<uint16_t>(a) | static_cast<uint16_t>(b);
49 return static_cast<DLLCharacteristics>(Ret);
50}
51
52} // end namespace COFF
53
54// The structure of the yaml files is not an exact 1:1 match to COFF. In order
55// to use yaml::IO, we use these structures which are closer to the source.
56namespace COFFYAML {
57
59LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics)
61
62struct Relocation {
65
66 // Normally a Relocation can refer to the symbol via its name.
67 // It can also use a direct symbol table index instead (with no name
68 // specified), allowing disambiguating between multiple symbols with the
69 // same name or crafting intentionally broken files for testing.
71 std::optional<uint32_t> SymbolTableIndex;
72};
73
75 std::optional<uint32_t> UInt32;
77 std::optional<object::coff_load_configuration32> LoadConfig32;
78 std::optional<object::coff_load_configuration64> LoadConfig64;
79
80 LLVM_ABI size_t size() const;
82};
83
84struct Section {
86 unsigned Alignment = 0;
88 std::vector<CodeViewYAML::YAMLDebugSubsection> DebugS;
89 std::vector<CodeViewYAML::LeafRecord> DebugT;
90 std::vector<CodeViewYAML::LeafRecord> DebugP;
91 std::optional<CodeViewYAML::DebugHSection> DebugH;
92 std::vector<SectionDataEntry> StructuredData;
93 std::vector<Relocation> Relocations;
95
97};
98
99struct Symbol {
103 std::optional<COFF::AuxiliaryFunctionDefinition> FunctionDefinition;
104 std::optional<COFF::AuxiliarybfAndefSymbol> bfAndefSymbol;
105 std::optional<COFF::AuxiliaryWeakExternal> WeakExternal;
107 std::optional<COFF::AuxiliarySectionDefinition> SectionDefinition;
108 std::optional<COFF::AuxiliaryCLRToken> CLRToken;
110
112};
113
114struct PEHeader {
116 std::optional<COFF::DataDirectory>
118};
119
120struct Object {
121 std::optional<PEHeader> OptionalHeader;
123 std::vector<Section> Sections;
124 std::vector<Symbol> Symbols;
125
127};
128
129} // end namespace COFFYAML
130
131} // end namespace llvm
132
133LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
134LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
135LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
136LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::SectionDataEntry)
137
138namespace llvm {
139namespace yaml {
140
141template <>
142struct ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics> {
143 LLVM_ABI static void
144 enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value);
145};
146
147template <>
148struct ScalarEnumerationTraits<COFFYAML::AuxSymbolType> {
149 LLVM_ABI static void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value);
150};
151
152template <>
154 LLVM_ABI static void enumeration(IO &IO, COFFYAML::COMDATType &Value);
155};
156
157template <>
158struct ScalarEnumerationTraits<COFF::MachineTypes> {
160};
161
162template <>
163struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
165};
166
167template <>
168struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
170};
171
172template <>
173struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
175};
176
177template <>
178struct ScalarEnumerationTraits<COFF::RelocationTypeI386> {
180};
181
182template <>
183struct ScalarEnumerationTraits<COFF::RelocationTypeAMD64> {
185};
186
187template <> struct ScalarEnumerationTraits<COFF::RelocationTypesMips> {
189};
190
191template <>
192struct ScalarEnumerationTraits<COFF::RelocationTypesARM> {
194};
195
196template <>
197struct ScalarEnumerationTraits<COFF::RelocationTypesARM64> {
199};
200
201template <>
202struct ScalarEnumerationTraits<COFF::WindowsSubsystem> {
204};
205
206template <>
207struct ScalarBitSetTraits<COFF::Characteristics> {
209};
210
211template <>
212struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
214};
215
216template <>
217struct ScalarBitSetTraits<COFF::DLLCharacteristics> {
219};
220
221template <>
222struct MappingTraits<COFFYAML::Relocation> {
223 LLVM_ABI static void mapping(IO &IO, COFFYAML::Relocation &Rel);
224};
225
226template <>
227struct MappingTraits<COFFYAML::PEHeader> {
228 LLVM_ABI static void mapping(IO &IO, COFFYAML::PEHeader &PH);
229};
230
231template <>
232struct MappingTraits<COFF::DataDirectory> {
233 LLVM_ABI static void mapping(IO &IO, COFF::DataDirectory &DD);
234};
235
236template <>
237struct MappingTraits<COFF::header> {
238 LLVM_ABI static void mapping(IO &IO, COFF::header &H);
239};
240
241template <> struct MappingTraits<COFF::AuxiliaryFunctionDefinition> {
243};
244
245template <> struct MappingTraits<COFF::AuxiliarybfAndefSymbol> {
247};
248
249template <> struct MappingTraits<COFF::AuxiliaryWeakExternal> {
251};
252
253template <> struct MappingTraits<COFF::AuxiliarySectionDefinition> {
255};
256
257template <> struct MappingTraits<COFF::AuxiliaryCLRToken> {
258 LLVM_ABI static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT);
259};
260
261template <> struct MappingTraits<object::coff_load_configuration32> {
263};
264
265template <> struct MappingTraits<object::coff_load_configuration64> {
267};
268
269template <> struct MappingTraits<object::coff_load_config_code_integrity> {
270 LLVM_ABI static void mapping(IO &IO,
272};
273
274template <>
275struct MappingTraits<COFFYAML::Symbol> {
276 LLVM_ABI static void mapping(IO &IO, COFFYAML::Symbol &S);
277};
278
279template <> struct MappingTraits<COFFYAML::SectionDataEntry> {
280 LLVM_ABI static void mapping(IO &IO, COFFYAML::SectionDataEntry &Sec);
281};
282
283template <>
284struct MappingTraits<COFFYAML::Section> {
285 LLVM_ABI static void mapping(IO &IO, COFFYAML::Section &Sec);
286};
287
288template <>
289struct MappingTraits<COFFYAML::Object> {
290 LLVM_ABI static void mapping(IO &IO, COFFYAML::Object &Obj);
291};
292
293} // end namespace yaml
294} // end namespace llvm
295
296#endif // LLVM_OBJECTYAML_COFFYAML_H
#define LLVM_ABI
Definition Compiler.h:215
#define H(x, y, z)
Definition MD5.cpp:56
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML sequence.
#define LLVM_YAML_STRONG_TYPEDEF(_base, _type)
YAML I/O does conversion based on types. But often native data types are just a typedef of built in i...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM Value Representation.
Definition Value.h:75
Specialized YAMLIO scalar type for representing a binary blob.
Definition YAML.h:64
DLLCharacteristics
Definition COFF.h:669
Characteristics operator|(Characteristics a, Characteristics b)
Definition COFFYAML.h:35
RelocationTypesMips
Definition COFF.h:421
MachineTypes
Definition COFF.h:93
SectionCharacteristics
Definition COFF.h:298
RelocationTypesARM64
Definition COFF.h:400
RelocationTypeAMD64
Definition COFF.h:360
@ NUM_DATA_DIRECTORIES
Definition COFF.h:647
SymbolStorageClass
Storage class tells where and what the symbol represents.
Definition COFF.h:218
WindowsSubsystem
Definition COFF.h:650
RelocationTypesARM
Definition COFF.h:380
RelocationTypeI386
Definition COFF.h:346
SymbolBaseType
Definition COFF.h:254
@ IMAGE_SYM_TYPE_NULL
No type information or unknown base type.
Definition COFF.h:255
Characteristics
Definition COFF.h:138
SymbolComplexType
Definition COFF.h:273
@ IMAGE_SYM_DTYPE_NULL
No complex type; simple scalar variable.
Definition COFF.h:274
This is an optimization pass for GlobalISel generic memory operations.
std::optional< PEHeader > OptionalHeader
Definition COFFYAML.h:121
std::vector< Section > Sections
Definition COFFYAML.h:123
std::vector< Symbol > Symbols
Definition COFFYAML.h:124
COFF::header Header
Definition COFFYAML.h:122
std::optional< COFF::DataDirectory > DataDirectories[COFF::NUM_DATA_DIRECTORIES]
Definition COFFYAML.h:117
COFF::PE32Header Header
Definition COFFYAML.h:115
std::optional< uint32_t > SymbolTableIndex
Definition COFFYAML.h:71
std::optional< object::coff_load_configuration64 > LoadConfig64
Definition COFFYAML.h:78
std::optional< object::coff_load_configuration32 > LoadConfig32
Definition COFFYAML.h:77
LLVM_ABI void writeAsBinary(yaml::ContiguousBlobAccumulator &CBA) const
std::optional< uint32_t > UInt32
Definition COFFYAML.h:75
LLVM_ABI size_t size() const
std::vector< CodeViewYAML::YAMLDebugSubsection > DebugS
Definition COFFYAML.h:88
std::vector< SectionDataEntry > StructuredData
Definition COFFYAML.h:92
std::vector< CodeViewYAML::LeafRecord > DebugT
Definition COFFYAML.h:89
yaml::BinaryRef SectionData
Definition COFFYAML.h:87
std::optional< CodeViewYAML::DebugHSection > DebugH
Definition COFFYAML.h:91
std::vector< CodeViewYAML::LeafRecord > DebugP
Definition COFFYAML.h:90
COFF::section Header
Definition COFFYAML.h:85
std::vector< Relocation > Relocations
Definition COFFYAML.h:93
std::optional< COFF::AuxiliaryWeakExternal > WeakExternal
Definition COFFYAML.h:105
std::optional< COFF::AuxiliarybfAndefSymbol > bfAndefSymbol
Definition COFFYAML.h:104
COFF::SymbolComplexType ComplexType
Definition COFFYAML.h:102
std::optional< COFF::AuxiliarySectionDefinition > SectionDefinition
Definition COFFYAML.h:107
std::optional< COFF::AuxiliaryFunctionDefinition > FunctionDefinition
Definition COFFYAML.h:103
COFF::symbol Header
Definition COFFYAML.h:100
COFF::SymbolBaseType SimpleType
Definition COFFYAML.h:101
std::optional< COFF::AuxiliaryCLRToken > CLRToken
Definition COFFYAML.h:108
32-bit load config (IMAGE_LOAD_CONFIG_DIRECTORY32)
Definition COFF.h:619
64-bit load config (IMAGE_LOAD_CONFIG_DIRECTORY64)
Definition COFF.h:677
static LLVM_ABI void mapping(IO &IO, COFFYAML::Object &Obj)
Definition COFFYAML.cpp:725
static LLVM_ABI void mapping(IO &IO, COFFYAML::PEHeader &PH)
Definition COFFYAML.cpp:472
static LLVM_ABI void mapping(IO &IO, COFFYAML::Relocation &Rel)
Definition COFFYAML.cpp:434
static LLVM_ABI void mapping(IO &IO, COFFYAML::SectionDataEntry &Sec)
Definition COFFYAML.cpp:657
static LLVM_ABI void mapping(IO &IO, COFFYAML::Section &Sec)
Definition COFFYAML.cpp:686
static LLVM_ABI void mapping(IO &IO, COFFYAML::Symbol &S)
Definition COFFYAML.cpp:669
static LLVM_ABI void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT)
Definition COFFYAML.cpp:566
static LLVM_ABI void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD)
Definition COFFYAML.cpp:531
static LLVM_ABI void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD)
Definition COFFYAML.cpp:553
static LLVM_ABI void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE)
Definition COFFYAML.cpp:545
static LLVM_ABI void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS)
Definition COFFYAML.cpp:539
static LLVM_ABI void mapping(IO &IO, COFF::DataDirectory &DD)
Definition COFFYAML.cpp:466
static LLVM_ABI void mapping(IO &IO, COFF::header &H)
Definition COFFYAML.cpp:521
static LLVM_ABI void mapping(IO &IO, object::coff_load_config_code_integrity &ACT)
Definition COFFYAML.cpp:573
static LLVM_ABI void mapping(IO &IO, object::coff_load_configuration32 &ACT)
Definition COFFYAML.cpp:647
static LLVM_ABI void mapping(IO &IO, object::coff_load_configuration64 &ACT)
Definition COFFYAML.cpp:652
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
Definition YAMLTraits.h:63
static LLVM_ABI void bitset(IO &IO, COFF::Characteristics &Value)
Definition COFFYAML.cpp:268
static LLVM_ABI void bitset(IO &IO, COFF::DLLCharacteristics &Value)
Definition COFFYAML.cpp:313
static LLVM_ABI void bitset(IO &IO, COFF::SectionCharacteristics &Value)
Definition COFFYAML.cpp:287
This class should be specialized by any integer type that is a union of bit values and the YAML repre...
Definition YAMLTraits.h:124
static LLVM_ABI void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value)
Definition COFFYAML.cpp:55
static LLVM_ABI void enumeration(IO &IO, COFFYAML::COMDATType &Value)
Definition COFFYAML.cpp:33
static LLVM_ABI void enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value)
Definition COFFYAML.cpp:46
static LLVM_ABI void enumeration(IO &IO, COFF::MachineTypes &Value)
Definition COFFYAML.cpp:60
static LLVM_ABI void enumeration(IO &IO, COFF::RelocationTypeAMD64 &Value)
Definition COFFYAML.cpp:165
static LLVM_ABI void enumeration(IO &IO, COFF::RelocationTypeI386 &Value)
Definition COFFYAML.cpp:150
static LLVM_ABI void enumeration(IO &IO, COFF::RelocationTypesARM64 &Value)
Definition COFFYAML.cpp:226
static LLVM_ABI void enumeration(IO &IO, COFF::RelocationTypesARM &Value)
Definition COFFYAML.cpp:205
static LLVM_ABI void enumeration(IO &IO, COFF::RelocationTypesMips &Value)
Definition COFFYAML.cpp:186
static LLVM_ABI void enumeration(IO &IO, COFF::SymbolBaseType &Value)
Definition COFFYAML.cpp:91
static LLVM_ABI void enumeration(IO &IO, COFF::SymbolComplexType &Value)
Definition COFFYAML.cpp:142
static LLVM_ABI void enumeration(IO &IO, COFF::SymbolStorageClass &Value)
Definition COFFYAML.cpp:111
static LLVM_ABI void enumeration(IO &IO, COFF::WindowsSubsystem &Value)
Definition COFFYAML.cpp:248
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition YAMLTraits.h:108