LLVM  13.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/Optional.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/BinaryFormat/COFF.h"
22 #include "llvm/ObjectYAML/YAML.h"
23 #include <cstdint>
24 #include <vector>
25 
26 namespace llvm {
27 
28 namespace 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.
51 namespace COFFYAML {
52 
56 
57 struct 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.
67 };
68 
69 struct Section {
71  unsigned Alignment = 0;
73  std::vector<CodeViewYAML::YAMLDebugSubsection> DebugS;
74  std::vector<CodeViewYAML::LeafRecord> DebugT;
75  std::vector<CodeViewYAML::LeafRecord> DebugP;
77  std::vector<Relocation> Relocations;
79 
80  Section();
81 };
82 
83 struct Symbol {
94 
95  Symbol();
96 };
97 
98 struct PEHeader {
101 };
102 
103 struct Object {
106  std::vector<Section> Sections;
107  std::vector<Symbol> Symbols;
108 
109  Object();
110 };
111 
112 } // end namespace COFFYAML
113 
114 } // end namespace llvm
115 
118 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
119 
120 namespace llvm {
121 namespace yaml {
122 
123 template <>
124 struct ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics> {
125  static void enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value);
126 };
127 
128 template <>
129 struct ScalarEnumerationTraits<COFFYAML::AuxSymbolType> {
130  static void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value);
131 };
132 
133 template <>
134 struct ScalarEnumerationTraits<COFFYAML::COMDATType> {
135  static void enumeration(IO &IO, COFFYAML::COMDATType &Value);
136 };
137 
138 template <>
139 struct ScalarEnumerationTraits<COFF::MachineTypes> {
140  static void enumeration(IO &IO, COFF::MachineTypes &Value);
141 };
142 
143 template <>
144 struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
145  static void enumeration(IO &IO, COFF::SymbolBaseType &Value);
146 };
147 
148 template <>
149 struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
150  static void enumeration(IO &IO, COFF::SymbolStorageClass &Value);
151 };
152 
153 template <>
154 struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
155  static void enumeration(IO &IO, COFF::SymbolComplexType &Value);
156 };
157 
158 template <>
159 struct ScalarEnumerationTraits<COFF::RelocationTypeI386> {
160  static void enumeration(IO &IO, COFF::RelocationTypeI386 &Value);
161 };
162 
163 template <>
164 struct ScalarEnumerationTraits<COFF::RelocationTypeAMD64> {
165  static void enumeration(IO &IO, COFF::RelocationTypeAMD64 &Value);
166 };
167 
168 template <>
169 struct ScalarEnumerationTraits<COFF::RelocationTypesARM> {
170  static void enumeration(IO &IO, COFF::RelocationTypesARM &Value);
171 };
172 
173 template <>
174 struct ScalarEnumerationTraits<COFF::RelocationTypesARM64> {
175  static void enumeration(IO &IO, COFF::RelocationTypesARM64 &Value);
176 };
177 
178 template <>
179 struct ScalarEnumerationTraits<COFF::WindowsSubsystem> {
180  static void enumeration(IO &IO, COFF::WindowsSubsystem &Value);
181 };
182 
183 template <>
184 struct ScalarBitSetTraits<COFF::Characteristics> {
185  static void bitset(IO &IO, COFF::Characteristics &Value);
186 };
187 
188 template <>
189 struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
190  static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
191 };
192 
193 template <>
194 struct ScalarBitSetTraits<COFF::DLLCharacteristics> {
195  static void bitset(IO &IO, COFF::DLLCharacteristics &Value);
196 };
197 
198 template <>
199 struct MappingTraits<COFFYAML::Relocation> {
200  static void mapping(IO &IO, COFFYAML::Relocation &Rel);
201 };
202 
203 template <>
204 struct MappingTraits<COFFYAML::PEHeader> {
205  static void mapping(IO &IO, COFFYAML::PEHeader &PH);
206 };
207 
208 template <>
209 struct MappingTraits<COFF::DataDirectory> {
210  static void mapping(IO &IO, COFF::DataDirectory &DD);
211 };
212 
213 template <>
214 struct MappingTraits<COFF::header> {
215  static void mapping(IO &IO, COFF::header &H);
216 };
217 
218 template <> struct MappingTraits<COFF::AuxiliaryFunctionDefinition> {
219  static void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD);
220 };
221 
222 template <> struct MappingTraits<COFF::AuxiliarybfAndefSymbol> {
223  static void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS);
224 };
225 
226 template <> struct MappingTraits<COFF::AuxiliaryWeakExternal> {
227  static void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE);
228 };
229 
230 template <> struct MappingTraits<COFF::AuxiliarySectionDefinition> {
231  static void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD);
232 };
233 
234 template <> struct MappingTraits<COFF::AuxiliaryCLRToken> {
235  static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT);
236 };
237 
238 template <>
239 struct MappingTraits<COFFYAML::Symbol> {
240  static void mapping(IO &IO, COFFYAML::Symbol &S);
241 };
242 
243 template <>
244 struct MappingTraits<COFFYAML::Section> {
245  static void mapping(IO &IO, COFFYAML::Section &Sec);
246 };
247 
248 template <>
249 struct MappingTraits<COFFYAML::Object> {
250  static void mapping(IO &IO, COFFYAML::Object &Obj);
251 };
252 
253 } // end namespace yaml
254 } // end namespace llvm
255 
256 #endif // LLVM_OBJECTYAML_COFFYAML_H
llvm::COFFYAML::Symbol::File
StringRef File
Definition: COFFYAML.h:90
llvm::COFFYAML::PEHeader::Header
COFF::PE32Header Header
Definition: COFFYAML.h:99
CodeViewYAMLDebugSections.h
llvm
Definition: AllocatorList.h:23
llvm::COFFYAML::Symbol::SimpleType
COFF::SymbolBaseType SimpleType
Definition: COFFYAML.h:85
llvm::COFF::DataDirectory
Definition: COFF.h:576
Optional.h
llvm::COFFYAML::Symbol::Symbol
Symbol()
Definition: COFFYAML.cpp:26
llvm::COFF::AuxiliarybfAndefSymbol
Definition: COFF.h:425
llvm::COFFYAML::Object::Sections
std::vector< Section > Sections
Definition: COFFYAML.h:106
llvm::COFFYAML::Symbol::FunctionDefinition
Optional< COFF::AuxiliaryFunctionDefinition > FunctionDefinition
Definition: COFFYAML.h:87
StringRef.h
llvm::COFFYAML::Section::DebugH
Optional< CodeViewYAML::DebugHSection > DebugH
Definition: COFFYAML.h:76
llvm::COFFYAML::Object::Object
Object()
Definition: COFFYAML.cpp:27
LLVM_YAML_IS_SEQUENCE_VECTOR
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
COFF.h
llvm::COFFYAML::Symbol::ComplexType
COFF::SymbolComplexType ComplexType
Definition: COFFYAML.h:86
llvm::COFFYAML::Section::Name
StringRef Name
Definition: COFFYAML.h:78
llvm::COFF::Characteristics
Characteristics
Definition: COFF.h:123
llvm::COFFYAML::Object::OptionalHeader
Optional< PEHeader > OptionalHeader
Definition: COFFYAML.h:104
llvm::Optional< uint32_t >
llvm::COFFYAML::Relocation
Definition: COFFYAML.h:57
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:116
llvm::COFFYAML::Section
Definition: COFFYAML.h:69
llvm::yaml::MappingTraits
Definition: ModuleSummaryIndex.h:50
llvm::COFF::AuxiliaryFunctionDefinition
Definition: COFF.h:417
llvm::COFF::RelocationTypesARM
RelocationTypesARM
Definition: COFF.h:365
llvm::COFF::COMDATType
COMDATType
Definition: COFF.h:406
llvm::COFF::SymbolStorageClass
SymbolStorageClass
Storage class tells where and what the symbol represents.
Definition: COFF.h:203
a
=0.0 ? 0.0 :(a > 0.0 ? 1.0 :-1.0) a
Definition: README.txt:489
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
llvm::COFFYAML::Symbol::Name
StringRef Name
Definition: COFFYAML.h:93
llvm::COFFYAML::Symbol::bfAndefSymbol
Optional< COFF::AuxiliarybfAndefSymbol > bfAndefSymbol
Definition: COFFYAML.h:88
llvm::COFFYAML::Section::Relocations
std::vector< Relocation > Relocations
Definition: COFFYAML.h:77
b
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int b
Definition: README.txt:418
CodeViewYAMLTypeHashing.h
YAML.h
llvm::COFFYAML::Symbol::WeakExternal
Optional< COFF::AuxiliaryWeakExternal > WeakExternal
Definition: COFFYAML.h:89
llvm::COFF::AuxiliaryWeakExternal
Definition: COFF.h:433
llvm::COFFYAML::Symbol::SectionDefinition
Optional< COFF::AuxiliarySectionDefinition > SectionDefinition
Definition: COFFYAML.h:91
llvm::COFFYAML::Object
Definition: COFFYAML.h:103
llvm::COFF::SymbolComplexType
SymbolComplexType
Definition: COFF.h:258
llvm::OutputFileType::Object
@ Object
llvm::COFF::symbol
Definition: COFF.h:187
llvm::COFFYAML::Relocation::SymbolName
StringRef SymbolName
Definition: COFFYAML.h:65
llvm::COFF::IMAGE_SYM_TYPE_NULL
@ IMAGE_SYM_TYPE_NULL
No type information or unknown base type.
Definition: COFF.h:240
llvm::COFF::SymbolBaseType
SymbolBaseType
Definition: COFF.h:239
llvm::COFF::AuxiliaryCLRToken
Definition: COFF.h:455
llvm::COFFYAML::PEHeader
Definition: COFFYAML.h:98
LLVM_YAML_STRONG_TYPEDEF
#define LLVM_YAML_STRONG_TYPEDEF(_base, _type)
llvm::COFFYAML::Section::SectionData
yaml::BinaryRef SectionData
Definition: COFFYAML.h:72
llvm::COFF::PE32Header
Definition: COFF.h:539
llvm::COFF::RelocationTypeI386
RelocationTypeI386
Definition: COFF.h:331
llvm::COFF::AuxSymbolType
AuxSymbolType
Definition: COFF.h:268
llvm::COFFYAML::Symbol
Definition: COFFYAML.h:83
llvm::COFFYAML::Section::DebugP
std::vector< CodeViewYAML::LeafRecord > DebugP
Definition: COFFYAML.h:75
llvm::COFF::WeakExternalCharacteristics
WeakExternalCharacteristics
Definition: COFF.h:439
llvm::COFFYAML::PEHeader::DataDirectories
Optional< COFF::DataDirectory > DataDirectories[COFF::NUM_DATA_DIRECTORIES]
Definition: COFFYAML.h:100
CodeViewYAMLTypes.h
llvm::COFFYAML::Relocation::VirtualAddress
uint32_t VirtualAddress
Definition: COFFYAML.h:58
llvm::COFFYAML::Section::Section
Section()
Definition: COFFYAML.cpp:25
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::yaml::BinaryRef
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:63
uint32_t
llvm::COFF::operator|
Characteristics operator|(Characteristics a, Characteristics b)
Definition: COFFYAML.h:30
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::COFFYAML::Object::Symbols
std::vector< Symbol > Symbols
Definition: COFFYAML.h:107
llvm::COFFYAML::Section::DebugT
std::vector< CodeViewYAML::LeafRecord > DebugT
Definition: COFFYAML.h:74
H
#define H(x, y, z)
Definition: MD5.cpp:58
uint16_t
llvm::COFF::NUM_DATA_DIRECTORIES
@ NUM_DATA_DIRECTORIES
Definition: COFF.h:598
llvm::COFF::WindowsSubsystem
WindowsSubsystem
Definition: COFF.h:601
llvm::COFF::section
Definition: COFF.h:270
llvm::COFFYAML::Section::DebugS
std::vector< CodeViewYAML::YAMLDebugSubsection > DebugS
Definition: COFFYAML.h:73
llvm::COFF::MachineTypes
MachineTypes
Definition: COFF.h:93
llvm::COFF::AuxiliarySectionDefinition
Definition: COFF.h:445
llvm::COFF::DLLCharacteristics
DLLCharacteristics
Definition: COFF.h:620
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
llvm::COFFYAML::Relocation::SymbolTableIndex
Optional< uint32_t > SymbolTableIndex
Definition: COFFYAML.h:66
llvm::COFF::RelocationTypesARM64
RelocationTypesARM64
Definition: COFF.h:385
llvm::COFFYAML::Section::Alignment
unsigned Alignment
Definition: COFFYAML.h:71
llvm::COFFYAML::Symbol::CLRToken
Optional< COFF::AuxiliaryCLRToken > CLRToken
Definition: COFFYAML.h:92
llvm::COFF::IMAGE_SYM_DTYPE_NULL
@ IMAGE_SYM_DTYPE_NULL
No complex type; simple scalar variable.
Definition: COFF.h:259
Characteristics
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:325
llvm::COFF::header
Definition: COFF.h:65
llvm::COFFYAML::Object::Header
COFF::header Header
Definition: COFFYAML.h:105
llvm::COFFYAML::Symbol::Header
COFF::symbol Header
Definition: COFFYAML.h:84
llvm::COFFYAML::Relocation::Type
uint16_t Type
Definition: COFFYAML.h:59
llvm::COFFYAML::Section::Header
COFF::section Header
Definition: COFFYAML.h:70
llvm::COFF::SectionCharacteristics
SectionCharacteristics
Definition: COFF.h:283
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::COFF::RelocationTypeAMD64
RelocationTypeAMD64
Definition: COFF.h:345