2013-05-18 00:58:42 +02:00
|
|
|
//===- COFFYAML.h - COFF YAMLIO implementation ------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// 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
|
2013-05-18 00:58:42 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares classes for handling the YAML representation of COFF.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-03-01 20:15:06 +01:00
|
|
|
#ifndef LLVM_OBJECTYAML_COFFYAML_H
|
|
|
|
#define LLVM_OBJECTYAML_COFFYAML_H
|
2013-05-18 00:58:42 +02:00
|
|
|
|
2014-03-19 05:47:47 +01:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2017-07-01 03:35:55 +02:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2017-06-07 05:48:56 +02:00
|
|
|
#include "llvm/BinaryFormat/COFF.h"
|
2017-06-14 17:59:27 +02:00
|
|
|
#include "llvm/ObjectYAML/CodeViewYAMLDebugSections.h"
|
2017-12-06 19:58:48 +01:00
|
|
|
#include "llvm/ObjectYAML/CodeViewYAMLTypeHashing.h"
|
2017-06-14 17:59:27 +02:00
|
|
|
#include "llvm/ObjectYAML/CodeViewYAMLTypes.h"
|
2016-03-01 20:15:06 +01:00
|
|
|
#include "llvm/ObjectYAML/YAML.h"
|
2017-07-01 03:35:55 +02:00
|
|
|
#include <cstdint>
|
|
|
|
#include <vector>
|
2013-05-18 00:58:42 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
namespace COFF {
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
inline Characteristics operator|(Characteristics a, Characteristics b) {
|
|
|
|
uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
|
|
|
|
return static_cast<Characteristics>(Ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline SectionCharacteristics operator|(SectionCharacteristics a,
|
|
|
|
SectionCharacteristics b) {
|
|
|
|
uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
|
|
|
|
return static_cast<SectionCharacteristics>(Ret);
|
|
|
|
}
|
2014-11-14 09:15:42 +01:00
|
|
|
|
|
|
|
inline DLLCharacteristics operator|(DLLCharacteristics a,
|
|
|
|
DLLCharacteristics b) {
|
|
|
|
uint16_t Ret = static_cast<uint16_t>(a) | static_cast<uint16_t>(b);
|
|
|
|
return static_cast<DLLCharacteristics>(Ret);
|
|
|
|
}
|
2017-07-01 03:35:55 +02:00
|
|
|
|
|
|
|
} // end namespace COFF
|
2013-05-18 00:58:42 +02:00
|
|
|
|
|
|
|
// The structure of the yaml files is not an exact 1:1 match to COFF. In order
|
|
|
|
// to use yaml::IO, we use these structures which are closer to the source.
|
|
|
|
namespace COFFYAML {
|
2017-07-01 03:35:55 +02:00
|
|
|
|
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint8_t, COMDATType)
|
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics)
|
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint8_t, AuxSymbolType)
|
|
|
|
|
|
|
|
struct Relocation {
|
|
|
|
uint32_t VirtualAddress;
|
|
|
|
uint16_t Type;
|
2019-01-07 21:55:33 +01:00
|
|
|
|
|
|
|
// Normally a Relocation can refer to the symbol via its name.
|
|
|
|
// It can also use a direct symbol table index instead (with no name
|
|
|
|
// specified), allowing disambiguating between multiple symbols with the
|
|
|
|
// same name or crafting intentionally broken files for testing.
|
2017-07-01 03:35:55 +02:00
|
|
|
StringRef SymbolName;
|
2019-01-07 21:55:33 +01:00
|
|
|
Optional<uint32_t> SymbolTableIndex;
|
2017-07-01 03:35:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Section {
|
|
|
|
COFF::section Header;
|
|
|
|
unsigned Alignment = 0;
|
|
|
|
yaml::BinaryRef SectionData;
|
|
|
|
std::vector<CodeViewYAML::YAMLDebugSubsection> DebugS;
|
|
|
|
std::vector<CodeViewYAML::LeafRecord> DebugT;
|
2018-04-09 22:17:56 +02:00
|
|
|
std::vector<CodeViewYAML::LeafRecord> DebugP;
|
2017-12-06 19:58:48 +01:00
|
|
|
Optional<CodeViewYAML::DebugHSection> DebugH;
|
2017-07-01 03:35:55 +02:00
|
|
|
std::vector<Relocation> Relocations;
|
|
|
|
StringRef Name;
|
|
|
|
|
|
|
|
Section();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Symbol {
|
|
|
|
COFF::symbol Header;
|
|
|
|
COFF::SymbolBaseType SimpleType = COFF::IMAGE_SYM_TYPE_NULL;
|
|
|
|
COFF::SymbolComplexType ComplexType = COFF::IMAGE_SYM_DTYPE_NULL;
|
|
|
|
Optional<COFF::AuxiliaryFunctionDefinition> FunctionDefinition;
|
|
|
|
Optional<COFF::AuxiliarybfAndefSymbol> bfAndefSymbol;
|
|
|
|
Optional<COFF::AuxiliaryWeakExternal> WeakExternal;
|
|
|
|
StringRef File;
|
|
|
|
Optional<COFF::AuxiliarySectionDefinition> SectionDefinition;
|
|
|
|
Optional<COFF::AuxiliaryCLRToken> CLRToken;
|
|
|
|
StringRef Name;
|
|
|
|
|
|
|
|
Symbol();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PEHeader {
|
|
|
|
COFF::PE32Header Header;
|
|
|
|
Optional<COFF::DataDirectory> DataDirectories[COFF::NUM_DATA_DIRECTORIES];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Object {
|
|
|
|
Optional<PEHeader> OptionalHeader;
|
|
|
|
COFF::header Header;
|
|
|
|
std::vector<Section> Sections;
|
|
|
|
std::vector<Symbol> Symbols;
|
|
|
|
|
|
|
|
Object();
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace COFFYAML
|
|
|
|
|
|
|
|
} // end namespace llvm
|
2013-05-18 00:58:42 +02:00
|
|
|
|
|
|
|
LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
|
|
|
|
LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
|
2013-06-06 15:06:17 +02:00
|
|
|
LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
|
2013-05-18 00:58:42 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace yaml {
|
|
|
|
|
2014-03-19 05:47:47 +01:00
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics> {
|
|
|
|
static void enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<COFFYAML::AuxSymbolType> {
|
|
|
|
static void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<COFFYAML::COMDATType> {
|
|
|
|
static void enumeration(IO &IO, COFFYAML::COMDATType &Value);
|
|
|
|
};
|
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<COFF::MachineTypes> {
|
|
|
|
static void enumeration(IO &IO, COFF::MachineTypes &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
|
|
|
|
static void enumeration(IO &IO, COFF::SymbolBaseType &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
|
|
|
|
static void enumeration(IO &IO, COFF::SymbolStorageClass &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
|
|
|
|
static void enumeration(IO &IO, COFF::SymbolComplexType &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2014-04-08 01:12:20 +02:00
|
|
|
struct ScalarEnumerationTraits<COFF::RelocationTypeI386> {
|
|
|
|
static void enumeration(IO &IO, COFF::RelocationTypeI386 &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<COFF::RelocationTypeAMD64> {
|
|
|
|
static void enumeration(IO &IO, COFF::RelocationTypeAMD64 &Value);
|
2013-05-18 00:58:42 +02:00
|
|
|
};
|
|
|
|
|
2017-11-06 08:20:58 +01:00
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<COFF::RelocationTypesARM> {
|
|
|
|
static void enumeration(IO &IO, COFF::RelocationTypesARM &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<COFF::RelocationTypesARM64> {
|
|
|
|
static void enumeration(IO &IO, COFF::RelocationTypesARM64 &Value);
|
|
|
|
};
|
|
|
|
|
2014-11-14 09:15:42 +01:00
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<COFF::WindowsSubsystem> {
|
|
|
|
static void enumeration(IO &IO, COFF::WindowsSubsystem &Value);
|
|
|
|
};
|
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
template <>
|
|
|
|
struct ScalarBitSetTraits<COFF::Characteristics> {
|
|
|
|
static void bitset(IO &IO, COFF::Characteristics &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
|
|
|
|
static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
|
|
|
|
};
|
|
|
|
|
2014-11-14 09:15:42 +01:00
|
|
|
template <>
|
|
|
|
struct ScalarBitSetTraits<COFF::DLLCharacteristics> {
|
|
|
|
static void bitset(IO &IO, COFF::DLLCharacteristics &Value);
|
|
|
|
};
|
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
template <>
|
2013-06-06 15:06:17 +02:00
|
|
|
struct MappingTraits<COFFYAML::Relocation> {
|
|
|
|
static void mapping(IO &IO, COFFYAML::Relocation &Rel);
|
2013-05-18 00:58:42 +02:00
|
|
|
};
|
|
|
|
|
2014-11-14 09:15:42 +01:00
|
|
|
template <>
|
|
|
|
struct MappingTraits<COFFYAML::PEHeader> {
|
|
|
|
static void mapping(IO &IO, COFFYAML::PEHeader &PH);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct MappingTraits<COFF::DataDirectory> {
|
|
|
|
static void mapping(IO &IO, COFF::DataDirectory &DD);
|
|
|
|
};
|
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
template <>
|
|
|
|
struct MappingTraits<COFF::header> {
|
|
|
|
static void mapping(IO &IO, COFF::header &H);
|
|
|
|
};
|
|
|
|
|
2014-03-19 05:47:47 +01:00
|
|
|
template <> struct MappingTraits<COFF::AuxiliaryFunctionDefinition> {
|
|
|
|
static void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct MappingTraits<COFF::AuxiliarybfAndefSymbol> {
|
|
|
|
static void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct MappingTraits<COFF::AuxiliaryWeakExternal> {
|
|
|
|
static void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct MappingTraits<COFF::AuxiliarySectionDefinition> {
|
|
|
|
static void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct MappingTraits<COFF::AuxiliaryCLRToken> {
|
|
|
|
static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT);
|
|
|
|
};
|
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
template <>
|
|
|
|
struct MappingTraits<COFFYAML::Symbol> {
|
|
|
|
static void mapping(IO &IO, COFFYAML::Symbol &S);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct MappingTraits<COFFYAML::Section> {
|
|
|
|
static void mapping(IO &IO, COFFYAML::Section &Sec);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct MappingTraits<COFFYAML::Object> {
|
|
|
|
static void mapping(IO &IO, COFFYAML::Object &Obj);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace yaml
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2017-07-01 03:35:55 +02:00
|
|
|
#endif // LLVM_OBJECTYAML_COFFYAML_H
|