diff options
Diffstat (limited to 'include/llvm/ObjectYAML')
-rw-r--r-- | include/llvm/ObjectYAML/DWARFYAML.h | 2 | ||||
-rw-r--r-- | include/llvm/ObjectYAML/ELFYAML.h | 116 | ||||
-rw-r--r-- | include/llvm/ObjectYAML/MachOYAML.h | 3 | ||||
-rw-r--r-- | include/llvm/ObjectYAML/MinidumpYAML.h | 64 | ||||
-rw-r--r-- | include/llvm/ObjectYAML/WasmYAML.h | 2 | ||||
-rw-r--r-- | include/llvm/ObjectYAML/yaml2obj.h | 67 |
6 files changed, 222 insertions, 32 deletions
diff --git a/include/llvm/ObjectYAML/DWARFYAML.h b/include/llvm/ObjectYAML/DWARFYAML.h index 78d736c3ef05..525fd9a89242 100644 --- a/include/llvm/ObjectYAML/DWARFYAML.h +++ b/include/llvm/ObjectYAML/DWARFYAML.h @@ -234,7 +234,7 @@ template <> struct MappingTraits<DWARFYAML::InitialLength> { static void mapping(IO &IO, DWARFYAML::InitialLength &DWARF); }; -#define HANDLE_DW_TAG(unused, name, unused2, unused3) \ +#define HANDLE_DW_TAG(unused, name, unused2, unused3, unused4) \ io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name); template <> struct ScalarEnumerationTraits<dwarf::Tag> { diff --git a/include/llvm/ObjectYAML/ELFYAML.h b/include/llvm/ObjectYAML/ELFYAML.h index f4212516f486..0898a0e7d532 100644 --- a/include/llvm/ObjectYAML/ELFYAML.h +++ b/include/llvm/ObjectYAML/ELFYAML.h @@ -25,6 +25,8 @@ namespace llvm { namespace ELFYAML { +StringRef dropUniqueSuffix(StringRef S); + // These types are invariant across 32/64-bit ELF, so for simplicity just // directly give them their exact sizes. We don't need to worry about // endianness because these are just the types in the YAMLIO structures, @@ -54,8 +56,6 @@ LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF) LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_SHN) LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STB) LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT) -LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STV) -LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STO) LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG) LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP) @@ -77,7 +77,7 @@ struct FileHeader { llvm::yaml::Hex64 Entry; Optional<llvm::yaml::Hex16> SHEntSize; - Optional<llvm::yaml::Hex16> SHOffset; + Optional<llvm::yaml::Hex64> SHOff; Optional<llvm::yaml::Hex16> SHNum; Optional<llvm::yaml::Hex16> SHStrNdx; }; @@ -107,7 +107,7 @@ struct Symbol { ELF_STB Binding; llvm::yaml::Hex64 Value; llvm::yaml::Hex64 Size; - uint8_t Other; + Optional<uint8_t> Other; }; struct SectionOrType { @@ -119,6 +119,11 @@ struct DynamicEntry { llvm::yaml::Hex64 Val; }; +struct StackSizeEntry { + llvm::yaml::Hex64 Address; + llvm::yaml::Hex64 Size; +}; + struct Section { enum class SectionKind { Dynamic, @@ -126,10 +131,14 @@ struct Section { RawContent, Relocation, NoBits, + Hash, Verdef, Verneed, + StackSizes, + SymtabShndxSection, Symver, - MipsABIFlags + MipsABIFlags, + Addrsig }; SectionKind Kind; StringRef Name; @@ -140,16 +149,44 @@ struct Section { llvm::yaml::Hex64 AddressAlign; Optional<llvm::yaml::Hex64> EntSize; + // Usually sections are not created implicitly, but loaded from YAML. + // When they are, this flag is used to signal about that. + bool IsImplicit; + + Section(SectionKind Kind, bool IsImplicit = false) + : Kind(Kind), IsImplicit(IsImplicit) {} + virtual ~Section(); + + // The following members are used to override section fields which is + // useful for creating invalid objects. + + // This can be used to override the offset stored in the sh_name field. + // It does not affect the name stored in the string table. + Optional<llvm::yaml::Hex64> ShName; + // This can be used to override the sh_offset field. It does not place the - // section data at the offset specified. Useful for creating invalid objects. + // section data at the offset specified. Optional<llvm::yaml::Hex64> ShOffset; // This can be used to override the sh_size field. It does not affect the // content written. Optional<llvm::yaml::Hex64> ShSize; +}; - Section(SectionKind Kind) : Kind(Kind) {} - virtual ~Section(); +struct StackSizesSection : Section { + Optional<yaml::BinaryRef> Content; + Optional<llvm::yaml::Hex64> Size; + Optional<std::vector<StackSizeEntry>> Entries; + + StackSizesSection() : Section(SectionKind::StackSizes) {} + + static bool classof(const Section *S) { + return S->Kind == SectionKind::StackSizes; + } + + static bool nameMatches(StringRef Name) { + return Name == ".stack_sizes"; + } }; struct DynamicSection : Section { @@ -185,6 +222,17 @@ struct NoBitsSection : Section { } }; +struct HashSection : Section { + Optional<yaml::BinaryRef> Content; + Optional<llvm::yaml::Hex64> Size; + Optional<std::vector<uint32_t>> Bucket; + Optional<std::vector<uint32_t>> Chain; + + HashSection() : Section(SectionKind::Hash) {} + + static bool classof(const Section *S) { return S->Kind == SectionKind::Hash; } +}; + struct VernauxEntry { uint32_t Hash; uint16_t Flags; @@ -209,6 +257,26 @@ struct VerneedSection : Section { } }; +struct AddrsigSymbol { + AddrsigSymbol(StringRef N) : Name(N), Index(None) {} + AddrsigSymbol(llvm::yaml::Hex32 Ndx) : Name(None), Index(Ndx) {} + AddrsigSymbol() : Name(None), Index(None) {} + + Optional<StringRef> Name; + Optional<llvm::yaml::Hex32> Index; +}; + +struct AddrsigSection : Section { + Optional<yaml::BinaryRef> Content; + Optional<llvm::yaml::Hex64> Size; + Optional<std::vector<AddrsigSymbol>> Symbols; + + AddrsigSection() : Section(SectionKind::Addrsig) {} + static bool classof(const Section *S) { + return S->Kind == SectionKind::Addrsig; + } +}; + struct SymverSection : Section { std::vector<uint16_t> Entries; @@ -269,6 +337,16 @@ struct RelocationSection : Section { } }; +struct SymtabShndxSection : Section { + std::vector<uint32_t> Entries; + + SymtabShndxSection() : Section(SectionKind::SymtabShndxSection) {} + + static bool classof(const Section *S) { + return S->Kind == SectionKind::SymtabShndxSection; + } +}; + // Represents .MIPS.abiflags section struct MipsABIFlags : Section { llvm::yaml::Hex16 Version; @@ -298,13 +376,15 @@ struct Object { // cleaner and nicer if we read them from the YAML as a separate // top-level key, which automatically ensures that invariants like there // being a single SHT_SYMTAB section are upheld. - std::vector<Symbol> Symbols; + Optional<std::vector<Symbol>> Symbols; std::vector<Symbol> DynamicSymbols; }; } // end namespace ELFYAML } // end namespace llvm +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::AddrsigSymbol) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::StackSizeEntry) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::DynamicEntry) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::ProgramHeader) LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::ELFYAML::Section>) @@ -381,16 +461,6 @@ struct ScalarEnumerationTraits<ELFYAML::ELF_STT> { }; template <> -struct ScalarEnumerationTraits<ELFYAML::ELF_STV> { - static void enumeration(IO &IO, ELFYAML::ELF_STV &Value); -}; - -template <> -struct ScalarBitSetTraits<ELFYAML::ELF_STO> { - static void bitset(IO &IO, ELFYAML::ELF_STO &Value); -}; - -template <> struct ScalarEnumerationTraits<ELFYAML::ELF_REL> { static void enumeration(IO &IO, ELFYAML::ELF_REL &Value); }; @@ -450,6 +520,10 @@ struct MappingTraits<ELFYAML::Symbol> { static StringRef validate(IO &IO, ELFYAML::Symbol &Symbol); }; +template <> struct MappingTraits<ELFYAML::StackSizeEntry> { + static void mapping(IO &IO, ELFYAML::StackSizeEntry &Rel); +}; + template <> struct MappingTraits<ELFYAML::DynamicEntry> { static void mapping(IO &IO, ELFYAML::DynamicEntry &Rel); }; @@ -466,6 +540,10 @@ template <> struct MappingTraits<ELFYAML::VernauxEntry> { static void mapping(IO &IO, ELFYAML::VernauxEntry &E); }; +template <> struct MappingTraits<ELFYAML::AddrsigSymbol> { + static void mapping(IO &IO, ELFYAML::AddrsigSymbol &Sym); +}; + template <> struct MappingTraits<ELFYAML::Relocation> { static void mapping(IO &IO, ELFYAML::Relocation &Rel); }; diff --git a/include/llvm/ObjectYAML/MachOYAML.h b/include/llvm/ObjectYAML/MachOYAML.h index d7e1c033f43b..327c3b9f892b 100644 --- a/include/llvm/ObjectYAML/MachOYAML.h +++ b/include/llvm/ObjectYAML/MachOYAML.h @@ -18,6 +18,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/ObjectYAML/DWARFYAML.h" +#include "llvm/ObjectYAML/YAML.h" #include "llvm/Support/YAMLTraits.h" #include <cstdint> #include <string> @@ -39,6 +40,7 @@ struct Section { llvm::yaml::Hex32 reserved1; llvm::yaml::Hex32 reserved2; llvm::yaml::Hex32 reserved3; + Optional<llvm::yaml::BinaryRef> content; }; struct FileHeader { @@ -198,6 +200,7 @@ template <> struct MappingTraits<MachOYAML::ExportEntry> { template <> struct MappingTraits<MachOYAML::Section> { static void mapping(IO &IO, MachOYAML::Section &Section); + static StringRef validate(IO &io, MachOYAML::Section &Section); }; template <> struct MappingTraits<MachOYAML::NListEntry> { diff --git a/include/llvm/ObjectYAML/MinidumpYAML.h b/include/llvm/ObjectYAML/MinidumpYAML.h index 39fdd62e017b..c1711a28dd84 100644 --- a/include/llvm/ObjectYAML/MinidumpYAML.h +++ b/include/llvm/ObjectYAML/MinidumpYAML.h @@ -26,6 +26,8 @@ namespace MinidumpYAML { /// from Types to Kinds is fixed and given by the static getKind function. struct Stream { enum class StreamKind { + Exception, + MemoryInfoList, MemoryList, ModuleList, RawContent, @@ -102,6 +104,45 @@ using ModuleListStream = detail::ListStream<detail::ParsedModule>; using ThreadListStream = detail::ListStream<detail::ParsedThread>; using MemoryListStream = detail::ListStream<detail::ParsedMemoryDescriptor>; +/// ExceptionStream minidump stream. +struct ExceptionStream : public Stream { + minidump::ExceptionStream MDExceptionStream; + yaml::BinaryRef ThreadContext; + + ExceptionStream() + : Stream(StreamKind::Exception, minidump::StreamType::Exception), + MDExceptionStream({}) {} + + explicit ExceptionStream(const minidump::ExceptionStream &MDExceptionStream, + ArrayRef<uint8_t> ThreadContext) + : Stream(StreamKind::Exception, minidump::StreamType::Exception), + MDExceptionStream(MDExceptionStream), ThreadContext(ThreadContext) {} + + static bool classof(const Stream *S) { + return S->Kind == StreamKind::Exception; + } +}; + +/// A structure containing the list of MemoryInfo entries comprising a +/// MemoryInfoList stream. +struct MemoryInfoListStream : public Stream { + std::vector<minidump::MemoryInfo> Infos; + + MemoryInfoListStream() + : Stream(StreamKind::MemoryInfoList, + minidump::StreamType::MemoryInfoList) {} + + explicit MemoryInfoListStream( + iterator_range<object::MinidumpFile::MemoryInfoIterator> Range) + : Stream(StreamKind::MemoryInfoList, + minidump::StreamType::MemoryInfoList), + Infos(Range.begin(), Range.end()) {} + + static bool classof(const Stream *S) { + return S->Kind == StreamKind::MemoryInfoList; + } +}; + /// A minidump stream represented as a sequence of hex bytes. This is used as a /// fallback when no other stream kind is suitable. struct RawContentStream : public Stream { @@ -122,16 +163,16 @@ struct SystemInfoStream : public Stream { minidump::SystemInfo Info; std::string CSDVersion; - explicit SystemInfoStream(const minidump::SystemInfo &Info, - std::string CSDVersion) - : Stream(StreamKind::SystemInfo, minidump::StreamType::SystemInfo), - Info(Info), CSDVersion(std::move(CSDVersion)) {} - SystemInfoStream() : Stream(StreamKind::SystemInfo, minidump::StreamType::SystemInfo) { memset(&Info, 0, sizeof(Info)); } + explicit SystemInfoStream(const minidump::SystemInfo &Info, + std::string CSDVersion) + : Stream(StreamKind::SystemInfo, minidump::StreamType::SystemInfo), + Info(Info), CSDVersion(std::move(CSDVersion)) {} + static bool classof(const Stream *S) { return S->Kind == StreamKind::SystemInfo; } @@ -177,12 +218,6 @@ struct Object { static Expected<Object> create(const object::MinidumpFile &File); }; -/// Serialize the minidump file represented by Obj to OS in binary form. -void writeAsBinary(Object &Obj, raw_ostream &OS); - -/// Serialize the yaml string as a minidump file to OS in binary form. -Error writeAsBinary(StringRef Yaml, raw_ostream &OS); - } // namespace MinidumpYAML namespace yaml { @@ -213,6 +248,10 @@ template <> struct MappingContextTraits<minidump::MemoryDescriptor, BinaryRef> { } // namespace llvm +LLVM_YAML_DECLARE_BITSET_TRAITS(llvm::minidump::MemoryProtection) +LLVM_YAML_DECLARE_BITSET_TRAITS(llvm::minidump::MemoryState) +LLVM_YAML_DECLARE_BITSET_TRAITS(llvm::minidump::MemoryType) + LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::minidump::ProcessorArchitecture) LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::minidump::OSPlatform) LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::minidump::StreamType) @@ -220,6 +259,8 @@ LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::minidump::StreamType) LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::CPUInfo::ArmInfo) LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::CPUInfo::OtherInfo) LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::CPUInfo::X86Info) +LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::Exception) +LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::MemoryInfo) LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::VSFixedFileInfo) LLVM_YAML_DECLARE_MAPPING_TRAITS( @@ -233,6 +274,7 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::MinidumpYAML::Stream>) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MinidumpYAML::MemoryListStream::entry_type) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MinidumpYAML::ModuleListStream::entry_type) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MinidumpYAML::ThreadListStream::entry_type) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::minidump::MemoryInfo) LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::MinidumpYAML::Object) diff --git a/include/llvm/ObjectYAML/WasmYAML.h b/include/llvm/ObjectYAML/WasmYAML.h index 2411dc7ac17d..15a8cc215020 100644 --- a/include/llvm/ObjectYAML/WasmYAML.h +++ b/include/llvm/ObjectYAML/WasmYAML.h @@ -145,7 +145,7 @@ struct Signature { uint32_t Index; SignatureForm Form = wasm::WASM_TYPE_FUNC; std::vector<ValueType> ParamTypes; - ValueType ReturnType; + std::vector<ValueType> ReturnTypes; }; struct SymbolInfo { diff --git a/include/llvm/ObjectYAML/yaml2obj.h b/include/llvm/ObjectYAML/yaml2obj.h new file mode 100644 index 000000000000..386551337d86 --- /dev/null +++ b/include/llvm/ObjectYAML/yaml2obj.h @@ -0,0 +1,67 @@ +//===--- yaml2obj.h - -------------------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +/// \file +/// Common declarations for yaml2obj +//===----------------------------------------------------------------------===// +#ifndef LLVM_TOOLS_YAML2OBJ_YAML2OBJ_H +#define LLVM_TOOLS_YAML2OBJ_YAML2OBJ_H + +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Error.h" +#include <memory> + +namespace llvm { +class raw_ostream; +template <typename T> class SmallVectorImpl; +template <typename T> class Expected; + +namespace object { +class ObjectFile; +} + +namespace COFFYAML { +struct Object; +} + +namespace ELFYAML { +struct Object; +} + +namespace MinidumpYAML { +struct Object; +} + +namespace WasmYAML { +struct Object; +} + +namespace yaml { +class Input; +struct YamlObjectFile; + +using ErrorHandler = llvm::function_ref<void(const Twine &Msg)>; + +bool yaml2coff(COFFYAML::Object &Doc, raw_ostream &Out, ErrorHandler EH); +bool yaml2elf(ELFYAML::Object &Doc, raw_ostream &Out, ErrorHandler EH); +bool yaml2macho(YamlObjectFile &Doc, raw_ostream &Out, ErrorHandler EH); +bool yaml2minidump(MinidumpYAML::Object &Doc, raw_ostream &Out, + ErrorHandler EH); +bool yaml2wasm(WasmYAML::Object &Doc, raw_ostream &Out, ErrorHandler EH); + +bool convertYAML(Input &YIn, raw_ostream &Out, ErrorHandler ErrHandler, + unsigned DocNum = 1); + +/// Convenience function for tests. +std::unique_ptr<object::ObjectFile> +yaml2ObjectFile(SmallVectorImpl<char> &Storage, StringRef Yaml, + ErrorHandler ErrHandler); + +} // namespace yaml +} // namespace llvm + +#endif |