2013-05-18 00:58:42 +02:00
|
|
|
//===- COFFYAML.cpp - COFF YAMLIO implementation --------------------------===//
|
|
|
|
//
|
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 defines classes for handling the YAML representation of COFF.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-03-01 20:15:06 +01:00
|
|
|
#include "llvm/ObjectYAML/COFFYAML.h"
|
2017-07-01 03:35:55 +02:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstring>
|
2013-05-18 00:58:42 +02:00
|
|
|
|
|
|
|
#define ECase(X) IO.enumCase(Value, #X, COFF::X);
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
namespace COFFYAML {
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
Section::Section() { memset(&Header, 0, sizeof(COFF::section)); }
|
|
|
|
Symbol::Symbol() { memset(&Header, 0, sizeof(COFF::symbol)); }
|
|
|
|
Object::Object() { memset(&Header, 0, sizeof(COFF::header)); }
|
2017-07-01 03:35:55 +02:00
|
|
|
|
|
|
|
} // end namespace COFFYAML
|
2013-05-18 00:58:42 +02:00
|
|
|
|
|
|
|
namespace yaml {
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2014-03-19 05:47:47 +01:00
|
|
|
void ScalarEnumerationTraits<COFFYAML::COMDATType>::enumeration(
|
|
|
|
IO &IO, COFFYAML::COMDATType &Value) {
|
|
|
|
IO.enumCase(Value, "0", 0);
|
|
|
|
ECase(IMAGE_COMDAT_SELECT_NODUPLICATES);
|
|
|
|
ECase(IMAGE_COMDAT_SELECT_ANY);
|
|
|
|
ECase(IMAGE_COMDAT_SELECT_SAME_SIZE);
|
|
|
|
ECase(IMAGE_COMDAT_SELECT_EXACT_MATCH);
|
|
|
|
ECase(IMAGE_COMDAT_SELECT_ASSOCIATIVE);
|
|
|
|
ECase(IMAGE_COMDAT_SELECT_LARGEST);
|
|
|
|
ECase(IMAGE_COMDAT_SELECT_NEWEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics>::enumeration(
|
|
|
|
IO &IO, COFFYAML::WeakExternalCharacteristics &Value) {
|
2014-04-09 18:38:15 +02:00
|
|
|
IO.enumCase(Value, "0", 0);
|
2014-03-19 05:47:47 +01:00
|
|
|
ECase(IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY);
|
|
|
|
ECase(IMAGE_WEAK_EXTERN_SEARCH_LIBRARY);
|
|
|
|
ECase(IMAGE_WEAK_EXTERN_SEARCH_ALIAS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScalarEnumerationTraits<COFFYAML::AuxSymbolType>::enumeration(
|
|
|
|
IO &IO, COFFYAML::AuxSymbolType &Value) {
|
|
|
|
ECase(IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF);
|
|
|
|
}
|
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
void ScalarEnumerationTraits<COFF::MachineTypes>::enumeration(
|
|
|
|
IO &IO, COFF::MachineTypes &Value) {
|
|
|
|
ECase(IMAGE_FILE_MACHINE_UNKNOWN);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_AM33);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_AMD64);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_ARM);
|
2014-03-11 04:08:37 +01:00
|
|
|
ECase(IMAGE_FILE_MACHINE_ARMNT);
|
2015-07-28 18:18:17 +02:00
|
|
|
ECase(IMAGE_FILE_MACHINE_ARM64);
|
2013-05-18 00:58:42 +02:00
|
|
|
ECase(IMAGE_FILE_MACHINE_EBC);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_I386);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_IA64);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_M32R);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_MIPS16);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_MIPSFPU);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_MIPSFPU16);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_POWERPC);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_POWERPCFP);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_R4000);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_SH3);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_SH3DSP);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_SH4);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_SH5);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_THUMB);
|
|
|
|
ECase(IMAGE_FILE_MACHINE_WCEMIPSV2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScalarEnumerationTraits<COFF::SymbolBaseType>::enumeration(
|
|
|
|
IO &IO, COFF::SymbolBaseType &Value) {
|
|
|
|
ECase(IMAGE_SYM_TYPE_NULL);
|
|
|
|
ECase(IMAGE_SYM_TYPE_VOID);
|
|
|
|
ECase(IMAGE_SYM_TYPE_CHAR);
|
|
|
|
ECase(IMAGE_SYM_TYPE_SHORT);
|
|
|
|
ECase(IMAGE_SYM_TYPE_INT);
|
|
|
|
ECase(IMAGE_SYM_TYPE_LONG);
|
|
|
|
ECase(IMAGE_SYM_TYPE_FLOAT);
|
|
|
|
ECase(IMAGE_SYM_TYPE_DOUBLE);
|
|
|
|
ECase(IMAGE_SYM_TYPE_STRUCT);
|
|
|
|
ECase(IMAGE_SYM_TYPE_UNION);
|
|
|
|
ECase(IMAGE_SYM_TYPE_ENUM);
|
|
|
|
ECase(IMAGE_SYM_TYPE_MOE);
|
|
|
|
ECase(IMAGE_SYM_TYPE_BYTE);
|
|
|
|
ECase(IMAGE_SYM_TYPE_WORD);
|
|
|
|
ECase(IMAGE_SYM_TYPE_UINT);
|
|
|
|
ECase(IMAGE_SYM_TYPE_DWORD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScalarEnumerationTraits<COFF::SymbolStorageClass>::enumeration(
|
|
|
|
IO &IO, COFF::SymbolStorageClass &Value) {
|
|
|
|
ECase(IMAGE_SYM_CLASS_END_OF_FUNCTION);
|
|
|
|
ECase(IMAGE_SYM_CLASS_NULL);
|
|
|
|
ECase(IMAGE_SYM_CLASS_AUTOMATIC);
|
|
|
|
ECase(IMAGE_SYM_CLASS_EXTERNAL);
|
|
|
|
ECase(IMAGE_SYM_CLASS_STATIC);
|
|
|
|
ECase(IMAGE_SYM_CLASS_REGISTER);
|
|
|
|
ECase(IMAGE_SYM_CLASS_EXTERNAL_DEF);
|
|
|
|
ECase(IMAGE_SYM_CLASS_LABEL);
|
|
|
|
ECase(IMAGE_SYM_CLASS_UNDEFINED_LABEL);
|
|
|
|
ECase(IMAGE_SYM_CLASS_MEMBER_OF_STRUCT);
|
|
|
|
ECase(IMAGE_SYM_CLASS_ARGUMENT);
|
|
|
|
ECase(IMAGE_SYM_CLASS_STRUCT_TAG);
|
|
|
|
ECase(IMAGE_SYM_CLASS_MEMBER_OF_UNION);
|
|
|
|
ECase(IMAGE_SYM_CLASS_UNION_TAG);
|
|
|
|
ECase(IMAGE_SYM_CLASS_TYPE_DEFINITION);
|
|
|
|
ECase(IMAGE_SYM_CLASS_UNDEFINED_STATIC);
|
|
|
|
ECase(IMAGE_SYM_CLASS_ENUM_TAG);
|
|
|
|
ECase(IMAGE_SYM_CLASS_MEMBER_OF_ENUM);
|
|
|
|
ECase(IMAGE_SYM_CLASS_REGISTER_PARAM);
|
|
|
|
ECase(IMAGE_SYM_CLASS_BIT_FIELD);
|
|
|
|
ECase(IMAGE_SYM_CLASS_BLOCK);
|
|
|
|
ECase(IMAGE_SYM_CLASS_FUNCTION);
|
|
|
|
ECase(IMAGE_SYM_CLASS_END_OF_STRUCT);
|
|
|
|
ECase(IMAGE_SYM_CLASS_FILE);
|
|
|
|
ECase(IMAGE_SYM_CLASS_SECTION);
|
|
|
|
ECase(IMAGE_SYM_CLASS_WEAK_EXTERNAL);
|
|
|
|
ECase(IMAGE_SYM_CLASS_CLR_TOKEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScalarEnumerationTraits<COFF::SymbolComplexType>::enumeration(
|
|
|
|
IO &IO, COFF::SymbolComplexType &Value) {
|
|
|
|
ECase(IMAGE_SYM_DTYPE_NULL);
|
|
|
|
ECase(IMAGE_SYM_DTYPE_POINTER);
|
|
|
|
ECase(IMAGE_SYM_DTYPE_FUNCTION);
|
|
|
|
ECase(IMAGE_SYM_DTYPE_ARRAY);
|
|
|
|
}
|
|
|
|
|
2014-04-08 01:12:20 +02:00
|
|
|
void ScalarEnumerationTraits<COFF::RelocationTypeI386>::enumeration(
|
|
|
|
IO &IO, COFF::RelocationTypeI386 &Value) {
|
2013-05-18 00:58:42 +02:00
|
|
|
ECase(IMAGE_REL_I386_ABSOLUTE);
|
|
|
|
ECase(IMAGE_REL_I386_DIR16);
|
|
|
|
ECase(IMAGE_REL_I386_REL16);
|
|
|
|
ECase(IMAGE_REL_I386_DIR32);
|
|
|
|
ECase(IMAGE_REL_I386_DIR32NB);
|
|
|
|
ECase(IMAGE_REL_I386_SEG12);
|
|
|
|
ECase(IMAGE_REL_I386_SECTION);
|
|
|
|
ECase(IMAGE_REL_I386_SECREL);
|
|
|
|
ECase(IMAGE_REL_I386_TOKEN);
|
|
|
|
ECase(IMAGE_REL_I386_SECREL7);
|
|
|
|
ECase(IMAGE_REL_I386_REL32);
|
2014-04-08 01:12:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScalarEnumerationTraits<COFF::RelocationTypeAMD64>::enumeration(
|
|
|
|
IO &IO, COFF::RelocationTypeAMD64 &Value) {
|
2013-05-18 00:58:42 +02:00
|
|
|
ECase(IMAGE_REL_AMD64_ABSOLUTE);
|
|
|
|
ECase(IMAGE_REL_AMD64_ADDR64);
|
|
|
|
ECase(IMAGE_REL_AMD64_ADDR32);
|
|
|
|
ECase(IMAGE_REL_AMD64_ADDR32NB);
|
|
|
|
ECase(IMAGE_REL_AMD64_REL32);
|
|
|
|
ECase(IMAGE_REL_AMD64_REL32_1);
|
|
|
|
ECase(IMAGE_REL_AMD64_REL32_2);
|
|
|
|
ECase(IMAGE_REL_AMD64_REL32_3);
|
|
|
|
ECase(IMAGE_REL_AMD64_REL32_4);
|
|
|
|
ECase(IMAGE_REL_AMD64_REL32_5);
|
|
|
|
ECase(IMAGE_REL_AMD64_SECTION);
|
|
|
|
ECase(IMAGE_REL_AMD64_SECREL);
|
|
|
|
ECase(IMAGE_REL_AMD64_SECREL7);
|
|
|
|
ECase(IMAGE_REL_AMD64_TOKEN);
|
|
|
|
ECase(IMAGE_REL_AMD64_SREL32);
|
|
|
|
ECase(IMAGE_REL_AMD64_PAIR);
|
|
|
|
ECase(IMAGE_REL_AMD64_SSPAN32);
|
|
|
|
}
|
2014-11-14 09:15:42 +01:00
|
|
|
|
2017-11-06 08:20:58 +01:00
|
|
|
void ScalarEnumerationTraits<COFF::RelocationTypesARM>::enumeration(
|
|
|
|
IO &IO, COFF::RelocationTypesARM &Value) {
|
|
|
|
ECase(IMAGE_REL_ARM_ABSOLUTE);
|
|
|
|
ECase(IMAGE_REL_ARM_ADDR32);
|
|
|
|
ECase(IMAGE_REL_ARM_ADDR32NB);
|
|
|
|
ECase(IMAGE_REL_ARM_BRANCH24);
|
|
|
|
ECase(IMAGE_REL_ARM_BRANCH11);
|
|
|
|
ECase(IMAGE_REL_ARM_TOKEN);
|
|
|
|
ECase(IMAGE_REL_ARM_BLX24);
|
|
|
|
ECase(IMAGE_REL_ARM_BLX11);
|
|
|
|
ECase(IMAGE_REL_ARM_SECTION);
|
|
|
|
ECase(IMAGE_REL_ARM_SECREL);
|
|
|
|
ECase(IMAGE_REL_ARM_MOV32A);
|
|
|
|
ECase(IMAGE_REL_ARM_MOV32T);
|
|
|
|
ECase(IMAGE_REL_ARM_BRANCH20T);
|
|
|
|
ECase(IMAGE_REL_ARM_BRANCH24T);
|
|
|
|
ECase(IMAGE_REL_ARM_BLX23T);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScalarEnumerationTraits<COFF::RelocationTypesARM64>::enumeration(
|
|
|
|
IO &IO, COFF::RelocationTypesARM64 &Value) {
|
|
|
|
ECase(IMAGE_REL_ARM64_ABSOLUTE);
|
|
|
|
ECase(IMAGE_REL_ARM64_ADDR32);
|
|
|
|
ECase(IMAGE_REL_ARM64_ADDR32NB);
|
|
|
|
ECase(IMAGE_REL_ARM64_BRANCH26);
|
|
|
|
ECase(IMAGE_REL_ARM64_PAGEBASE_REL21);
|
|
|
|
ECase(IMAGE_REL_ARM64_REL21);
|
|
|
|
ECase(IMAGE_REL_ARM64_PAGEOFFSET_12A);
|
|
|
|
ECase(IMAGE_REL_ARM64_PAGEOFFSET_12L);
|
|
|
|
ECase(IMAGE_REL_ARM64_SECREL);
|
|
|
|
ECase(IMAGE_REL_ARM64_SECREL_LOW12A);
|
|
|
|
ECase(IMAGE_REL_ARM64_SECREL_HIGH12A);
|
|
|
|
ECase(IMAGE_REL_ARM64_SECREL_LOW12L);
|
|
|
|
ECase(IMAGE_REL_ARM64_TOKEN);
|
|
|
|
ECase(IMAGE_REL_ARM64_SECTION);
|
|
|
|
ECase(IMAGE_REL_ARM64_ADDR64);
|
|
|
|
ECase(IMAGE_REL_ARM64_BRANCH19);
|
|
|
|
ECase(IMAGE_REL_ARM64_BRANCH14);
|
|
|
|
}
|
|
|
|
|
2014-11-14 09:15:42 +01:00
|
|
|
void ScalarEnumerationTraits<COFF::WindowsSubsystem>::enumeration(
|
|
|
|
IO &IO, COFF::WindowsSubsystem &Value) {
|
2017-07-01 03:35:55 +02:00
|
|
|
ECase(IMAGE_SUBSYSTEM_UNKNOWN);
|
|
|
|
ECase(IMAGE_SUBSYSTEM_NATIVE);
|
|
|
|
ECase(IMAGE_SUBSYSTEM_WINDOWS_GUI);
|
|
|
|
ECase(IMAGE_SUBSYSTEM_WINDOWS_CUI);
|
|
|
|
ECase(IMAGE_SUBSYSTEM_OS2_CUI);
|
|
|
|
ECase(IMAGE_SUBSYSTEM_POSIX_CUI);
|
|
|
|
ECase(IMAGE_SUBSYSTEM_NATIVE_WINDOWS);
|
|
|
|
ECase(IMAGE_SUBSYSTEM_WINDOWS_CE_GUI);
|
|
|
|
ECase(IMAGE_SUBSYSTEM_EFI_APPLICATION);
|
|
|
|
ECase(IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER);
|
|
|
|
ECase(IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER);
|
|
|
|
ECase(IMAGE_SUBSYSTEM_EFI_ROM);
|
|
|
|
ECase(IMAGE_SUBSYSTEM_XBOX);
|
|
|
|
ECase(IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION);
|
2014-11-14 09:15:42 +01:00
|
|
|
}
|
2013-05-18 00:58:42 +02:00
|
|
|
#undef ECase
|
|
|
|
|
|
|
|
#define BCase(X) IO.bitSetCase(Value, #X, COFF::X);
|
|
|
|
void ScalarBitSetTraits<COFF::Characteristics>::bitset(
|
|
|
|
IO &IO, COFF::Characteristics &Value) {
|
|
|
|
BCase(IMAGE_FILE_RELOCS_STRIPPED);
|
|
|
|
BCase(IMAGE_FILE_EXECUTABLE_IMAGE);
|
|
|
|
BCase(IMAGE_FILE_LINE_NUMS_STRIPPED);
|
|
|
|
BCase(IMAGE_FILE_LOCAL_SYMS_STRIPPED);
|
|
|
|
BCase(IMAGE_FILE_AGGRESSIVE_WS_TRIM);
|
|
|
|
BCase(IMAGE_FILE_LARGE_ADDRESS_AWARE);
|
|
|
|
BCase(IMAGE_FILE_BYTES_REVERSED_LO);
|
|
|
|
BCase(IMAGE_FILE_32BIT_MACHINE);
|
|
|
|
BCase(IMAGE_FILE_DEBUG_STRIPPED);
|
|
|
|
BCase(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP);
|
|
|
|
BCase(IMAGE_FILE_NET_RUN_FROM_SWAP);
|
|
|
|
BCase(IMAGE_FILE_SYSTEM);
|
|
|
|
BCase(IMAGE_FILE_DLL);
|
|
|
|
BCase(IMAGE_FILE_UP_SYSTEM_ONLY);
|
|
|
|
BCase(IMAGE_FILE_BYTES_REVERSED_HI);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScalarBitSetTraits<COFF::SectionCharacteristics>::bitset(
|
|
|
|
IO &IO, COFF::SectionCharacteristics &Value) {
|
2015-07-30 18:47:56 +02:00
|
|
|
BCase(IMAGE_SCN_TYPE_NOLOAD);
|
2013-05-18 00:58:42 +02:00
|
|
|
BCase(IMAGE_SCN_TYPE_NO_PAD);
|
|
|
|
BCase(IMAGE_SCN_CNT_CODE);
|
|
|
|
BCase(IMAGE_SCN_CNT_INITIALIZED_DATA);
|
|
|
|
BCase(IMAGE_SCN_CNT_UNINITIALIZED_DATA);
|
|
|
|
BCase(IMAGE_SCN_LNK_OTHER);
|
|
|
|
BCase(IMAGE_SCN_LNK_INFO);
|
|
|
|
BCase(IMAGE_SCN_LNK_REMOVE);
|
|
|
|
BCase(IMAGE_SCN_LNK_COMDAT);
|
|
|
|
BCase(IMAGE_SCN_GPREL);
|
|
|
|
BCase(IMAGE_SCN_MEM_PURGEABLE);
|
|
|
|
BCase(IMAGE_SCN_MEM_16BIT);
|
|
|
|
BCase(IMAGE_SCN_MEM_LOCKED);
|
|
|
|
BCase(IMAGE_SCN_MEM_PRELOAD);
|
|
|
|
BCase(IMAGE_SCN_LNK_NRELOC_OVFL);
|
|
|
|
BCase(IMAGE_SCN_MEM_DISCARDABLE);
|
|
|
|
BCase(IMAGE_SCN_MEM_NOT_CACHED);
|
|
|
|
BCase(IMAGE_SCN_MEM_NOT_PAGED);
|
|
|
|
BCase(IMAGE_SCN_MEM_SHARED);
|
|
|
|
BCase(IMAGE_SCN_MEM_EXECUTE);
|
|
|
|
BCase(IMAGE_SCN_MEM_READ);
|
|
|
|
BCase(IMAGE_SCN_MEM_WRITE);
|
|
|
|
}
|
2014-11-14 09:15:42 +01:00
|
|
|
|
|
|
|
void ScalarBitSetTraits<COFF::DLLCharacteristics>::bitset(
|
|
|
|
IO &IO, COFF::DLLCharacteristics &Value) {
|
|
|
|
BCase(IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA);
|
|
|
|
BCase(IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE);
|
|
|
|
BCase(IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY);
|
|
|
|
BCase(IMAGE_DLL_CHARACTERISTICS_NX_COMPAT);
|
|
|
|
BCase(IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION);
|
|
|
|
BCase(IMAGE_DLL_CHARACTERISTICS_NO_SEH);
|
|
|
|
BCase(IMAGE_DLL_CHARACTERISTICS_NO_BIND);
|
|
|
|
BCase(IMAGE_DLL_CHARACTERISTICS_APPCONTAINER);
|
|
|
|
BCase(IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER);
|
|
|
|
BCase(IMAGE_DLL_CHARACTERISTICS_GUARD_CF);
|
|
|
|
BCase(IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE);
|
|
|
|
}
|
2013-05-18 00:58:42 +02:00
|
|
|
#undef BCase
|
|
|
|
|
|
|
|
namespace {
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2014-03-19 05:47:47 +01:00
|
|
|
struct NSectionSelectionType {
|
|
|
|
NSectionSelectionType(IO &)
|
|
|
|
: SelectionType(COFFYAML::COMDATType(0)) {}
|
|
|
|
NSectionSelectionType(IO &, uint8_t C)
|
|
|
|
: SelectionType(COFFYAML::COMDATType(C)) {}
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2014-03-19 05:47:47 +01:00
|
|
|
uint8_t denormalize(IO &) { return SelectionType; }
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2014-03-19 05:47:47 +01:00
|
|
|
COFFYAML::COMDATType SelectionType;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NWeakExternalCharacteristics {
|
|
|
|
NWeakExternalCharacteristics(IO &)
|
|
|
|
: Characteristics(COFFYAML::WeakExternalCharacteristics(0)) {}
|
|
|
|
NWeakExternalCharacteristics(IO &, uint32_t C)
|
|
|
|
: Characteristics(COFFYAML::WeakExternalCharacteristics(C)) {}
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2014-03-19 05:47:47 +01:00
|
|
|
uint32_t denormalize(IO &) { return Characteristics; }
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2014-03-19 05:47:47 +01:00
|
|
|
COFFYAML::WeakExternalCharacteristics Characteristics;
|
|
|
|
};
|
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
struct NSectionCharacteristics {
|
|
|
|
NSectionCharacteristics(IO &)
|
|
|
|
: Characteristics(COFF::SectionCharacteristics(0)) {}
|
|
|
|
NSectionCharacteristics(IO &, uint32_t C)
|
|
|
|
: Characteristics(COFF::SectionCharacteristics(C)) {}
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
uint32_t denormalize(IO &) { return Characteristics; }
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
COFF::SectionCharacteristics Characteristics;
|
|
|
|
};
|
|
|
|
|
2014-03-19 05:47:47 +01:00
|
|
|
struct NAuxTokenType {
|
|
|
|
NAuxTokenType(IO &)
|
|
|
|
: AuxType(COFFYAML::AuxSymbolType(0)) {}
|
|
|
|
NAuxTokenType(IO &, uint8_t C)
|
|
|
|
: AuxType(COFFYAML::AuxSymbolType(C)) {}
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2014-03-19 05:47:47 +01:00
|
|
|
uint32_t denormalize(IO &) { return AuxType; }
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2014-03-19 05:47:47 +01:00
|
|
|
COFFYAML::AuxSymbolType AuxType;
|
|
|
|
};
|
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
struct NStorageClass {
|
|
|
|
NStorageClass(IO &) : StorageClass(COFF::SymbolStorageClass(0)) {}
|
|
|
|
NStorageClass(IO &, uint8_t S) : StorageClass(COFF::SymbolStorageClass(S)) {}
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
uint8_t denormalize(IO &) { return StorageClass; }
|
|
|
|
|
|
|
|
COFF::SymbolStorageClass StorageClass;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NMachine {
|
|
|
|
NMachine(IO &) : Machine(COFF::MachineTypes(0)) {}
|
|
|
|
NMachine(IO &, uint16_t M) : Machine(COFF::MachineTypes(M)) {}
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
uint16_t denormalize(IO &) { return Machine; }
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
COFF::MachineTypes Machine;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NHeaderCharacteristics {
|
|
|
|
NHeaderCharacteristics(IO &) : Characteristics(COFF::Characteristics(0)) {}
|
|
|
|
NHeaderCharacteristics(IO &, uint16_t C)
|
|
|
|
: Characteristics(COFF::Characteristics(C)) {}
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
uint16_t denormalize(IO &) { return Characteristics; }
|
|
|
|
|
|
|
|
COFF::Characteristics Characteristics;
|
|
|
|
};
|
|
|
|
|
2014-04-08 01:12:20 +02:00
|
|
|
template <typename RelocType>
|
2013-05-18 00:58:42 +02:00
|
|
|
struct NType {
|
2014-04-08 01:12:20 +02:00
|
|
|
NType(IO &) : Type(RelocType(0)) {}
|
|
|
|
NType(IO &, uint16_t T) : Type(RelocType(T)) {}
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
uint16_t denormalize(IO &) { return Type; }
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2014-04-08 01:12:20 +02:00
|
|
|
RelocType Type;
|
2013-05-18 00:58:42 +02:00
|
|
|
};
|
|
|
|
|
2014-11-14 09:15:42 +01:00
|
|
|
struct NWindowsSubsystem {
|
|
|
|
NWindowsSubsystem(IO &) : Subsystem(COFF::WindowsSubsystem(0)) {}
|
|
|
|
NWindowsSubsystem(IO &, uint16_t C) : Subsystem(COFF::WindowsSubsystem(C)) {}
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2014-11-14 09:15:42 +01:00
|
|
|
uint16_t denormalize(IO &) { return Subsystem; }
|
|
|
|
|
|
|
|
COFF::WindowsSubsystem Subsystem;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NDLLCharacteristics {
|
|
|
|
NDLLCharacteristics(IO &) : Characteristics(COFF::DLLCharacteristics(0)) {}
|
|
|
|
NDLLCharacteristics(IO &, uint16_t C)
|
|
|
|
: Characteristics(COFF::DLLCharacteristics(C)) {}
|
2017-07-01 03:35:55 +02:00
|
|
|
|
2014-11-14 09:15:42 +01:00
|
|
|
uint16_t denormalize(IO &) { return Characteristics; }
|
|
|
|
|
|
|
|
COFF::DLLCharacteristics Characteristics;
|
|
|
|
};
|
|
|
|
|
2017-07-01 03:35:55 +02:00
|
|
|
} // end anonymous namespace
|
2013-05-18 00:58:42 +02:00
|
|
|
|
2013-06-06 15:06:17 +02:00
|
|
|
void MappingTraits<COFFYAML::Relocation>::mapping(IO &IO,
|
|
|
|
COFFYAML::Relocation &Rel) {
|
2013-05-18 00:58:42 +02:00
|
|
|
IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
|
2019-01-07 21:55:33 +01:00
|
|
|
IO.mapOptional("SymbolName", Rel.SymbolName, StringRef());
|
|
|
|
IO.mapOptional("SymbolTableIndex", Rel.SymbolTableIndex);
|
2014-04-08 01:12:20 +02:00
|
|
|
|
|
|
|
COFF::header &H = *static_cast<COFF::header *>(IO.getContext());
|
|
|
|
if (H.Machine == COFF::IMAGE_FILE_MACHINE_I386) {
|
|
|
|
MappingNormalization<NType<COFF::RelocationTypeI386>, uint16_t> NT(
|
|
|
|
IO, Rel.Type);
|
|
|
|
IO.mapRequired("Type", NT->Type);
|
|
|
|
} else if (H.Machine == COFF::IMAGE_FILE_MACHINE_AMD64) {
|
|
|
|
MappingNormalization<NType<COFF::RelocationTypeAMD64>, uint16_t> NT(
|
|
|
|
IO, Rel.Type);
|
2017-11-06 08:20:58 +01:00
|
|
|
IO.mapRequired("Type", NT->Type);
|
|
|
|
} else if (H.Machine == COFF::IMAGE_FILE_MACHINE_ARMNT) {
|
|
|
|
MappingNormalization<NType<COFF::RelocationTypesARM>, uint16_t> NT(
|
|
|
|
IO, Rel.Type);
|
|
|
|
IO.mapRequired("Type", NT->Type);
|
|
|
|
} else if (H.Machine == COFF::IMAGE_FILE_MACHINE_ARM64) {
|
|
|
|
MappingNormalization<NType<COFF::RelocationTypesARM64>, uint16_t> NT(
|
|
|
|
IO, Rel.Type);
|
2014-04-08 01:12:20 +02:00
|
|
|
IO.mapRequired("Type", NT->Type);
|
|
|
|
} else {
|
|
|
|
IO.mapRequired("Type", Rel.Type);
|
|
|
|
}
|
2013-05-18 00:58:42 +02:00
|
|
|
}
|
|
|
|
|
2014-11-14 09:15:42 +01:00
|
|
|
void MappingTraits<COFF::DataDirectory>::mapping(IO &IO,
|
|
|
|
COFF::DataDirectory &DD) {
|
|
|
|
IO.mapRequired("RelativeVirtualAddress", DD.RelativeVirtualAddress);
|
|
|
|
IO.mapRequired("Size", DD.Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingTraits<COFFYAML::PEHeader>::mapping(IO &IO,
|
|
|
|
COFFYAML::PEHeader &PH) {
|
|
|
|
MappingNormalization<NWindowsSubsystem, uint16_t> NWS(IO,
|
|
|
|
PH.Header.Subsystem);
|
|
|
|
MappingNormalization<NDLLCharacteristics, uint16_t> NDC(
|
|
|
|
IO, PH.Header.DLLCharacteristics);
|
|
|
|
|
|
|
|
IO.mapRequired("AddressOfEntryPoint", PH.Header.AddressOfEntryPoint);
|
|
|
|
IO.mapRequired("ImageBase", PH.Header.ImageBase);
|
|
|
|
IO.mapRequired("SectionAlignment", PH.Header.SectionAlignment);
|
|
|
|
IO.mapRequired("FileAlignment", PH.Header.FileAlignment);
|
|
|
|
IO.mapRequired("MajorOperatingSystemVersion",
|
|
|
|
PH.Header.MajorOperatingSystemVersion);
|
|
|
|
IO.mapRequired("MinorOperatingSystemVersion",
|
|
|
|
PH.Header.MinorOperatingSystemVersion);
|
|
|
|
IO.mapRequired("MajorImageVersion", PH.Header.MajorImageVersion);
|
|
|
|
IO.mapRequired("MinorImageVersion", PH.Header.MinorImageVersion);
|
|
|
|
IO.mapRequired("MajorSubsystemVersion", PH.Header.MajorSubsystemVersion);
|
|
|
|
IO.mapRequired("MinorSubsystemVersion", PH.Header.MinorSubsystemVersion);
|
|
|
|
IO.mapRequired("Subsystem", NWS->Subsystem);
|
|
|
|
IO.mapRequired("DLLCharacteristics", NDC->Characteristics);
|
|
|
|
IO.mapRequired("SizeOfStackReserve", PH.Header.SizeOfStackReserve);
|
|
|
|
IO.mapRequired("SizeOfStackCommit", PH.Header.SizeOfStackCommit);
|
|
|
|
IO.mapRequired("SizeOfHeapReserve", PH.Header.SizeOfHeapReserve);
|
|
|
|
IO.mapRequired("SizeOfHeapCommit", PH.Header.SizeOfHeapCommit);
|
|
|
|
|
|
|
|
IO.mapOptional("ExportTable", PH.DataDirectories[COFF::EXPORT_TABLE]);
|
|
|
|
IO.mapOptional("ImportTable", PH.DataDirectories[COFF::IMPORT_TABLE]);
|
|
|
|
IO.mapOptional("ResourceTable", PH.DataDirectories[COFF::RESOURCE_TABLE]);
|
|
|
|
IO.mapOptional("ExceptionTable", PH.DataDirectories[COFF::EXCEPTION_TABLE]);
|
|
|
|
IO.mapOptional("CertificateTable", PH.DataDirectories[COFF::CERTIFICATE_TABLE]);
|
|
|
|
IO.mapOptional("BaseRelocationTable",
|
|
|
|
PH.DataDirectories[COFF::BASE_RELOCATION_TABLE]);
|
2016-06-02 19:10:43 +02:00
|
|
|
IO.mapOptional("Debug", PH.DataDirectories[COFF::DEBUG_DIRECTORY]);
|
2014-11-14 09:15:42 +01:00
|
|
|
IO.mapOptional("Architecture", PH.DataDirectories[COFF::ARCHITECTURE]);
|
|
|
|
IO.mapOptional("GlobalPtr", PH.DataDirectories[COFF::GLOBAL_PTR]);
|
|
|
|
IO.mapOptional("TlsTable", PH.DataDirectories[COFF::TLS_TABLE]);
|
|
|
|
IO.mapOptional("LoadConfigTable",
|
|
|
|
PH.DataDirectories[COFF::LOAD_CONFIG_TABLE]);
|
|
|
|
IO.mapOptional("BoundImport", PH.DataDirectories[COFF::BOUND_IMPORT]);
|
|
|
|
IO.mapOptional("IAT", PH.DataDirectories[COFF::IAT]);
|
|
|
|
IO.mapOptional("DelayImportDescriptor",
|
|
|
|
PH.DataDirectories[COFF::DELAY_IMPORT_DESCRIPTOR]);
|
|
|
|
IO.mapOptional("ClrRuntimeHeader",
|
|
|
|
PH.DataDirectories[COFF::CLR_RUNTIME_HEADER]);
|
|
|
|
}
|
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
void MappingTraits<COFF::header>::mapping(IO &IO, COFF::header &H) {
|
|
|
|
MappingNormalization<NMachine, uint16_t> NM(IO, H.Machine);
|
|
|
|
MappingNormalization<NHeaderCharacteristics, uint16_t> NC(IO,
|
|
|
|
H.Characteristics);
|
|
|
|
|
|
|
|
IO.mapRequired("Machine", NM->Machine);
|
|
|
|
IO.mapOptional("Characteristics", NC->Characteristics);
|
2014-04-08 01:12:20 +02:00
|
|
|
IO.setContext(static_cast<void *>(&H));
|
2013-05-18 00:58:42 +02:00
|
|
|
}
|
|
|
|
|
2014-03-19 05:47:47 +01:00
|
|
|
void MappingTraits<COFF::AuxiliaryFunctionDefinition>::mapping(
|
|
|
|
IO &IO, COFF::AuxiliaryFunctionDefinition &AFD) {
|
|
|
|
IO.mapRequired("TagIndex", AFD.TagIndex);
|
|
|
|
IO.mapRequired("TotalSize", AFD.TotalSize);
|
|
|
|
IO.mapRequired("PointerToLinenumber", AFD.PointerToLinenumber);
|
|
|
|
IO.mapRequired("PointerToNextFunction", AFD.PointerToNextFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingTraits<COFF::AuxiliarybfAndefSymbol>::mapping(
|
|
|
|
IO &IO, COFF::AuxiliarybfAndefSymbol &AAS) {
|
|
|
|
IO.mapRequired("Linenumber", AAS.Linenumber);
|
|
|
|
IO.mapRequired("PointerToNextFunction", AAS.PointerToNextFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingTraits<COFF::AuxiliaryWeakExternal>::mapping(
|
|
|
|
IO &IO, COFF::AuxiliaryWeakExternal &AWE) {
|
|
|
|
MappingNormalization<NWeakExternalCharacteristics, uint32_t> NWEC(
|
|
|
|
IO, AWE.Characteristics);
|
|
|
|
IO.mapRequired("TagIndex", AWE.TagIndex);
|
|
|
|
IO.mapRequired("Characteristics", NWEC->Characteristics);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingTraits<COFF::AuxiliarySectionDefinition>::mapping(
|
|
|
|
IO &IO, COFF::AuxiliarySectionDefinition &ASD) {
|
|
|
|
MappingNormalization<NSectionSelectionType, uint8_t> NSST(
|
|
|
|
IO, ASD.Selection);
|
|
|
|
|
|
|
|
IO.mapRequired("Length", ASD.Length);
|
|
|
|
IO.mapRequired("NumberOfRelocations", ASD.NumberOfRelocations);
|
|
|
|
IO.mapRequired("NumberOfLinenumbers", ASD.NumberOfLinenumbers);
|
|
|
|
IO.mapRequired("CheckSum", ASD.CheckSum);
|
|
|
|
IO.mapRequired("Number", ASD.Number);
|
|
|
|
IO.mapOptional("Selection", NSST->SelectionType, COFFYAML::COMDATType(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingTraits<COFF::AuxiliaryCLRToken>::mapping(
|
|
|
|
IO &IO, COFF::AuxiliaryCLRToken &ACT) {
|
|
|
|
MappingNormalization<NAuxTokenType, uint8_t> NATT(IO, ACT.AuxType);
|
|
|
|
IO.mapRequired("AuxType", NATT->AuxType);
|
|
|
|
IO.mapRequired("SymbolTableIndex", ACT.SymbolTableIndex);
|
|
|
|
}
|
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
void MappingTraits<COFFYAML::Symbol>::mapping(IO &IO, COFFYAML::Symbol &S) {
|
|
|
|
MappingNormalization<NStorageClass, uint8_t> NS(IO, S.Header.StorageClass);
|
|
|
|
|
|
|
|
IO.mapRequired("Name", S.Name);
|
|
|
|
IO.mapRequired("Value", S.Header.Value);
|
|
|
|
IO.mapRequired("SectionNumber", S.Header.SectionNumber);
|
|
|
|
IO.mapRequired("SimpleType", S.SimpleType);
|
|
|
|
IO.mapRequired("ComplexType", S.ComplexType);
|
|
|
|
IO.mapRequired("StorageClass", NS->StorageClass);
|
2014-03-19 05:47:47 +01:00
|
|
|
IO.mapOptional("FunctionDefinition", S.FunctionDefinition);
|
|
|
|
IO.mapOptional("bfAndefSymbol", S.bfAndefSymbol);
|
|
|
|
IO.mapOptional("WeakExternal", S.WeakExternal);
|
|
|
|
IO.mapOptional("File", S.File, StringRef());
|
|
|
|
IO.mapOptional("SectionDefinition", S.SectionDefinition);
|
|
|
|
IO.mapOptional("CLRToken", S.CLRToken);
|
2013-05-18 00:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MappingTraits<COFFYAML::Section>::mapping(IO &IO, COFFYAML::Section &Sec) {
|
|
|
|
MappingNormalization<NSectionCharacteristics, uint32_t> NC(
|
|
|
|
IO, Sec.Header.Characteristics);
|
|
|
|
IO.mapRequired("Name", Sec.Name);
|
|
|
|
IO.mapRequired("Characteristics", NC->Characteristics);
|
2014-11-14 09:15:42 +01:00
|
|
|
IO.mapOptional("VirtualAddress", Sec.Header.VirtualAddress, 0U);
|
|
|
|
IO.mapOptional("VirtualSize", Sec.Header.VirtualSize, 0U);
|
2016-03-17 17:55:11 +01:00
|
|
|
IO.mapOptional("Alignment", Sec.Alignment, 0U);
|
2017-06-14 17:59:27 +02:00
|
|
|
|
2018-04-09 22:17:56 +02:00
|
|
|
// If this is a .debug$S .debug$T .debug$P, or .debug$H section parse the
|
|
|
|
// semantic representation of the symbols/types. If it is any other kind
|
|
|
|
// of section, just deal in raw bytes.
|
2017-06-14 17:59:27 +02:00
|
|
|
IO.mapOptional("SectionData", Sec.SectionData);
|
|
|
|
if (Sec.Name == ".debug$S")
|
|
|
|
IO.mapOptional("Subsections", Sec.DebugS);
|
|
|
|
else if (Sec.Name == ".debug$T")
|
|
|
|
IO.mapOptional("Types", Sec.DebugT);
|
2018-04-09 22:17:56 +02:00
|
|
|
else if (Sec.Name == ".debug$P")
|
|
|
|
IO.mapOptional("PrecompTypes", Sec.DebugP);
|
2017-12-06 19:58:48 +01:00
|
|
|
else if (Sec.Name == ".debug$H")
|
|
|
|
IO.mapOptional("GlobalHashes", Sec.DebugH);
|
2017-06-14 17:59:27 +02:00
|
|
|
|
2013-05-18 00:58:42 +02:00
|
|
|
IO.mapOptional("Relocations", Sec.Relocations);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingTraits<COFFYAML::Object>::mapping(IO &IO, COFFYAML::Object &Obj) {
|
2016-06-27 21:53:53 +02:00
|
|
|
IO.mapTag("!COFF", true);
|
2014-11-14 09:15:42 +01:00
|
|
|
IO.mapOptional("OptionalHeader", Obj.OptionalHeader);
|
2013-05-18 00:58:42 +02:00
|
|
|
IO.mapRequired("header", Obj.Header);
|
|
|
|
IO.mapRequired("sections", Obj.Sections);
|
|
|
|
IO.mapRequired("symbols", Obj.Symbols);
|
|
|
|
}
|
|
|
|
|
2017-07-01 03:35:55 +02:00
|
|
|
} // end namespace yaml
|
|
|
|
|
|
|
|
} // end namespace llvm
|