diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:50:12 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:50:12 +0000 |
commit | e6d1592492a3a379186bfb02bd0f4eda0669c0d5 (patch) | |
tree | 599ab169a01f1c86eda9adc774edaedde2f2db5b /include/llvm/BinaryFormat | |
parent | 1a56a5ead7a2e84bee8240f5f6b033b5f1707154 (diff) |
Notes
Diffstat (limited to 'include/llvm/BinaryFormat')
22 files changed, 1129 insertions, 472 deletions
diff --git a/include/llvm/BinaryFormat/AMDGPUMetadataVerifier.h b/include/llvm/BinaryFormat/AMDGPUMetadataVerifier.h index de44f41720ed..7332b2a7ea89 100644 --- a/include/llvm/BinaryFormat/AMDGPUMetadataVerifier.h +++ b/include/llvm/BinaryFormat/AMDGPUMetadataVerifier.h @@ -1,9 +1,8 @@ //===- AMDGPUMetadataVerifier.h - MsgPack Types -----------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -17,7 +16,7 @@ #ifndef LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H #define LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H -#include "llvm/BinaryFormat/MsgPackTypes.h" +#include "llvm/BinaryFormat/MsgPackDocument.h" namespace llvm { namespace AMDGPU { @@ -34,22 +33,22 @@ namespace V3 { class MetadataVerifier { bool Strict; - bool verifyScalar(msgpack::Node &Node, msgpack::ScalarNode::ScalarKind SKind, - function_ref<bool(msgpack::ScalarNode &)> verifyValue = {}); - bool verifyInteger(msgpack::Node &Node); - bool verifyArray(msgpack::Node &Node, - function_ref<bool(msgpack::Node &)> verifyNode, + bool verifyScalar(msgpack::DocNode &Node, msgpack::Type SKind, + function_ref<bool(msgpack::DocNode &)> verifyValue = {}); + bool verifyInteger(msgpack::DocNode &Node); + bool verifyArray(msgpack::DocNode &Node, + function_ref<bool(msgpack::DocNode &)> verifyNode, Optional<size_t> Size = None); - bool verifyEntry(msgpack::MapNode &MapNode, StringRef Key, bool Required, - function_ref<bool(msgpack::Node &)> verifyNode); + bool verifyEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required, + function_ref<bool(msgpack::DocNode &)> verifyNode); bool - verifyScalarEntry(msgpack::MapNode &MapNode, StringRef Key, bool Required, - msgpack::ScalarNode::ScalarKind SKind, - function_ref<bool(msgpack::ScalarNode &)> verifyValue = {}); - bool verifyIntegerEntry(msgpack::MapNode &MapNode, StringRef Key, + verifyScalarEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required, + msgpack::Type SKind, + function_ref<bool(msgpack::DocNode &)> verifyValue = {}); + bool verifyIntegerEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required); - bool verifyKernelArgs(msgpack::Node &Node); - bool verifyKernel(msgpack::Node &Node); + bool verifyKernelArgs(msgpack::DocNode &Node); + bool verifyKernel(msgpack::DocNode &Node); public: /// Construct a MetadataVerifier, specifying whether it will operate in \p @@ -59,7 +58,7 @@ public: /// Verify given HSA metadata. /// /// \returns True when successful, false when metadata is invalid. - bool verify(msgpack::Node &HSAMetadataRoot); + bool verify(msgpack::DocNode &HSAMetadataRoot); }; } // end namespace V3 diff --git a/include/llvm/BinaryFormat/COFF.h b/include/llvm/BinaryFormat/COFF.h index 7b973c03cc80..0fe38a437725 100644 --- a/include/llvm/BinaryFormat/COFF.h +++ b/include/llvm/BinaryFormat/COFF.h @@ -1,9 +1,8 @@ //===-- llvm/BinaryFormat/COFF.h --------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -371,13 +370,15 @@ enum RelocationTypesARM : unsigned { IMAGE_REL_ARM_TOKEN = 0x0005, IMAGE_REL_ARM_BLX24 = 0x0008, IMAGE_REL_ARM_BLX11 = 0x0009, + IMAGE_REL_ARM_REL32 = 0x000A, IMAGE_REL_ARM_SECTION = 0x000E, IMAGE_REL_ARM_SECREL = 0x000F, IMAGE_REL_ARM_MOV32A = 0x0010, IMAGE_REL_ARM_MOV32T = 0x0011, IMAGE_REL_ARM_BRANCH20T = 0x0012, IMAGE_REL_ARM_BRANCH24T = 0x0014, - IMAGE_REL_ARM_BLX23T = 0x0015 + IMAGE_REL_ARM_BLX23T = 0x0015, + IMAGE_REL_ARM_PAIR = 0x0016, }; enum RelocationTypesARM64 : unsigned { @@ -398,9 +399,10 @@ enum RelocationTypesARM64 : unsigned { IMAGE_REL_ARM64_ADDR64 = 0x000E, IMAGE_REL_ARM64_BRANCH19 = 0x000F, IMAGE_REL_ARM64_BRANCH14 = 0x0010, + IMAGE_REL_ARM64_REL32 = 0x0011, }; -enum COMDATType : unsigned { +enum COMDATType : uint8_t { IMAGE_COMDAT_SELECT_NODUPLICATES = 1, IMAGE_COMDAT_SELECT_ANY, IMAGE_COMDAT_SELECT_SAME_SIZE, diff --git a/include/llvm/BinaryFormat/Dwarf.def b/include/llvm/BinaryFormat/Dwarf.def index 6ad3cb57f62f..b0f78d0fd61f 100644 --- a/include/llvm/BinaryFormat/Dwarf.def +++ b/include/llvm/BinaryFormat/Dwarf.def @@ -1,9 +1,8 @@ //===- llvm/Support/Dwarf.def - Dwarf definitions ---------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -355,7 +354,13 @@ HANDLE_DW_AT(0x2107, GNU_vector, 0, GNU) HANDLE_DW_AT(0x2110, GNU_template_name, 0, GNU) HANDLE_DW_AT(0x210f, GNU_odr_signature, 0, GNU) HANDLE_DW_AT(0x2111, GNU_call_site_value, 0, GNU) +HANDLE_DW_AT (0x2112, GNU_call_site_data_value, 0, GNU) +HANDLE_DW_AT (0x2113, GNU_call_site_target, 0, GNU) +HANDLE_DW_AT (0x2114, GNU_call_site_target_clobbered, 0, GNU) +HANDLE_DW_AT (0x2115, GNU_tail_call, 0, GNU) +HANDLE_DW_AT (0x2116, GNU_all_tail_call_sites, 0, GNU) HANDLE_DW_AT(0x2117, GNU_all_call_sites, 0, GNU) +HANDLE_DW_AT (0x2118, GNU_all_source_call_sites, 0, GNU) HANDLE_DW_AT(0x2119, GNU_macros, 0, GNU) // Extensions for Fission proposal. HANDLE_DW_AT(0x2130, GNU_dwo_name, 0, GNU) @@ -387,6 +392,7 @@ HANDLE_DW_AT(0x3b31, BORLAND_closure, 0, BORLAND) HANDLE_DW_AT(0x3e00, LLVM_include_path, 0, LLVM) HANDLE_DW_AT(0x3e01, LLVM_config_macros, 0, LLVM) HANDLE_DW_AT(0x3e02, LLVM_isysroot, 0, LLVM) +HANDLE_DW_AT(0x3e03, LLVM_tag_offset, 0, LLVM) // Apple extensions. HANDLE_DW_AT(0x3fe1, APPLE_optimized, 0, APPLE) HANDLE_DW_AT(0x3fe2, APPLE_flags, 0, APPLE) @@ -627,6 +633,8 @@ HANDLE_DW_OP(0xa9, reinterpret, 5, DWARF) // Vendor extensions: // Extensions for GNU-style thread-local storage. HANDLE_DW_OP(0xe0, GNU_push_tls_address, 0, GNU) +// The GNU entry value extension. +HANDLE_DW_OP(0xf3, GNU_entry_value, 0, GNU) // Extensions for Fission proposal. HANDLE_DW_OP(0xfb, GNU_addr_index, 0, GNU) HANDLE_DW_OP(0xfc, GNU_const_index, 0, GNU) diff --git a/include/llvm/BinaryFormat/Dwarf.h b/include/llvm/BinaryFormat/Dwarf.h index 525a04d5e6cf..76d9c365c0a8 100644 --- a/include/llvm/BinaryFormat/Dwarf.h +++ b/include/llvm/BinaryFormat/Dwarf.h @@ -1,9 +1,8 @@ //===-- llvm/BinaryFormat/Dwarf.h ---Dwarf Constants-------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -130,7 +129,9 @@ enum LocationAtom { #include "llvm/BinaryFormat/Dwarf.def" DW_OP_lo_user = 0xe0, DW_OP_hi_user = 0xff, - DW_OP_LLVM_fragment = 0x1000 ///< Only used in LLVM metadata. + DW_OP_LLVM_fragment = 0x1000, ///< Only used in LLVM metadata. + DW_OP_LLVM_convert = 0x1001, ///< Only used in LLVM metadata. + DW_OP_LLVM_tag_offset = 0x1002, ///< Only used in LLVM metadata. }; enum TypeKind : uint8_t { diff --git a/include/llvm/BinaryFormat/DynamicTags.def b/include/llvm/BinaryFormat/DynamicTags.def index 2e15cc30fca7..aec408bd2d72 100644 --- a/include/llvm/BinaryFormat/DynamicTags.def +++ b/include/llvm/BinaryFormat/DynamicTags.def @@ -6,6 +6,11 @@ // such as DT_HIOS, etc. to allow using this file to in other contexts. // For example we can use it to generate a stringification switch statement. +#ifndef AARCH64_DYNAMIC_TAG +#define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) +#define AARCH64_DYNAMIC_TAG_DEFINED +#endif + #ifndef HEXAGON_DYNAMIC_TAG #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) #define HEXAGON_DYNAMIC_TAG_DEFINED @@ -16,6 +21,11 @@ #define MIPS_DYNAMIC_TAG_DEFINED #endif +#ifndef PPC_DYNAMIC_TAG +#define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) +#define PPC_DYNAMIC_TAG_DEFINED +#endif + #ifndef PPC64_DYNAMIC_TAG #define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) #define PPC64_DYNAMIC_TAG_DEFINED @@ -107,6 +117,10 @@ DYNAMIC_TAG(VERNEED, 0X6FFFFFFE) // The address of the version dependency // table. DYNAMIC_TAG(VERNEEDNUM, 0X6FFFFFFF) // The number of entries in DT_VERNEED. +// AArch64 specific dynamic table entries +AARCH64_DYNAMIC_TAG(AARCH64_BTI_PLT, 0x70000001) +AARCH64_DYNAMIC_TAG(AARCH64_PAC_PLT, 0x70000003) + // Hexagon specific dynamic table entries HEXAGON_DYNAMIC_TAG(HEXAGON_SYMSZ, 0x70000000) HEXAGON_DYNAMIC_TAG(HEXAGON_VER, 0x70000001) @@ -190,17 +204,27 @@ MIPS_DYNAMIC_TAG(MIPS_RWPLT, 0x70000034) // Points to the base MIPS_DYNAMIC_TAG(MIPS_RLD_MAP_REL, 0x70000035) // Relative offset of run time loader // map, used for debugging. +// PPC specific dynamic table entries. +PPC_DYNAMIC_TAG(PPC_GOT, 0x70000000) // Uses Secure PLT ABI. +PPC_DYNAMIC_TAG(PPC_OPT, 0x70000001) // Has TLS optimization. + // PPC64 specific dynamic table entries. PPC64_DYNAMIC_TAG(PPC64_GLINK, 0x70000000) // Address of 32 bytes before the // first glink lazy resolver stub. // Sun machine-independent extensions. DYNAMIC_TAG(AUXILIARY, 0x7FFFFFFD) // Shared object to load before self +DYNAMIC_TAG(USED, 0x7FFFFFFE) // Same as DT_NEEDED DYNAMIC_TAG(FILTER, 0x7FFFFFFF) // Shared object to get values from #ifdef DYNAMIC_TAG_MARKER_DEFINED #undef DYNAMIC_TAG_MARKER +#undef DYNAMIC_TAG_MARKER_DEFINED +#endif +#ifdef AARCH64_DYNAMIC_TAG_DEFINED +#undef AARCH64_DYNAMIC_TAG +#undef AARCH64_DYNAMIC_TAG_DEFINED #endif #ifdef MIPS_DYNAMIC_TAG_DEFINED #undef MIPS_DYNAMIC_TAG @@ -210,6 +234,10 @@ DYNAMIC_TAG(FILTER, 0x7FFFFFFF) // Shared object to get values from #undef HEXAGON_DYNAMIC_TAG #undef HEXAGON_DYNAMIC_TAG_DEFINED #endif +#ifdef PPC_DYNAMIC_TAG_DEFINED +#undef PPC_DYNAMIC_TAG +#undef PPC_DYNAMIC_TAG_DEFINED +#endif #ifdef PPC64_DYNAMIC_TAG_DEFINED #undef PPC64_DYNAMIC_TAG #undef PPC64_DYNAMIC_TAG_DEFINED diff --git a/include/llvm/BinaryFormat/ELF.h b/include/llvm/BinaryFormat/ELF.h index ce35d127d433..2bd711137845 100644 --- a/include/llvm/BinaryFormat/ELF.h +++ b/include/llvm/BinaryFormat/ELF.h @@ -1,9 +1,8 @@ //===- llvm/BinaryFormat/ELF.h - ELF constants and structures ---*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -703,15 +702,20 @@ enum : unsigned { EF_AMDGPU_MACH_AMDGCN_GFX902 = 0x02d, EF_AMDGPU_MACH_AMDGCN_GFX904 = 0x02e, EF_AMDGPU_MACH_AMDGCN_GFX906 = 0x02f, + EF_AMDGPU_MACH_AMDGCN_GFX908 = 0x030, EF_AMDGPU_MACH_AMDGCN_GFX909 = 0x031, + // AMDGCN GFX10. + EF_AMDGPU_MACH_AMDGCN_GFX1010 = 0x033, + EF_AMDGPU_MACH_AMDGCN_GFX1011 = 0x034, + EF_AMDGPU_MACH_AMDGCN_GFX1012 = 0x035, // Reserved for AMDGCN-based processors. EF_AMDGPU_MACH_AMDGCN_RESERVED0 = 0x027, - EF_AMDGPU_MACH_AMDGCN_RESERVED1 = 0x030, + EF_AMDGPU_MACH_AMDGCN_RESERVED1 = 0x032, // First/last AMDGCN-based processors. EF_AMDGPU_MACH_AMDGCN_FIRST = EF_AMDGPU_MACH_AMDGCN_GFX600, - EF_AMDGPU_MACH_AMDGCN_LAST = EF_AMDGPU_MACH_AMDGCN_GFX909, + EF_AMDGPU_MACH_AMDGCN_LAST = EF_AMDGPU_MACH_AMDGCN_GFX1012, // Indicates if the "xnack" target feature is enabled for all code contained // in the object. @@ -839,6 +843,10 @@ enum : unsigned { SHT_LLVM_CALL_GRAPH_PROFILE = 0x6fff4c02, // LLVM Call Graph Profile. SHT_LLVM_ADDRSIG = 0x6fff4c03, // List of address-significant symbols // for safe ICF. + SHT_LLVM_DEPENDENT_LIBRARIES = 0x6fff4c04, // LLVM Dependent Library Specifiers. + SHT_LLVM_SYMPART = 0x6fff4c05, // Symbol partition specification. + SHT_LLVM_PART_EHDR = 0x6fff4c06, // ELF header for loadable partition. + SHT_LLVM_PART_PHDR = 0x6fff4c07, // Phdrs for loadable partition. // Android's experimental support for SHT_RELR sections. // https://android.googlesource.com/platform/bionic/+/b7feec74547f84559a1467aca02708ff61346d2a/libc/include/elf.h#512 SHT_ANDROID_RELR = 0x6fffff00, // Relocation entries; only offsets. @@ -1340,6 +1348,14 @@ enum { NT_FREEBSD_PROCSTAT_AUXV = 16, }; +// Generic note types +enum : unsigned { + NT_VERSION = 1, + NT_ARCH = 2, + NT_GNU_BUILD_ATTRIBUTE_OPEN = 0x100, + NT_GNU_BUILD_ATTRIBUTE_FUNC = 0x101, +}; + enum { NT_GNU_ABI_TAG = 1, NT_GNU_HWCAP = 2, @@ -1352,13 +1368,65 @@ enum { enum : unsigned { GNU_PROPERTY_STACK_SIZE = 1, GNU_PROPERTY_NO_COPY_ON_PROTECTED = 2, - GNU_PROPERTY_X86_FEATURE_1_AND = 0xc0000002 + GNU_PROPERTY_AARCH64_FEATURE_1_AND = 0xc0000000, + GNU_PROPERTY_X86_FEATURE_1_AND = 0xc0000002, + GNU_PROPERTY_X86_ISA_1_NEEDED = 0xc0008000, + GNU_PROPERTY_X86_FEATURE_2_NEEDED = 0xc0008001, + GNU_PROPERTY_X86_ISA_1_USED = 0xc0010000, + GNU_PROPERTY_X86_FEATURE_2_USED = 0xc0010001, }; -// CET properties -enum { +// aarch64 processor feature bits. +enum : unsigned { + GNU_PROPERTY_AARCH64_FEATURE_1_BTI = 1 << 0, + GNU_PROPERTY_AARCH64_FEATURE_1_PAC = 1 << 1, +}; + +// x86 processor feature bits. +enum : unsigned { GNU_PROPERTY_X86_FEATURE_1_IBT = 1 << 0, - GNU_PROPERTY_X86_FEATURE_1_SHSTK = 1 << 1 + GNU_PROPERTY_X86_FEATURE_1_SHSTK = 1 << 1, + + GNU_PROPERTY_X86_ISA_1_CMOV = 1 << 0, + GNU_PROPERTY_X86_ISA_1_SSE = 1 << 1, + GNU_PROPERTY_X86_ISA_1_SSE2 = 1 << 2, + GNU_PROPERTY_X86_ISA_1_SSE3 = 1 << 3, + GNU_PROPERTY_X86_ISA_1_SSSE3 = 1 << 4, + GNU_PROPERTY_X86_ISA_1_SSE4_1 = 1 << 5, + GNU_PROPERTY_X86_ISA_1_SSE4_2 = 1 << 6, + GNU_PROPERTY_X86_ISA_1_AVX = 1 << 7, + GNU_PROPERTY_X86_ISA_1_AVX2 = 1 << 8, + GNU_PROPERTY_X86_ISA_1_FMA = 1 << 9, + GNU_PROPERTY_X86_ISA_1_AVX512F = 1 << 10, + GNU_PROPERTY_X86_ISA_1_AVX512CD = 1 << 11, + GNU_PROPERTY_X86_ISA_1_AVX512ER = 1 << 12, + GNU_PROPERTY_X86_ISA_1_AVX512PF = 1 << 13, + GNU_PROPERTY_X86_ISA_1_AVX512VL = 1 << 14, + GNU_PROPERTY_X86_ISA_1_AVX512DQ = 1 << 15, + GNU_PROPERTY_X86_ISA_1_AVX512BW = 1 << 16, + GNU_PROPERTY_X86_ISA_1_AVX512_4FMAPS = 1 << 17, + GNU_PROPERTY_X86_ISA_1_AVX512_4VNNIW = 1 << 18, + GNU_PROPERTY_X86_ISA_1_AVX512_BITALG = 1 << 19, + GNU_PROPERTY_X86_ISA_1_AVX512_IFMA = 1 << 20, + GNU_PROPERTY_X86_ISA_1_AVX512_VBMI = 1 << 21, + GNU_PROPERTY_X86_ISA_1_AVX512_VBMI2 = 1 << 22, + GNU_PROPERTY_X86_ISA_1_AVX512_VNNI = 1 << 23, + + GNU_PROPERTY_X86_FEATURE_2_X86 = 1 << 0, + GNU_PROPERTY_X86_FEATURE_2_X87 = 1 << 1, + GNU_PROPERTY_X86_FEATURE_2_MMX = 1 << 2, + GNU_PROPERTY_X86_FEATURE_2_XMM = 1 << 3, + GNU_PROPERTY_X86_FEATURE_2_YMM = 1 << 4, + GNU_PROPERTY_X86_FEATURE_2_ZMM = 1 << 5, + GNU_PROPERTY_X86_FEATURE_2_FXSR = 1 << 6, + GNU_PROPERTY_X86_FEATURE_2_XSAVE = 1 << 7, + GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT = 1 << 8, + GNU_PROPERTY_X86_FEATURE_2_XSAVEC = 1 << 9, +}; + +// AMDGPU-specific section indices. +enum { + SHN_AMDGPU_LDS = 0xff00, // Variable in LDS; symbol encoded like SHN_COMMON }; // AMD specific notes. (Code Object V2) diff --git a/include/llvm/BinaryFormat/ELFRelocs/ARM.def b/include/llvm/BinaryFormat/ELFRelocs/ARM.def index 730fc5b8836c..e0709fb81813 100644 --- a/include/llvm/BinaryFormat/ELFRelocs/ARM.def +++ b/include/llvm/BinaryFormat/ELFRelocs/ARM.def @@ -135,4 +135,7 @@ ELF_RELOC(R_ARM_PRIVATE_15, 0x7f) ELF_RELOC(R_ARM_ME_TOO, 0x80) ELF_RELOC(R_ARM_THM_TLS_DESCSEQ16, 0x81) ELF_RELOC(R_ARM_THM_TLS_DESCSEQ32, 0x82) +ELF_RELOC(R_ARM_THM_BF16, 0x88) +ELF_RELOC(R_ARM_THM_BF12, 0x89) +ELF_RELOC(R_ARM_THM_BF18, 0x8a) ELF_RELOC(R_ARM_IRELATIVE, 0xa0) diff --git a/include/llvm/BinaryFormat/ELFRelocs/PowerPC.def b/include/llvm/BinaryFormat/ELFRelocs/PowerPC.def index e4f8ee0ebe2b..28036889cca6 100644 --- a/include/llvm/BinaryFormat/ELFRelocs/PowerPC.def +++ b/include/llvm/BinaryFormat/ELFRelocs/PowerPC.def @@ -27,9 +27,25 @@ #undef R_PPC_GOT16_HI #undef R_PPC_GOT16_HA #undef R_PPC_PLTREL24 +#undef R_PPC_COPY +#undef R_PPC_GLOB_DAT #undef R_PPC_JMP_SLOT +#undef R_PPC_RELATIVE #undef R_PPC_LOCAL24PC +#undef R_PPC_UADDR32 +#undef R_PPC_UADDR16 #undef R_PPC_REL32 +#undef R_PPC_PLT32 +#undef R_PPC_PLTREL32 +#undef R_PPC_PLT16_LO +#undef R_PPC_PLT16_HI +#undef R_PPC_PLT16_HA +#undef R_PPC_SDAREL16 +#undef R_PPC_SECTOFF +#undef R_PPC_SECTOFF_LO +#undef R_PPC_SECTOFF_HI +#undef R_PPC_SECTOFF_HA +#undef R_PPC_ADDR30 #undef R_PPC_TLS #undef R_PPC_DTPMOD32 #undef R_PPC_TPREL16 @@ -84,9 +100,25 @@ ELF_RELOC(R_PPC_GOT16_LO, 15) ELF_RELOC(R_PPC_GOT16_HI, 16) ELF_RELOC(R_PPC_GOT16_HA, 17) ELF_RELOC(R_PPC_PLTREL24, 18) +ELF_RELOC(R_PPC_COPY, 19) +ELF_RELOC(R_PPC_GLOB_DAT, 20) ELF_RELOC(R_PPC_JMP_SLOT, 21) +ELF_RELOC(R_PPC_RELATIVE, 22) ELF_RELOC(R_PPC_LOCAL24PC, 23) +ELF_RELOC(R_PPC_UADDR32, 24) +ELF_RELOC(R_PPC_UADDR16, 25) ELF_RELOC(R_PPC_REL32, 26) +ELF_RELOC(R_PPC_PLT32, 27) +ELF_RELOC(R_PPC_PLTREL32, 28) +ELF_RELOC(R_PPC_PLT16_LO, 29) +ELF_RELOC(R_PPC_PLT16_HI, 30) +ELF_RELOC(R_PPC_PLT16_HA, 31) +ELF_RELOC(R_PPC_SDAREL16, 32) +ELF_RELOC(R_PPC_SECTOFF, 33) +ELF_RELOC(R_PPC_SECTOFF_LO, 34) +ELF_RELOC(R_PPC_SECTOFF_HI, 35) +ELF_RELOC(R_PPC_SECTOFF_HA, 36) +ELF_RELOC(R_PPC_ADDR30, 37) ELF_RELOC(R_PPC_TLS, 67) ELF_RELOC(R_PPC_DTPMOD32, 68) ELF_RELOC(R_PPC_TPREL16, 69) @@ -117,6 +149,7 @@ ELF_RELOC(R_PPC_GOT_DTPREL16_HI, 93) ELF_RELOC(R_PPC_GOT_DTPREL16_HA, 94) ELF_RELOC(R_PPC_TLSGD, 95) ELF_RELOC(R_PPC_TLSLD, 96) +ELF_RELOC(R_PPC_IRELATIVE, 248) ELF_RELOC(R_PPC_REL16, 249) ELF_RELOC(R_PPC_REL16_LO, 250) ELF_RELOC(R_PPC_REL16_HI, 251) diff --git a/include/llvm/BinaryFormat/MachO.def b/include/llvm/BinaryFormat/MachO.def index 95de48d2b19e..76dcc58ba048 100644 --- a/include/llvm/BinaryFormat/MachO.def +++ b/include/llvm/BinaryFormat/MachO.def @@ -1,9 +1,8 @@ //,,,-- llvm/Support/MachO.def - The MachO file definitions -----*- C++ -*-,,,// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //,,,----------------------------------------------------------------------,,,// // diff --git a/include/llvm/BinaryFormat/MachO.h b/include/llvm/BinaryFormat/MachO.h index b3d60984249f..a01393a3b303 100644 --- a/include/llvm/BinaryFormat/MachO.h +++ b/include/llvm/BinaryFormat/MachO.h @@ -1,9 +1,8 @@ //===-- llvm/BinaryFormat/MachO.h - The MachO file format -------*- C++/-*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -335,6 +334,7 @@ enum { N_WEAK_DEF = 0x0080u, N_SYMBOL_RESOLVER = 0x0100u, N_ALT_ENTRY = 0x0200u, + N_COLD_FUNC = 0x0400u, // For undefined symbols coming from libraries, see GET_LIBRARY_ORDINAL() // as these are in the top 8 bits. SELF_LIBRARY_ORDINAL = 0x0, @@ -487,6 +487,7 @@ enum PlatformType { PLATFORM_TVOS = 3, PLATFORM_WATCHOS = 4, PLATFORM_BRIDGEOS = 5, + PLATFORM_MACCATALYST = 6, PLATFORM_IOSSIMULATOR = 7, PLATFORM_TVOSSIMULATOR = 8, PLATFORM_WATCHOSSIMULATOR = 9 @@ -942,8 +943,13 @@ struct fat_arch_64 { // Structs from <mach-o/reloc.h> struct relocation_info { int32_t r_address; +#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN) + uint32_t r_type : 4, r_extern : 1, r_length : 2, r_pcrel : 1, + r_symbolnum : 24; +#else uint32_t r_symbolnum : 24, r_pcrel : 1, r_length : 2, r_extern : 1, r_type : 4; +#endif }; struct scattered_relocation_info { @@ -1396,7 +1402,8 @@ inline void SET_COMM_ALIGN(uint16_t &n_desc, uint8_t align) { enum : uint32_t { // Capability bits used in the definition of cpu_type. CPU_ARCH_MASK = 0xff000000, // Mask for architecture bits - CPU_ARCH_ABI64 = 0x01000000 // 64 bit ABI + CPU_ARCH_ABI64 = 0x01000000, // 64 bit ABI + CPU_ARCH_ABI64_32 = 0x02000000, // ILP32 ABI on 64-bit hardware }; // Constants for the cputype field. @@ -1409,6 +1416,7 @@ enum CPUType { CPU_TYPE_MC98000 = 10, // Old Motorola PowerPC CPU_TYPE_ARM = 12, CPU_TYPE_ARM64 = CPU_TYPE_ARM | CPU_ARCH_ABI64, + CPU_TYPE_ARM64_32 = CPU_TYPE_ARM | CPU_ARCH_ABI64_32, CPU_TYPE_SPARC = 14, CPU_TYPE_POWERPC = 18, CPU_TYPE_POWERPC64 = CPU_TYPE_POWERPC | CPU_ARCH_ABI64 @@ -1477,7 +1485,12 @@ enum CPUSubTypeARM { CPU_SUBTYPE_ARM_V7EM = 16 }; -enum CPUSubTypeARM64 { CPU_SUBTYPE_ARM64_ALL = 0 }; +enum CPUSubTypeARM64 { + CPU_SUBTYPE_ARM64_ALL = 0, + CPU_SUBTYPE_ARM64E = 2, +}; + +enum CPUSubTypeARM64_32 { CPU_SUBTYPE_ARM64_32_V8 = 1 }; enum CPUSubTypeSPARC { CPU_SUBTYPE_SPARC_ALL = 0 }; diff --git a/include/llvm/BinaryFormat/Magic.h b/include/llvm/BinaryFormat/Magic.h index 04801f810be3..cd9833ec4d22 100644 --- a/include/llvm/BinaryFormat/Magic.h +++ b/include/llvm/BinaryFormat/Magic.h @@ -1,9 +1,8 @@ //===- llvm/BinaryFormat/Magic.h - File magic identification ----*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -40,11 +39,14 @@ struct file_magic { macho_dsym_companion, ///< Mach-O dSYM companion file macho_kext_bundle, ///< Mach-O kext bundle file macho_universal_binary, ///< Mach-O universal binary + minidump, ///< Windows minidump file coff_cl_gl_object, ///< Microsoft cl.exe's intermediate code file coff_object, ///< COFF object file coff_import_library, ///< COFF import library pecoff_executable, ///< PECOFF executable file windows_resource, ///< Windows compiled resource file (.res) + xcoff_object_32, ///< 32-bit XCOFF object file + xcoff_object_64, ///< 64-bit XCOFF object file wasm_object, ///< WebAssembly Object file pdb, ///< Windows PDB debug info file }; diff --git a/include/llvm/BinaryFormat/Minidump.h b/include/llvm/BinaryFormat/Minidump.h new file mode 100644 index 000000000000..65c17d1eb00c --- /dev/null +++ b/include/llvm/BinaryFormat/Minidump.h @@ -0,0 +1,203 @@ +//===- Minidump.h - Minidump constants and structures -----------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// This header constants and data structures pertaining to the Windows Minidump +// core file format. +// +// Reference: +// https://msdn.microsoft.com/en-us/library/windows/desktop/ms679293(v=vs.85).aspx +// https://chromium.googlesource.com/breakpad/breakpad/ +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_BINARYFORMAT_MINIDUMP_H +#define LLVM_BINARYFORMAT_MINIDUMP_H + +#include "llvm/ADT/DenseMapInfo.h" +#include "llvm/Support/Endian.h" + +namespace llvm { +namespace minidump { + +/// The minidump header is the first part of a minidump file. It identifies the +/// file as a minidump file, and gives the location of the stream directory. +struct Header { + static constexpr uint32_t MagicSignature = 0x504d444d; // PMDM + static constexpr uint16_t MagicVersion = 0xa793; + + support::ulittle32_t Signature; + // The high 16 bits of version field are implementation specific. The low 16 + // bits should be MagicVersion. + support::ulittle32_t Version; + support::ulittle32_t NumberOfStreams; + support::ulittle32_t StreamDirectoryRVA; + support::ulittle32_t Checksum; + support::ulittle32_t TimeDateStamp; + support::ulittle64_t Flags; +}; +static_assert(sizeof(Header) == 32, ""); + +/// The type of a minidump stream identifies its contents. Streams numbers after +/// LastReserved are for application-defined data streams. +enum class StreamType : uint32_t { +#define HANDLE_MDMP_STREAM_TYPE(CODE, NAME) NAME = CODE, +#include "llvm/BinaryFormat/MinidumpConstants.def" + Unused = 0, + LastReserved = 0x0000ffff, +}; + +/// Specifies the location (and size) of various objects in the minidump file. +/// The location is relative to the start of the file. +struct LocationDescriptor { + support::ulittle32_t DataSize; + support::ulittle32_t RVA; +}; +static_assert(sizeof(LocationDescriptor) == 8, ""); + +/// Describes a single memory range (both its VM address and where to find it in +/// the file) of the process from which this minidump file was generated. +struct MemoryDescriptor { + support::ulittle64_t StartOfMemoryRange; + LocationDescriptor Memory; +}; +static_assert(sizeof(MemoryDescriptor) == 16, ""); + +/// Specifies the location and type of a single stream in the minidump file. The +/// minidump stream directory is an array of entries of this type, with its size +/// given by Header.NumberOfStreams. +struct Directory { + support::little_t<StreamType> Type; + LocationDescriptor Location; +}; +static_assert(sizeof(Directory) == 12, ""); + +/// The processor architecture of the system that generated this minidump. Used +/// in the ProcessorArch field of the SystemInfo stream. +enum class ProcessorArchitecture : uint16_t { +#define HANDLE_MDMP_ARCH(CODE, NAME) NAME = CODE, +#include "llvm/BinaryFormat/MinidumpConstants.def" +}; + +/// The OS Platform of the system that generated this minidump. Used in the +/// PlatformId field of the SystemInfo stream. +enum class OSPlatform : uint32_t { +#define HANDLE_MDMP_PLATFORM(CODE, NAME) NAME = CODE, +#include "llvm/BinaryFormat/MinidumpConstants.def" +}; + +/// Detailed information about the processor of the system that generated this +/// minidump. Its interpretation depends on the ProcessorArchitecture enum. +union CPUInfo { + struct X86Info { + char VendorID[12]; // cpuid 0: ebx, edx, ecx + support::ulittle32_t VersionInfo; // cpuid 1: eax + support::ulittle32_t FeatureInfo; // cpuid 1: edx + support::ulittle32_t AMDExtendedFeatures; // cpuid 0x80000001, ebx + } X86; + struct ArmInfo { + support::ulittle32_t CPUID; + support::ulittle32_t ElfHWCaps; // linux specific, 0 otherwise + } Arm; + struct OtherInfo { + uint8_t ProcessorFeatures[16]; + } Other; +}; +static_assert(sizeof(CPUInfo) == 24, ""); + +/// The SystemInfo stream, containing various information about the system where +/// this minidump was generated. +struct SystemInfo { + support::little_t<ProcessorArchitecture> ProcessorArch; + support::ulittle16_t ProcessorLevel; + support::ulittle16_t ProcessorRevision; + + uint8_t NumberOfProcessors; + uint8_t ProductType; + + support::ulittle32_t MajorVersion; + support::ulittle32_t MinorVersion; + support::ulittle32_t BuildNumber; + support::little_t<OSPlatform> PlatformId; + support::ulittle32_t CSDVersionRVA; + + support::ulittle16_t SuiteMask; + support::ulittle16_t Reserved; + + CPUInfo CPU; +}; +static_assert(sizeof(SystemInfo) == 56, ""); + +struct VSFixedFileInfo { + support::ulittle32_t Signature; + support::ulittle32_t StructVersion; + support::ulittle32_t FileVersionHigh; + support::ulittle32_t FileVersionLow; + support::ulittle32_t ProductVersionHigh; + support::ulittle32_t ProductVersionLow; + support::ulittle32_t FileFlagsMask; + support::ulittle32_t FileFlags; + support::ulittle32_t FileOS; + support::ulittle32_t FileType; + support::ulittle32_t FileSubtype; + support::ulittle32_t FileDateHigh; + support::ulittle32_t FileDateLow; +}; +static_assert(sizeof(VSFixedFileInfo) == 52, ""); + +inline bool operator==(const VSFixedFileInfo &LHS, const VSFixedFileInfo &RHS) { + return memcmp(&LHS, &RHS, sizeof(VSFixedFileInfo)) == 0; +} + +struct Module { + support::ulittle64_t BaseOfImage; + support::ulittle32_t SizeOfImage; + support::ulittle32_t Checksum; + support::ulittle32_t TimeDateStamp; + support::ulittle32_t ModuleNameRVA; + VSFixedFileInfo VersionInfo; + LocationDescriptor CvRecord; + LocationDescriptor MiscRecord; + support::ulittle64_t Reserved0; + support::ulittle64_t Reserved1; +}; +static_assert(sizeof(Module) == 108, ""); + +/// Describes a single thread in the minidump file. Part of the ThreadList +/// stream. +struct Thread { + support::ulittle32_t ThreadId; + support::ulittle32_t SuspendCount; + support::ulittle32_t PriorityClass; + support::ulittle32_t Priority; + support::ulittle64_t EnvironmentBlock; + MemoryDescriptor Stack; + LocationDescriptor Context; +}; +static_assert(sizeof(Thread) == 48, ""); + +} // namespace minidump + +template <> struct DenseMapInfo<minidump::StreamType> { + static minidump::StreamType getEmptyKey() { return minidump::StreamType(-1); } + + static minidump::StreamType getTombstoneKey() { + return minidump::StreamType(-2); + } + + static unsigned getHashValue(minidump::StreamType Val) { + return DenseMapInfo<uint32_t>::getHashValue(static_cast<uint32_t>(Val)); + } + + static bool isEqual(minidump::StreamType LHS, minidump::StreamType RHS) { + return LHS == RHS; + } +}; + +} // namespace llvm + +#endif // LLVM_BINARYFORMAT_MINIDUMP_H diff --git a/include/llvm/BinaryFormat/MinidumpConstants.def b/include/llvm/BinaryFormat/MinidumpConstants.def new file mode 100644 index 000000000000..d4f13dd99217 --- /dev/null +++ b/include/llvm/BinaryFormat/MinidumpConstants.def @@ -0,0 +1,107 @@ +//===- MinidumpConstants.def - Iteration over minidump constants-*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#if !(defined HANDLE_MDMP_STREAM_TYPE || defined HANDLE_MDMP_ARCH || \ + defined HANDLE_MDMP_PLATFORM) +#error "Missing HANDLE_MDMP definition" +#endif + +#ifndef HANDLE_MDMP_STREAM_TYPE +#define HANDLE_MDMP_STREAM_TYPE(CODE, NAME) +#endif + +#ifndef HANDLE_MDMP_ARCH +#define HANDLE_MDMP_ARCH(CODE, NAME) +#endif + +#ifndef HANDLE_MDMP_PLATFORM +#define HANDLE_MDMP_PLATFORM(CODE, NAME) +#endif + +HANDLE_MDMP_STREAM_TYPE(0x0003, ThreadList) +HANDLE_MDMP_STREAM_TYPE(0x0004, ModuleList) +HANDLE_MDMP_STREAM_TYPE(0x0005, MemoryList) +HANDLE_MDMP_STREAM_TYPE(0x0006, Exception) +HANDLE_MDMP_STREAM_TYPE(0x0007, SystemInfo) +HANDLE_MDMP_STREAM_TYPE(0x0008, ThreadExList) +HANDLE_MDMP_STREAM_TYPE(0x0009, Memory64List) +HANDLE_MDMP_STREAM_TYPE(0x000a, CommentA) +HANDLE_MDMP_STREAM_TYPE(0x000b, CommentW) +HANDLE_MDMP_STREAM_TYPE(0x000c, HandleData) +HANDLE_MDMP_STREAM_TYPE(0x000d, FunctionTable) +HANDLE_MDMP_STREAM_TYPE(0x000e, UnloadedModuleList) +HANDLE_MDMP_STREAM_TYPE(0x000f, MiscInfo) +HANDLE_MDMP_STREAM_TYPE(0x0010, MemoryInfoList) +HANDLE_MDMP_STREAM_TYPE(0x0011, ThreadInfoList) +HANDLE_MDMP_STREAM_TYPE(0x0012, HandleOperationList) +HANDLE_MDMP_STREAM_TYPE(0x0013, Token) +HANDLE_MDMP_STREAM_TYPE(0x0014, JavascriptData) +HANDLE_MDMP_STREAM_TYPE(0x0015, SystemMemoryInfo) +HANDLE_MDMP_STREAM_TYPE(0x0016, ProcessVMCounters) +// Breakpad extension types. 0x4767 = "Gg" +HANDLE_MDMP_STREAM_TYPE(0x47670001, BreakpadInfo) +HANDLE_MDMP_STREAM_TYPE(0x47670002, AssertionInfo) +// These are additional minidump stream values which are specific to the linux +// breakpad implementation. +HANDLE_MDMP_STREAM_TYPE(0x47670003, LinuxCPUInfo) // /proc/cpuinfo +HANDLE_MDMP_STREAM_TYPE(0x47670004, LinuxProcStatus) // /proc/$x/status +HANDLE_MDMP_STREAM_TYPE(0x47670005, LinuxLSBRelease) // /etc/lsb-release +HANDLE_MDMP_STREAM_TYPE(0x47670006, LinuxCMDLine) // /proc/$x/cmdline +HANDLE_MDMP_STREAM_TYPE(0x47670007, LinuxEnviron) // /proc/$x/environ +HANDLE_MDMP_STREAM_TYPE(0x47670008, LinuxAuxv) // /proc/$x/auxv +HANDLE_MDMP_STREAM_TYPE(0x47670009, LinuxMaps) // /proc/$x/maps +HANDLE_MDMP_STREAM_TYPE(0x4767000A, LinuxDSODebug) +HANDLE_MDMP_STREAM_TYPE(0x4767000B, LinuxProcStat) // /proc/$x/stat +HANDLE_MDMP_STREAM_TYPE(0x4767000C, LinuxProcUptime) // uptime +HANDLE_MDMP_STREAM_TYPE(0x4767000D, LinuxProcFD) // /proc/$x/fd +// Facebook-defined stream types +HANDLE_MDMP_STREAM_TYPE(0xFACE1CA7, FacebookLogcat) +HANDLE_MDMP_STREAM_TYPE(0xFACECAFA, FacebookAppCustomData) +HANDLE_MDMP_STREAM_TYPE(0xFACECAFB, FacebookBuildID) +HANDLE_MDMP_STREAM_TYPE(0xFACECAFC, FacebookAppVersionName) +HANDLE_MDMP_STREAM_TYPE(0xFACECAFD, FacebookJavaStack) +HANDLE_MDMP_STREAM_TYPE(0xFACECAFE, FacebookDalvikInfo) +HANDLE_MDMP_STREAM_TYPE(0xFACECAFF, FacebookUnwindSymbols) +HANDLE_MDMP_STREAM_TYPE(0xFACECB00, FacebookDumpErrorLog) +HANDLE_MDMP_STREAM_TYPE(0xFACECCCC, FacebookAppStateLog) +HANDLE_MDMP_STREAM_TYPE(0xFACEDEAD, FacebookAbortReason) +HANDLE_MDMP_STREAM_TYPE(0xFACEE000, FacebookThreadName) + +HANDLE_MDMP_ARCH(0x0000, X86) // PROCESSOR_ARCHITECTURE_INTEL +HANDLE_MDMP_ARCH(0x0001, MIPS) // PROCESSOR_ARCHITECTURE_MIPS +HANDLE_MDMP_ARCH(0x0002, Alpha) // PROCESSOR_ARCHITECTURE_ALPHA +HANDLE_MDMP_ARCH(0x0003, PPC) // PROCESSOR_ARCHITECTURE_PPC +HANDLE_MDMP_ARCH(0x0004, SHX) // PROCESSOR_ARCHITECTURE_SHX (Super-H) +HANDLE_MDMP_ARCH(0x0005, ARM) // PROCESSOR_ARCHITECTURE_ARM +HANDLE_MDMP_ARCH(0x0006, IA64) // PROCESSOR_ARCHITECTURE_IA64 +HANDLE_MDMP_ARCH(0x0007, Alpha64) // PROCESSOR_ARCHITECTURE_ALPHA64 +HANDLE_MDMP_ARCH(0x0008, MSIL) // PROCESSOR_ARCHITECTURE_MSIL +HANDLE_MDMP_ARCH(0x0009, AMD64) // PROCESSOR_ARCHITECTURE_AMD64 +HANDLE_MDMP_ARCH(0x000a, X86Win64) // PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 +HANDLE_MDMP_ARCH(0x8001, SPARC) // Breakpad-defined value for SPARC +HANDLE_MDMP_ARCH(0x8002, PPC64) // Breakpad-defined value for PPC64 +HANDLE_MDMP_ARCH(0x8003, ARM64) // Breakpad-defined value for ARM64 +HANDLE_MDMP_ARCH(0x8004, MIPS64) // Breakpad-defined value for MIPS64 + +HANDLE_MDMP_PLATFORM(0x0000, Win32S) // Win32 on Windows 3.1 +HANDLE_MDMP_PLATFORM(0x0001, Win32Windows) // Windows 95-98-Me +HANDLE_MDMP_PLATFORM(0x0002, Win32NT) // Windows NT, 2000+ +HANDLE_MDMP_PLATFORM(0x0003, Win32CE) // Windows CE, Windows Mobile, "Handheld" +// Breakpad-defined values. +HANDLE_MDMP_PLATFORM(0x8000, Unix) // Generic Unix-ish +HANDLE_MDMP_PLATFORM(0x8101, MacOSX) // Mac OS X/Darwin +HANDLE_MDMP_PLATFORM(0x8102, IOS) // iOS +HANDLE_MDMP_PLATFORM(0x8201, Linux) // Linux +HANDLE_MDMP_PLATFORM(0x8202, Solaris) // Solaris +HANDLE_MDMP_PLATFORM(0x8203, Android) // Android +HANDLE_MDMP_PLATFORM(0x8204, PS3) // PS3 +HANDLE_MDMP_PLATFORM(0x8205, NaCl) // Native Client (NaCl) + +#undef HANDLE_MDMP_STREAM_TYPE +#undef HANDLE_MDMP_ARCH +#undef HANDLE_MDMP_PLATFORM diff --git a/include/llvm/BinaryFormat/MsgPack.def b/include/llvm/BinaryFormat/MsgPack.def index 781b49f46aeb..7ad83ff21c42 100644 --- a/include/llvm/BinaryFormat/MsgPack.def +++ b/include/llvm/BinaryFormat/MsgPack.def @@ -1,9 +1,8 @@ //===- MsgPack.def - MessagePack definitions --------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// /// diff --git a/include/llvm/BinaryFormat/MsgPack.h b/include/llvm/BinaryFormat/MsgPack.h index d431912a53e5..9fda14b21c71 100644 --- a/include/llvm/BinaryFormat/MsgPack.h +++ b/include/llvm/BinaryFormat/MsgPack.h @@ -1,9 +1,8 @@ //===-- MsgPack.h - MessagePack Constants -----------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// /// diff --git a/include/llvm/BinaryFormat/MsgPackDocument.h b/include/llvm/BinaryFormat/MsgPackDocument.h new file mode 100644 index 000000000000..824ecc353207 --- /dev/null +++ b/include/llvm/BinaryFormat/MsgPackDocument.h @@ -0,0 +1,385 @@ +//===-- MsgPackDocument.h - MsgPack Document --------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// +/// +/// This file declares a class that exposes a simple in-memory representation +/// of a document of MsgPack objects, that can be read from MsgPack, written to +/// MsgPack, and inspected and modified in memory. This is intended to be a +/// lighter-weight (in terms of memory allocations) replacement for +/// MsgPackTypes. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_BINARYFORMAT_MSGPACKDOCUMENT_H +#define LLVM_BINARYFORMAT_MSGPACKDOCUMENT_H + +#include "llvm/BinaryFormat/MsgPackReader.h" +#include <map> + +namespace llvm { +namespace msgpack { + +class ArrayDocNode; +class Document; +class MapDocNode; + +/// The kind of a DocNode and its owning Document. +struct KindAndDocument { + Document *Doc; + Type Kind; +}; + +/// A node in a MsgPack Document. This is a simple copyable and +/// passable-by-value type that does not own any memory. +class DocNode { + friend Document; + +public: + typedef std::map<DocNode, DocNode> MapTy; + typedef std::vector<DocNode> ArrayTy; + +private: + // Using KindAndDocument allows us to squeeze Kind and a pointer to the + // owning Document into the same word. Having a pointer to the owning + // Document makes the API of DocNode more convenient, and allows its use in + // YAMLIO. + const KindAndDocument *KindAndDoc; + +protected: + // The union of different values. + union { + int64_t Int; + uint64_t UInt; + bool Bool; + double Float; + StringRef Raw; + ArrayTy *Array; + MapTy *Map; + }; + +public: + DocNode() : KindAndDoc(nullptr) {} + + // Type methods + bool isMap() const { return getKind() == Type::Map; } + bool isArray() const { return getKind() == Type::Array; } + bool isScalar() const { return !isMap() && !isArray(); } + bool isString() const { return getKind() == Type::String; } + + // Accessors + bool isEmpty() const { return !KindAndDoc; } + Type getKind() const { return KindAndDoc->Kind; } + Document *getDocument() const { return KindAndDoc->Doc; } + + int64_t &getInt() { + assert(getKind() == Type::Int); + return Int; + } + + uint64_t &getUInt() { + assert(getKind() == Type::UInt); + return UInt; + } + + bool &getBool() { + assert(getKind() == Type::Boolean); + return Bool; + } + + double &getFloat() { + assert(getKind() == Type::Float); + return Float; + } + + int64_t getInt() const { + assert(getKind() == Type::Int); + return Int; + } + + uint64_t getUInt() const { + assert(getKind() == Type::UInt); + return UInt; + } + + bool getBool() const { + assert(getKind() == Type::Boolean); + return Bool; + } + + double getFloat() const { + assert(getKind() == Type::Float); + return Float; + } + + StringRef getString() const { + assert(getKind() == Type::String); + return Raw; + } + + /// Get an ArrayDocNode for an array node. If Convert, convert the node to an + /// array node if necessary. + ArrayDocNode &getArray(bool Convert = false) { + if (getKind() != Type::Array) { + assert(Convert); + convertToArray(); + } + // This could be a static_cast, except ArrayDocNode is a forward reference. + return *reinterpret_cast<ArrayDocNode *>(this); + } + + /// Get a MapDocNode for a map node. If Convert, convert the node to a map + /// node if necessary. + MapDocNode &getMap(bool Convert = false) { + if (getKind() != Type::Map) { + assert(Convert); + convertToMap(); + } + // This could be a static_cast, except MapDocNode is a forward reference. + return *reinterpret_cast<MapDocNode *>(this); + } + + /// Comparison operator, used for map keys. + friend bool operator<(const DocNode &Lhs, const DocNode &Rhs) { + // This has to cope with one or both of the nodes being default-constructed, + // such that KindAndDoc is not set. + if (Lhs.KindAndDoc != Rhs.KindAndDoc) { + if (!Rhs.KindAndDoc) + return false; + if (!Lhs.KindAndDoc) + return true; + return (unsigned)Lhs.getKind() < (unsigned)Rhs.getKind(); + } + switch (Lhs.getKind()) { + case Type::Int: + return Lhs.Int < Rhs.Int; + case Type::UInt: + return Lhs.UInt < Rhs.UInt; + case Type::Nil: + return false; + case Type::Boolean: + return Lhs.Bool < Rhs.Bool; + case Type::Float: + return Lhs.Float < Rhs.Float; + case Type::String: + case Type::Binary: + return Lhs.Raw < Rhs.Raw; + default: + llvm_unreachable("bad map key type"); + } + } + + /// Equality operator + friend bool operator==(const DocNode &Lhs, const DocNode &Rhs) { + return !(Lhs < Rhs) && !(Rhs < Lhs); + } + + /// Convert this node to a string, assuming it is scalar. + std::string toString() const; + + /// Convert the StringRef and use it to set this DocNode (assuming scalar). If + /// it is a string, copy the string into the Document's strings list so we do + /// not rely on S having a lifetime beyond this call. Tag is "" or a YAML tag. + StringRef fromString(StringRef S, StringRef Tag = ""); + +private: + // Private constructor setting KindAndDoc, used by methods in Document. + DocNode(const KindAndDocument *KindAndDoc) : KindAndDoc(KindAndDoc) {} + + void convertToArray(); + void convertToMap(); +}; + +/// A DocNode that is a map. +class MapDocNode : public DocNode { +public: + MapDocNode() {} + MapDocNode(DocNode &N) : DocNode(N) { assert(getKind() == Type::Map); } + + // Map access methods. + size_t size() const { return Map->size(); } + bool empty() const { return !size(); } + MapTy::iterator begin() { return Map->begin(); } + MapTy::iterator end() { return Map->end(); } + MapTy::iterator find(DocNode Key) { return Map->find(Key); } + MapTy::iterator find(StringRef Key); + /// Member access. The string data must remain valid for the lifetime of the + /// Document. + DocNode &operator[](StringRef S); + /// Member access. + DocNode &operator[](DocNode Key); +}; + +/// A DocNode that is an array. +class ArrayDocNode : public DocNode { +public: + ArrayDocNode() {} + ArrayDocNode(DocNode &N) : DocNode(N) { assert(getKind() == Type::Array); } + + // Array access methods. + size_t size() const { return Array->size(); } + bool empty() const { return !size(); } + ArrayTy::iterator begin() { return Array->begin(); } + ArrayTy::iterator end() { return Array->end(); } + void push_back(DocNode N) { + assert(N.getDocument() == getDocument()); + Array->push_back(N); + } + + /// Element access. This extends the array if necessary. + DocNode &operator[](size_t Index); +}; + +/// Simple in-memory representation of a document of msgpack objects with +/// ability to find and create array and map elements. Does not currently cope +/// with any extension types. +class Document { + // Maps, arrays and strings used by nodes in the document. No attempt is made + // to free unused ones. + std::vector<std::unique_ptr<DocNode::MapTy>> Maps; + std::vector<std::unique_ptr<DocNode::ArrayTy>> Arrays; + std::vector<std::unique_ptr<char[]>> Strings; + + // The root node of the document. + DocNode Root; + + // The KindAndDocument structs pointed to by nodes in the document. + KindAndDocument KindAndDocs[size_t(Type::Extension) + 1]; + + // Whether YAML output uses hex for UInt. + bool HexMode = false; + +public: + Document() { + clear(); + for (unsigned T = 0; T != size_t(Type::Extension) + 1; ++T) + KindAndDocs[T] = {this, Type(T)}; + } + + /// Get ref to the document's root element. + DocNode &getRoot() { return Root; } + + /// Restore the Document to an empty state. + void clear() { getRoot() = getNode(); } + + /// Create a nil node associated with this Document. + DocNode getNode() { + auto N = DocNode(&KindAndDocs[size_t(Type::Nil)]); + return N; + } + + /// Create an Int node associated with this Document. + DocNode getNode(int64_t V) { + auto N = DocNode(&KindAndDocs[size_t(Type::Int)]); + N.Int = V; + return N; + } + + /// Create an Int node associated with this Document. + DocNode getNode(int V) { + auto N = DocNode(&KindAndDocs[size_t(Type::Int)]); + N.Int = V; + return N; + } + + /// Create a UInt node associated with this Document. + DocNode getNode(uint64_t V) { + auto N = DocNode(&KindAndDocs[size_t(Type::UInt)]); + N.UInt = V; + return N; + } + + /// Create a UInt node associated with this Document. + DocNode getNode(unsigned V) { + auto N = DocNode(&KindAndDocs[size_t(Type::UInt)]); + N.UInt = V; + return N; + } + + /// Create a Boolean node associated with this Document. + DocNode getNode(bool V) { + auto N = DocNode(&KindAndDocs[size_t(Type::Boolean)]); + N.Bool = V; + return N; + } + + /// Create a Float node associated with this Document. + DocNode getNode(double V) { + auto N = DocNode(&KindAndDocs[size_t(Type::Float)]); + N.Float = V; + return N; + } + + /// Create a String node associated with this Document. If !Copy, the passed + /// string must remain valid for the lifetime of the Document. + DocNode getNode(StringRef V, bool Copy = false) { + if (Copy) + V = addString(V); + auto N = DocNode(&KindAndDocs[size_t(Type::String)]); + N.Raw = V; + return N; + } + + /// Create a String node associated with this Document. If !Copy, the passed + /// string must remain valid for the lifetime of the Document. + DocNode getNode(const char *V, bool Copy = false) { + return getNode(StringRef(V), Copy); + } + + /// Create an empty Map node associated with this Document. + MapDocNode getMapNode() { + auto N = DocNode(&KindAndDocs[size_t(Type::Map)]); + Maps.push_back(std::unique_ptr<DocNode::MapTy>(new DocNode::MapTy)); + N.Map = Maps.back().get(); + return N.getMap(); + } + + /// Create an empty Array node associated with this Document. + ArrayDocNode getArrayNode() { + auto N = DocNode(&KindAndDocs[size_t(Type::Array)]); + Arrays.push_back(std::unique_ptr<DocNode::ArrayTy>(new DocNode::ArrayTy)); + N.Array = Arrays.back().get(); + return N.getArray(); + } + + /// Read a MsgPack document from a binary MsgPack blob. + /// The blob data must remain valid for the lifetime of this Document (because + /// a string object in the document contains a StringRef into the original + /// blob). + /// If Multi, then this sets root to an array and adds top-level objects to + /// it. If !Multi, then it only reads a single top-level object, even if there + /// are more, and sets root to that. + /// Returns false if failed due to illegal format. + bool readFromBlob(StringRef Blob, bool Multi); + + /// Write a MsgPack document to a binary MsgPack blob. + void writeToBlob(std::string &Blob); + + /// Copy a string into the Document's strings list, and return the copy that + /// is owned by the Document. + StringRef addString(StringRef S) { + Strings.push_back(std::unique_ptr<char[]>(new char[S.size()])); + memcpy(&Strings.back()[0], S.data(), S.size()); + return StringRef(&Strings.back()[0], S.size()); + } + + /// Set whether YAML output uses hex for UInt. Default off. + void setHexMode(bool Val = true) { HexMode = Val; } + + /// Get Hexmode flag. + bool getHexMode() const { return HexMode; } + + /// Convert MsgPack Document to YAML text. + void toYAML(raw_ostream &OS); + + /// Read YAML text into the MsgPack document. Returns false on failure. + bool fromYAML(StringRef S); +}; + +} // namespace msgpack +} // namespace llvm + +#endif // LLVM_BINARYFORMAT_MSGPACKDOCUMENT_H diff --git a/include/llvm/BinaryFormat/MsgPackReader.h b/include/llvm/BinaryFormat/MsgPackReader.h index 511c31407455..2d332f531b23 100644 --- a/include/llvm/BinaryFormat/MsgPackReader.h +++ b/include/llvm/BinaryFormat/MsgPackReader.h @@ -1,9 +1,8 @@ //===- MsgPackReader.h - Simple MsgPack reader ------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// /// diff --git a/include/llvm/BinaryFormat/MsgPackTypes.h b/include/llvm/BinaryFormat/MsgPackTypes.h deleted file mode 100644 index f96cd4c338fd..000000000000 --- a/include/llvm/BinaryFormat/MsgPackTypes.h +++ /dev/null @@ -1,372 +0,0 @@ -//===- MsgPackTypes.h - MsgPack Types ---------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -/// \file -/// This is a data structure for representing MessagePack "documents", with -/// methods to go to and from MessagePack. The types also specialize YAMLIO -/// traits in order to go to and from YAML. -// -//===----------------------------------------------------------------------===// - -#include "llvm/ADT/Optional.h" -#include "llvm/BinaryFormat/MsgPackReader.h" -#include "llvm/BinaryFormat/MsgPackWriter.h" -#include "llvm/Support/Casting.h" -#include "llvm/Support/YAMLTraits.h" -#include <vector> - -#ifndef LLVM_BINARYFORMAT_MSGPACKTYPES_H -#define LLVM_BINARYFORMAT_MSGPACKTYPES_H - -namespace llvm { -namespace msgpack { - -class Node; - -/// Short-hand for a Node pointer. -using NodePtr = std::shared_ptr<Node>; - -/// Short-hand for an Optional Node pointer. -using OptNodePtr = Optional<NodePtr>; - -/// Abstract base-class which can be any MessagePack type. -class Node { -public: - enum NodeKind { - NK_Scalar, - NK_Array, - NK_Map, - }; - -private: - virtual void anchor() = 0; - const NodeKind Kind; - - static Expected<OptNodePtr> readArray(Reader &MPReader, size_t Length); - static Expected<OptNodePtr> readMap(Reader &MPReader, size_t Length); - -public: - NodeKind getKind() const { return Kind; } - - /// Construct a Node. Used by derived classes to track kind information. - Node(NodeKind Kind) : Kind(Kind) {} - - virtual ~Node() = default; - - /// Read from a MessagePack reader \p MPReader, returning an error if one is - /// encountered, or None if \p MPReader is at the end of stream, or some Node - /// pointer if some type is read. - static Expected<OptNodePtr> read(Reader &MPReader); - - /// Write to a MessagePack writer \p MPWriter. - virtual void write(Writer &MPWriter) = 0; -}; - -/// A MessagePack scalar. -class ScalarNode : public Node { -public: - enum ScalarKind { - SK_Int, - SK_UInt, - SK_Nil, - SK_Boolean, - SK_Float, - SK_String, - SK_Binary, - }; - -private: - void anchor() override; - - void destroy(); - - ScalarKind SKind; - - union { - int64_t IntValue; - uint64_t UIntValue; - bool BoolValue; - double FloatValue; - std::string StringValue; - }; - -public: - /// Construct an Int ScalarNode. - ScalarNode(int64_t IntValue); - /// Construct an Int ScalarNode. - ScalarNode(int32_t IntValue); - /// Construct an UInt ScalarNode. - ScalarNode(uint64_t UIntValue); - /// Construct an UInt ScalarNode. - ScalarNode(uint32_t UIntValue); - /// Construct a Nil ScalarNode. - ScalarNode(); - /// Construct a Boolean ScalarNode. - ScalarNode(bool BoolValue); - /// Construct a Float ScalarNode. - ScalarNode(double FloatValue); - /// Construct a String ScalarNode. - ScalarNode(StringRef StringValue); - /// Construct a String ScalarNode. - ScalarNode(const char *StringValue); - /// Construct a String ScalarNode. - ScalarNode(std::string &&StringValue); - /// Construct a Binary ScalarNode. - ScalarNode(MemoryBufferRef BinaryValue); - - ~ScalarNode(); - - ScalarNode &operator=(const ScalarNode &RHS) = delete; - /// A ScalarNode can only be move assigned. - ScalarNode &operator=(ScalarNode &&RHS); - - /// Change the kind of this ScalarNode, zero initializing it to the new type. - void setScalarKind(ScalarKind SKind) { - switch (SKind) { - case SK_Int: - *this = int64_t(0); - break; - case SK_UInt: - *this = uint64_t(0); - break; - case SK_Boolean: - *this = false; - break; - case SK_Float: - *this = 0.0; - break; - case SK_String: - *this = StringRef(); - break; - case SK_Binary: - *this = MemoryBufferRef("", ""); - break; - case SK_Nil: - *this = ScalarNode(); - break; - } - } - - /// Get the current kind of ScalarNode. - ScalarKind getScalarKind() { return SKind; } - - /// Get the value of an Int scalar. - /// - /// \warning Assumes getScalarKind() == SK_Int - int64_t getInt() { - assert(SKind == SK_Int); - return IntValue; - } - - /// Get the value of a UInt scalar. - /// - /// \warning Assumes getScalarKind() == SK_UInt - uint64_t getUInt() { - assert(SKind == SK_UInt); - return UIntValue; - } - - /// Get the value of an Boolean scalar. - /// - /// \warning Assumes getScalarKind() == SK_Boolean - bool getBool() { - assert(SKind == SK_Boolean); - return BoolValue; - } - - /// Get the value of an Float scalar. - /// - /// \warning Assumes getScalarKind() == SK_Float - double getFloat() { - assert(SKind == SK_Float); - return FloatValue; - } - - /// Get the value of a String scalar. - /// - /// \warning Assumes getScalarKind() == SK_String - StringRef getString() { - assert(SKind == SK_String); - return StringValue; - } - - /// Get the value of a Binary scalar. - /// - /// \warning Assumes getScalarKind() == SK_Binary - StringRef getBinary() { - assert(SKind == SK_Binary); - return StringValue; - } - - static bool classof(const Node *N) { return N->getKind() == NK_Scalar; } - - void write(Writer &MPWriter) override; - - /// Parse a YAML scalar of the current ScalarKind from \p ScalarStr. - /// - /// \returns An empty string on success, otherwise an error message. - StringRef inputYAML(StringRef ScalarStr); - - /// Output a YAML scalar of the current ScalarKind into \p OS. - void outputYAML(raw_ostream &OS) const; - - /// Determine which YAML quoting type the current value would need when - /// output. - yaml::QuotingType mustQuoteYAML(StringRef ScalarStr) const; - - /// Get the YAML tag for the current ScalarKind. - StringRef getYAMLTag() const; - - /// Flag which affects how the type handles YAML tags when reading and - /// writing. - /// - /// When false, tags are used when reading and writing. When reading, the tag - /// is used to decide the ScalarKind before parsing. When writing, the tag is - /// output along with the value. - /// - /// When true, tags are ignored when reading and writing. When reading, the - /// ScalarKind is always assumed to be String. When writing, the tag is not - /// output. - bool IgnoreTag = false; - - static const char *IntTag; - static const char *NilTag; - static const char *BooleanTag; - static const char *FloatTag; - static const char *StringTag; - static const char *BinaryTag; -}; - -class ArrayNode : public Node, public std::vector<NodePtr> { - void anchor() override; - -public: - ArrayNode() : Node(NK_Array) {} - static bool classof(const Node *N) { return N->getKind() == NK_Array; } - - void write(Writer &MPWriter) override { - MPWriter.writeArraySize(this->size()); - for (auto &N : *this) - N->write(MPWriter); - } -}; - -class MapNode : public Node, public StringMap<NodePtr> { - void anchor() override; - -public: - MapNode() : Node(NK_Map) {} - static bool classof(const Node *N) { return N->getKind() == NK_Map; } - - void write(Writer &MPWriter) override { - MPWriter.writeMapSize(this->size()); - for (auto &N : *this) { - MPWriter.write(N.first()); - N.second->write(MPWriter); - } - } -}; - -} // end namespace msgpack - -namespace yaml { - -template <> struct PolymorphicTraits<msgpack::NodePtr> { - static NodeKind getKind(const msgpack::NodePtr &N) { - if (isa<msgpack::ScalarNode>(*N)) - return NodeKind::Scalar; - if (isa<msgpack::MapNode>(*N)) - return NodeKind::Map; - if (isa<msgpack::ArrayNode>(*N)) - return NodeKind::Sequence; - llvm_unreachable("NodeKind not supported"); - } - static msgpack::ScalarNode &getAsScalar(msgpack::NodePtr &N) { - if (!N || !isa<msgpack::ScalarNode>(*N)) - N.reset(new msgpack::ScalarNode()); - return *cast<msgpack::ScalarNode>(N.get()); - } - static msgpack::MapNode &getAsMap(msgpack::NodePtr &N) { - if (!N || !isa<msgpack::MapNode>(*N)) - N.reset(new msgpack::MapNode()); - return *cast<msgpack::MapNode>(N.get()); - } - static msgpack::ArrayNode &getAsSequence(msgpack::NodePtr &N) { - if (!N || !isa<msgpack::ArrayNode>(*N)) - N.reset(new msgpack::ArrayNode()); - return *cast<msgpack::ArrayNode>(N.get()); - } -}; - -template <> struct TaggedScalarTraits<msgpack::ScalarNode> { - static void output(const msgpack::ScalarNode &S, void *Ctxt, - raw_ostream &ScalarOS, raw_ostream &TagOS) { - if (!S.IgnoreTag) - TagOS << S.getYAMLTag(); - S.outputYAML(ScalarOS); - } - - static StringRef input(StringRef ScalarStr, StringRef Tag, void *Ctxt, - msgpack::ScalarNode &S) { - if (Tag == msgpack::ScalarNode::IntTag) { - S.setScalarKind(msgpack::ScalarNode::SK_UInt); - if (S.inputYAML(ScalarStr) == StringRef()) - return StringRef(); - S.setScalarKind(msgpack::ScalarNode::SK_Int); - return S.inputYAML(ScalarStr); - } - - if (S.IgnoreTag || Tag == msgpack::ScalarNode::StringTag || - Tag == "tag:yaml.org,2002:str") - S.setScalarKind(msgpack::ScalarNode::SK_String); - else if (Tag == msgpack::ScalarNode::NilTag) - S.setScalarKind(msgpack::ScalarNode::SK_Nil); - else if (Tag == msgpack::ScalarNode::BooleanTag) - S.setScalarKind(msgpack::ScalarNode::SK_Boolean); - else if (Tag == msgpack::ScalarNode::FloatTag) - S.setScalarKind(msgpack::ScalarNode::SK_Float); - else if (Tag == msgpack::ScalarNode::StringTag) - S.setScalarKind(msgpack::ScalarNode::SK_String); - else if (Tag == msgpack::ScalarNode::BinaryTag) - S.setScalarKind(msgpack::ScalarNode::SK_Binary); - else - return "Unsupported messagepack tag"; - - return S.inputYAML(ScalarStr); - } - - static QuotingType mustQuote(const msgpack::ScalarNode &S, StringRef Str) { - return S.mustQuoteYAML(Str); - } -}; - -template <> struct CustomMappingTraits<msgpack::MapNode> { - static void inputOne(IO &IO, StringRef Key, msgpack::MapNode &M) { - IO.mapRequired(Key.str().c_str(), M[Key]); - } - static void output(IO &IO, msgpack::MapNode &M) { - for (auto &N : M) - IO.mapRequired(N.getKey().str().c_str(), N.getValue()); - } -}; - -template <> struct SequenceTraits<msgpack::ArrayNode> { - static size_t size(IO &IO, msgpack::ArrayNode &A) { return A.size(); } - static msgpack::NodePtr &element(IO &IO, msgpack::ArrayNode &A, - size_t Index) { - if (Index >= A.size()) - A.resize(Index + 1); - return A[Index]; - } -}; - -} // end namespace yaml -} // end namespace llvm - -#endif // LLVM_BINARYFORMAT_MSGPACKTYPES_H diff --git a/include/llvm/BinaryFormat/MsgPackWriter.h b/include/llvm/BinaryFormat/MsgPackWriter.h index 98af422c9f19..3b610b774f77 100644 --- a/include/llvm/BinaryFormat/MsgPackWriter.h +++ b/include/llvm/BinaryFormat/MsgPackWriter.h @@ -1,9 +1,8 @@ //===- MsgPackWriter.h - Simple MsgPack writer ------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// /// diff --git a/include/llvm/BinaryFormat/Wasm.h b/include/llvm/BinaryFormat/Wasm.h index d9f0f94b298d..0f22bfe610c6 100644 --- a/include/llvm/BinaryFormat/Wasm.h +++ b/include/llvm/BinaryFormat/Wasm.h @@ -1,9 +1,8 @@ //===- Wasm.h - Wasm object file format -------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -43,6 +42,17 @@ struct WasmDylinkInfo { std::vector<StringRef> Needed; // Shared library depenedencies }; +struct WasmProducerInfo { + std::vector<std::pair<std::string, std::string>> Languages; + std::vector<std::pair<std::string, std::string>> Tools; + std::vector<std::pair<std::string, std::string>> SDKs; +}; + +struct WasmFeatureEntry { + uint8_t Prefix; + std::string Name; +}; + struct WasmExport { StringRef Name; uint8_t Kind; @@ -126,12 +136,13 @@ struct WasmFunction { }; struct WasmDataSegment { - uint32_t MemoryIndex; - WasmInitExpr Offset; + uint32_t InitFlags; + uint32_t MemoryIndex; // present if InitFlags & WASM_SEGMENT_HAS_MEMINDEX + WasmInitExpr Offset; // present if InitFlags & WASM_SEGMENT_IS_PASSIVE == 0 ArrayRef<uint8_t> Content; StringRef Name; // from the "segment info" section uint32_t Alignment; - uint32_t Flags; + uint32_t LinkerFlags; uint32_t Comdat; // from the "comdat info" section }; @@ -165,7 +176,8 @@ struct WasmSymbolInfo { StringRef Name; uint8_t Kind; uint32_t Flags; - StringRef Module; // For undefined symbols the module name of the import + StringRef ImportModule; // For undefined symbols the module of the import + StringRef ImportName; // For undefined symbols the name of the import union { // For function or global symbols, the index in function or global index // space. @@ -212,7 +224,7 @@ enum : unsigned { WASM_TYPE_F64 = 0x7C, WASM_TYPE_V128 = 0x7B, WASM_TYPE_FUNCREF = 0x70, - WASM_TYPE_EXCEPT_REF = 0x68, + WASM_TYPE_EXNREF = 0x68, WASM_TYPE_FUNC = 0x60, WASM_TYPE_NORESULT = 0x40, // for blocks with no result values }; @@ -229,11 +241,19 @@ enum : unsigned { // Opcodes used in initializer expressions. enum : unsigned { WASM_OPCODE_END = 0x0b, + WASM_OPCODE_CALL = 0x10, + WASM_OPCODE_LOCAL_GET = 0x20, WASM_OPCODE_GLOBAL_GET = 0x23, + WASM_OPCODE_GLOBAL_SET = 0x24, + WASM_OPCODE_I32_STORE = 0x36, WASM_OPCODE_I32_CONST = 0x41, WASM_OPCODE_I64_CONST = 0x42, WASM_OPCODE_F32_CONST = 0x43, WASM_OPCODE_F64_CONST = 0x44, + WASM_OPCODE_I32_ADD = 0x6a, + WASM_OPCODE_MISC_PREFIX = 0xfc, + WASM_OPCODE_MEMORY_INIT = 0x08, + WASM_OPCODE_DATA_DROP = 0x09, }; enum : unsigned { @@ -241,6 +261,18 @@ enum : unsigned { WASM_LIMITS_FLAG_IS_SHARED = 0x2, }; +enum : unsigned { + WASM_SEGMENT_IS_PASSIVE = 0x01, + WASM_SEGMENT_HAS_MEMINDEX = 0x02, +}; + +// Feature policy prefixes used in the custom "target_features" section +enum : uint8_t { + WASM_FEATURE_PREFIX_USED = '+', + WASM_FEATURE_PREFIX_REQUIRED = '=', + WASM_FEATURE_PREFIX_DISALLOWED = '-', +}; + // Kind codes used in the custom "name" section enum : unsigned { WASM_NAMES_FUNCTION = 0x1, @@ -284,6 +316,8 @@ const unsigned WASM_SYMBOL_BINDING_LOCAL = 0x2; const unsigned WASM_SYMBOL_VISIBILITY_DEFAULT = 0x0; const unsigned WASM_SYMBOL_VISIBILITY_HIDDEN = 0x4; const unsigned WASM_SYMBOL_UNDEFINED = 0x10; +const unsigned WASM_SYMBOL_EXPORTED = 0x20; +const unsigned WASM_SYMBOL_EXPLICIT_NAME = 0x40; #define WASM_RELOC(name, value) name = value, @@ -300,17 +334,17 @@ enum class ValType { F32 = WASM_TYPE_F32, F64 = WASM_TYPE_F64, V128 = WASM_TYPE_V128, - EXCEPT_REF = WASM_TYPE_EXCEPT_REF, + EXNREF = WASM_TYPE_EXNREF, }; struct WasmSignature { - SmallVector<wasm::ValType, 1> Returns; - SmallVector<wasm::ValType, 4> Params; + SmallVector<ValType, 1> Returns; + SmallVector<ValType, 4> Params; // Support empty and tombstone instances, needed by DenseMap. enum { Plain, Empty, Tombstone } State = Plain; - WasmSignature(SmallVector<wasm::ValType, 1> &&InReturns, - SmallVector<wasm::ValType, 4> &&InParams) + WasmSignature(SmallVector<ValType, 1> &&InReturns, + SmallVector<ValType, 4> &&InParams) : Returns(InReturns), Params(InParams) {} WasmSignature() = default; }; @@ -333,8 +367,9 @@ inline bool operator!=(const WasmGlobalType &LHS, const WasmGlobalType &RHS) { return !(LHS == RHS); } -std::string toString(wasm::WasmSymbolType type); +std::string toString(WasmSymbolType type); std::string relocTypetoString(uint32_t type); +bool relocTypeHasAddend(uint32_t type); } // end namespace wasm } // end namespace llvm diff --git a/include/llvm/BinaryFormat/WasmRelocs.def b/include/llvm/BinaryFormat/WasmRelocs.def index b3a08e70c1d5..00dacf72abb0 100644 --- a/include/llvm/BinaryFormat/WasmRelocs.def +++ b/include/llvm/BinaryFormat/WasmRelocs.def @@ -2,14 +2,16 @@ #error "WASM_RELOC must be defined" #endif -WASM_RELOC(R_WEBASSEMBLY_FUNCTION_INDEX_LEB, 0) -WASM_RELOC(R_WEBASSEMBLY_TABLE_INDEX_SLEB, 1) -WASM_RELOC(R_WEBASSEMBLY_TABLE_INDEX_I32, 2) -WASM_RELOC(R_WEBASSEMBLY_MEMORY_ADDR_LEB, 3) -WASM_RELOC(R_WEBASSEMBLY_MEMORY_ADDR_SLEB, 4) -WASM_RELOC(R_WEBASSEMBLY_MEMORY_ADDR_I32, 5) -WASM_RELOC(R_WEBASSEMBLY_TYPE_INDEX_LEB, 6) -WASM_RELOC(R_WEBASSEMBLY_GLOBAL_INDEX_LEB, 7) -WASM_RELOC(R_WEBASSEMBLY_FUNCTION_OFFSET_I32, 8) -WASM_RELOC(R_WEBASSEMBLY_SECTION_OFFSET_I32, 9) -WASM_RELOC(R_WEBASSEMBLY_EVENT_INDEX_LEB, 10) +WASM_RELOC(R_WASM_FUNCTION_INDEX_LEB, 0) +WASM_RELOC(R_WASM_TABLE_INDEX_SLEB, 1) +WASM_RELOC(R_WASM_TABLE_INDEX_I32, 2) +WASM_RELOC(R_WASM_MEMORY_ADDR_LEB, 3) +WASM_RELOC(R_WASM_MEMORY_ADDR_SLEB, 4) +WASM_RELOC(R_WASM_MEMORY_ADDR_I32, 5) +WASM_RELOC(R_WASM_TYPE_INDEX_LEB, 6) +WASM_RELOC(R_WASM_GLOBAL_INDEX_LEB, 7) +WASM_RELOC(R_WASM_FUNCTION_OFFSET_I32, 8) +WASM_RELOC(R_WASM_SECTION_OFFSET_I32, 9) +WASM_RELOC(R_WASM_EVENT_INDEX_LEB, 10) +WASM_RELOC(R_WASM_MEMORY_ADDR_REL_SLEB, 11) +WASM_RELOC(R_WASM_TABLE_INDEX_REL_SLEB, 12) diff --git a/include/llvm/BinaryFormat/XCOFF.h b/include/llvm/BinaryFormat/XCOFF.h new file mode 100644 index 000000000000..7774ab3ed24a --- /dev/null +++ b/include/llvm/BinaryFormat/XCOFF.h @@ -0,0 +1,145 @@ +//===-- llvm/BinaryFormat/XCOFF.h - The XCOFF file format -------*- C++/-*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// This file defines manifest constants for the XCOFF object file format. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_BINARYFORMAT_XCOFF_H +#define LLVM_BINARYFORMAT_XCOFF_H + +#include <cstdint> + +namespace llvm { +namespace XCOFF { + +// Constants used in the XCOFF definition. +enum { SectionNameSize = 8, SymbolNameSize = 8 }; +enum ReservedSectionNum { N_DEBUG = -2, N_ABS = -1, N_UNDEF = 0 }; + +// x_smclas field of x_csect from system header: /usr/include/syms.h +/// Storage Mapping Class definitions. +enum StorageMappingClass { + // READ ONLY CLASSES + XMC_PR = 0, ///< Program Code + XMC_RO = 1, ///< Read Only Constant + XMC_DB = 2, ///< Debug Dictionary Table + XMC_GL = 6, ///< Global Linkage (Interfile Interface Code) + XMC_XO = 7, ///< Extended Operation (Pseudo Machine Instruction) + XMC_SV = 8, ///< Supervisor Call (32-bit process only) + XMC_SV64 = 17, ///< Supervisor Call for 64-bit process + XMC_SV3264 = 18, ///< Supervisor Call for both 32- and 64-bit processes + XMC_TI = 12, ///< Traceback Index csect + XMC_TB = 13, ///< Traceback Table csect + + // READ WRITE CLASSES + XMC_RW = 5, ///< Read Write Data + XMC_TC0 = 15, ///< TOC Anchor for TOC Addressability + XMC_TC = 3, ///< General TOC item + XMC_TD = 16, ///< Scalar data item in the TOC + XMC_DS = 10, ///< Descriptor csect + XMC_UA = 4, ///< Unclassified - Treated as Read Write + XMC_BS = 9, ///< BSS class (uninitialized static internal) + XMC_UC = 11, ///< Un-named Fortran Common + + XMC_TL = 20, ///< Initialized thread-local variable + XMC_UL = 21, ///< Uninitialized thread-local variable + XMC_TE = 22 ///< Symbol mapped at the end of TOC +}; + +// Flags for defining the section type. Used for the s_flags field of +// the section header structure. Defined in the system header `scnhdr.h`. +enum SectionTypeFlags { + STYP_PAD = 0x0008, + STYP_DWARF = 0x0010, + STYP_TEXT = 0x0020, + STYP_DATA = 0x0040, + STYP_BSS = 0x0080, + STYP_EXCEPT = 0x0100, + STYP_INFO = 0x0200, + STYP_TDATA = 0x0400, + STYP_TBSS = 0x0800, + STYP_LOADER = 0x1000, + STYP_DEBUG = 0x2000, + STYP_TYPCHK = 0x4000, + STYP_OVRFLO = 0x8000 +}; + +// STORAGE CLASSES, n_sclass field of syment. +// The values come from `storclass.h` and `dbxstclass.h`. +enum StorageClass : uint8_t { + // Storage classes used for symbolic debugging symbols. + C_FILE = 103, // File name + C_BINCL = 108, // Beginning of include file + C_EINCL = 109, // Ending of include file + C_GSYM = 128, // Global variable + C_STSYM = 133, // Statically allocated symbol + C_BCOMM = 135, // Beginning of common block + C_ECOMM = 137, // End of common block + C_ENTRY = 141, // Alternate entry + C_BSTAT = 143, // Beginning of static block + C_ESTAT = 144, // End of static block + C_GTLS = 145, // Global thread-local variable + C_STTLS = 146, // Static thread-local variable + + // Storage classes used for DWARF symbols. + C_DWARF = 112, // DWARF section symbol + + // Storage classes used for absolute symbols. + C_LSYM = 129, // Automatic variable allocated on stack + C_PSYM = 130, // Argument to subroutine allocated on stack + C_RSYM = 131, // Register variable + C_RPSYM = 132, // Argument to function or procedure stored in register + C_ECOML = 136, // Local member of common block + C_FUN = 142, // Function or procedure + + // Storage classes used for undefined external symbols or + // symbols of general sections. + C_EXT = 2, // External symbol + C_WEAKEXT = 111, // Weak external symbol + + // Storage classes used for symbols of general sections. + C_NULL = 0, + C_STAT = 3, // Static + C_BLOCK = 100, // ".bb" or ".eb" + C_FCN = 101, // ".bf" or ".ef" + C_HIDEXT = 107, // Un-named external symbol + C_INFO = 110, // Comment string in .info section + C_DECL = 140, // Declaration of object (type) + + // Storage classes - Obsolete/Undocumented. + C_AUTO = 1, // Automatic variable + C_REG = 4, // Register variable + C_EXTDEF = 5, // External definition + C_LABEL = 6, // Label + C_ULABEL = 7, // Undefined label + C_MOS = 8, // Member of structure + C_ARG = 9, // Function argument + C_STRTAG = 10, // Structure tag + C_MOU = 11, // Member of union + C_UNTAG = 12, // Union tag + C_TPDEF = 13, // Type definition + C_USTATIC = 14, // Undefined static + C_ENTAG = 15, // Enumeration tag + C_MOE = 16, // Member of enumeration + C_REGPARM = 17, // Register parameter + C_FIELD = 18, // Bit field + C_EOS = 102, // End of structure + C_LINE = 104, + C_ALIAS = 105, // Duplicate tag + C_HIDDEN = 106, // Special storage class for external + C_EFCN = 255, // Physical end of function + + // Storage classes - reserved + C_TCSYM = 134 // Reserved +}; + +} // end namespace XCOFF +} // end namespace llvm + +#endif |