Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- ELFYAML.h - ELF YAMLIO implementation --------------------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 10 | /// This file declares classes for handling the YAML representation |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 11 | /// of ELF. |
| 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_OBJECTYAML_ELFYAML_H |
| 16 | #define LLVM_OBJECTYAML_ELFYAML_H |
| 17 | |
| 18 | #include "llvm/ADT/StringRef.h" |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 19 | #include "llvm/BinaryFormat/ELF.h" |
| 20 | #include "llvm/Object/ELFTypes.h" |
| 21 | #include "llvm/ObjectYAML/DWARFYAML.h" |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 22 | #include "llvm/ObjectYAML/YAML.h" |
| 23 | #include "llvm/Support/YAMLTraits.h" |
| 24 | #include <cstdint> |
| 25 | #include <memory> |
| 26 | #include <vector> |
| 27 | |
| 28 | namespace llvm { |
| 29 | namespace ELFYAML { |
| 30 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 31 | StringRef dropUniqueSuffix(StringRef S); |
| 32 | std::string appendUniqueSuffix(StringRef Name, const Twine& Msg); |
| 33 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 34 | // These types are invariant across 32/64-bit ELF, so for simplicity just |
| 35 | // directly give them their exact sizes. We don't need to worry about |
| 36 | // endianness because these are just the types in the YAMLIO structures, |
| 37 | // and are appropriately converted to the necessary endianness when |
| 38 | // reading/generating binary object files. |
| 39 | // The naming of these types is intended to be ELF_PREFIX, where PREFIX is |
| 40 | // the common prefix of the respective constants. E.g. ELF_EM corresponds |
| 41 | // to the `e_machine` constants, like `EM_X86_64`. |
| 42 | // In the future, these would probably be better suited by C++11 enum |
| 43 | // class's with appropriate fixed underlying type. |
| 44 | LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_ET) |
| 45 | LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_PT) |
| 46 | LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_EM) |
| 47 | LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFCLASS) |
| 48 | LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFDATA) |
| 49 | LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFOSABI) |
| 50 | // Just use 64, since it can hold 32-bit values too. |
| 51 | LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_EF) |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 52 | // Just use 64, since it can hold 32-bit values too. |
| 53 | LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_DYNTAG) |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 54 | LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_PF) |
| 55 | LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT) |
| 56 | LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_REL) |
| 57 | LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_RSS) |
| 58 | // Just use 64, since it can hold 32-bit values too. |
| 59 | LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF) |
| 60 | LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_SHN) |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 61 | LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STB) |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 62 | LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT) |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 63 | |
| 64 | LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG) |
| 65 | LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP) |
| 66 | LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT) |
| 67 | LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE) |
| 68 | LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1) |
| 69 | LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_ISA) |
| 70 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 71 | LLVM_YAML_STRONG_TYPEDEF(StringRef, YAMLFlowString) |
| 72 | LLVM_YAML_STRONG_TYPEDEF(int64_t, YAMLIntUInt) |
| 73 | |
| 74 | template <class ELFT> |
| 75 | unsigned getDefaultShEntSize(unsigned EMachine, ELF_SHT SecType, |
| 76 | StringRef SecName) { |
| 77 | if (EMachine == ELF::EM_MIPS && SecType == ELF::SHT_MIPS_ABIFLAGS) |
| 78 | return sizeof(object::Elf_Mips_ABIFlags<ELFT>); |
| 79 | |
| 80 | switch (SecType) { |
| 81 | case ELF::SHT_GROUP: |
| 82 | return sizeof(typename ELFT::Word); |
| 83 | case ELF::SHT_REL: |
| 84 | return sizeof(typename ELFT::Rel); |
| 85 | case ELF::SHT_RELA: |
| 86 | return sizeof(typename ELFT::Rela); |
| 87 | case ELF::SHT_RELR: |
| 88 | return sizeof(typename ELFT::Relr); |
| 89 | case ELF::SHT_DYNAMIC: |
| 90 | return sizeof(typename ELFT::Dyn); |
| 91 | case ELF::SHT_HASH: |
| 92 | return sizeof(typename ELFT::Word); |
| 93 | case ELF::SHT_SYMTAB_SHNDX: |
| 94 | return sizeof(typename ELFT::Word); |
| 95 | case ELF::SHT_GNU_versym: |
| 96 | return sizeof(typename ELFT::Half); |
| 97 | case ELF::SHT_LLVM_CALL_GRAPH_PROFILE: |
| 98 | return sizeof(object::Elf_CGProfile_Impl<ELFT>); |
| 99 | default: |
| 100 | if (SecName == ".debug_str") |
| 101 | return 1; |
| 102 | return 0; |
| 103 | } |
| 104 | } |
| 105 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 106 | // For now, hardcode 64 bits everywhere that 32 or 64 would be needed |
| 107 | // since 64-bit can hold 32-bit values too. |
| 108 | struct FileHeader { |
| 109 | ELF_ELFCLASS Class; |
| 110 | ELF_ELFDATA Data; |
| 111 | ELF_ELFOSABI OSABI; |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 112 | llvm::yaml::Hex8 ABIVersion; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 113 | ELF_ET Type; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 114 | Optional<ELF_EM> Machine; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 115 | ELF_EF Flags; |
| 116 | llvm::yaml::Hex64 Entry; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 117 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 118 | Optional<llvm::yaml::Hex64> EPhOff; |
| 119 | Optional<llvm::yaml::Hex16> EPhEntSize; |
| 120 | Optional<llvm::yaml::Hex16> EPhNum; |
| 121 | Optional<llvm::yaml::Hex16> EShEntSize; |
| 122 | Optional<llvm::yaml::Hex64> EShOff; |
| 123 | Optional<llvm::yaml::Hex16> EShNum; |
| 124 | Optional<llvm::yaml::Hex16> EShStrNdx; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 125 | }; |
| 126 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 127 | struct SectionHeader { |
| 128 | StringRef Name; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 129 | }; |
| 130 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 131 | struct SectionHeaderTable { |
| 132 | Optional<std::vector<SectionHeader>> Sections; |
| 133 | Optional<std::vector<SectionHeader>> Excluded; |
| 134 | Optional<bool> NoHeaders; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | struct Symbol { |
| 138 | StringRef Name; |
| 139 | ELF_STT Type; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 140 | Optional<StringRef> Section; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 141 | Optional<ELF_SHN> Index; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 142 | ELF_STB Binding; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 143 | Optional<llvm::yaml::Hex64> Value; |
| 144 | Optional<llvm::yaml::Hex64> Size; |
| 145 | Optional<uint8_t> Other; |
| 146 | |
| 147 | Optional<uint32_t> StName; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 148 | }; |
| 149 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 150 | struct SectionOrType { |
| 151 | StringRef sectionNameOrType; |
| 152 | }; |
| 153 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 154 | struct DynamicEntry { |
| 155 | ELF_DYNTAG Tag; |
| 156 | llvm::yaml::Hex64 Val; |
| 157 | }; |
| 158 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 159 | struct BBAddrMapEntry { |
| 160 | struct BBEntry { |
| 161 | llvm::yaml::Hex32 AddressOffset; |
| 162 | llvm::yaml::Hex32 Size; |
| 163 | llvm::yaml::Hex32 Metadata; |
| 164 | }; |
| 165 | llvm::yaml::Hex64 Address; |
| 166 | Optional<std::vector<BBEntry>> BBEntries; |
| 167 | }; |
| 168 | |
| 169 | struct StackSizeEntry { |
| 170 | llvm::yaml::Hex64 Address; |
| 171 | llvm::yaml::Hex64 Size; |
| 172 | }; |
| 173 | |
| 174 | struct NoteEntry { |
| 175 | StringRef Name; |
| 176 | yaml::BinaryRef Desc; |
| 177 | llvm::yaml::Hex32 Type; |
| 178 | }; |
| 179 | |
| 180 | struct Chunk { |
| 181 | enum class ChunkKind { |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 182 | Dynamic, |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 183 | Group, |
| 184 | RawContent, |
| 185 | Relocation, |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 186 | Relr, |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 187 | NoBits, |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 188 | Note, |
| 189 | Hash, |
| 190 | GnuHash, |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 191 | Verdef, |
| 192 | Verneed, |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 193 | StackSizes, |
| 194 | SymtabShndxSection, |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 195 | Symver, |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 196 | ARMIndexTable, |
| 197 | MipsABIFlags, |
| 198 | Addrsig, |
| 199 | Fill, |
| 200 | LinkerOptions, |
| 201 | DependentLibraries, |
| 202 | CallGraphProfile, |
| 203 | BBAddrMap |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 204 | }; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 205 | |
| 206 | ChunkKind Kind; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 207 | StringRef Name; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 208 | Optional<llvm::yaml::Hex64> Offset; |
| 209 | |
| 210 | Chunk(ChunkKind K) : Kind(K) {} |
| 211 | virtual ~Chunk(); |
| 212 | }; |
| 213 | |
| 214 | struct Section : public Chunk { |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 215 | ELF_SHT Type; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 216 | Optional<ELF_SHF> Flags; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 217 | Optional<llvm::yaml::Hex64> Address; |
| 218 | Optional<StringRef> Link; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 219 | llvm::yaml::Hex64 AddressAlign; |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 220 | Optional<llvm::yaml::Hex64> EntSize; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 221 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 222 | Optional<yaml::BinaryRef> Content; |
| 223 | Optional<llvm::yaml::Hex64> Size; |
| 224 | |
| 225 | // Usually sections are not created implicitly, but loaded from YAML. |
| 226 | // When they are, this flag is used to signal about that. |
| 227 | bool IsImplicit; |
| 228 | |
| 229 | // Holds the original section index. |
| 230 | unsigned OriginalSecNdx; |
| 231 | |
| 232 | Section(ChunkKind Kind, bool IsImplicit = false) |
| 233 | : Chunk(Kind), IsImplicit(IsImplicit) {} |
| 234 | |
| 235 | static bool classof(const Chunk *S) { return S->Kind != ChunkKind::Fill; } |
| 236 | |
| 237 | // Some derived sections might have their own special entries. This method |
| 238 | // returns a vector of <entry name, is used> pairs. It is used for section |
| 239 | // validation. |
| 240 | virtual std::vector<std::pair<StringRef, bool>> getEntries() const { |
| 241 | return {}; |
| 242 | }; |
| 243 | |
| 244 | // The following members are used to override section fields which is |
| 245 | // useful for creating invalid objects. |
| 246 | |
| 247 | // This can be used to override the sh_addralign field. |
| 248 | Optional<llvm::yaml::Hex64> ShAddrAlign; |
| 249 | |
| 250 | // This can be used to override the offset stored in the sh_name field. |
| 251 | // It does not affect the name stored in the string table. |
| 252 | Optional<llvm::yaml::Hex64> ShName; |
| 253 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 254 | // This can be used to override the sh_offset field. It does not place the |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 255 | // section data at the offset specified. |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 256 | Optional<llvm::yaml::Hex64> ShOffset; |
| 257 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 258 | // This can be used to override the sh_size field. It does not affect the |
| 259 | // content written. |
| 260 | Optional<llvm::yaml::Hex64> ShSize; |
| 261 | |
| 262 | // This can be used to override the sh_flags field. |
| 263 | Optional<llvm::yaml::Hex64> ShFlags; |
| 264 | |
| 265 | // This can be used to override the sh_type field. It is useful when we |
| 266 | // want to use specific YAML keys for a section of a particular type to |
| 267 | // describe the content, but still want to have a different final type |
| 268 | // for the section. |
| 269 | Optional<ELF_SHT> ShType; |
| 270 | }; |
| 271 | |
| 272 | // Fill is a block of data which is placed outside of sections. It is |
| 273 | // not present in the sections header table, but it might affect the output file |
| 274 | // size and program headers produced. |
| 275 | struct Fill : Chunk { |
| 276 | Optional<yaml::BinaryRef> Pattern; |
| 277 | llvm::yaml::Hex64 Size; |
| 278 | |
| 279 | Fill() : Chunk(ChunkKind::Fill) {} |
| 280 | |
| 281 | static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Fill; } |
| 282 | }; |
| 283 | |
| 284 | struct BBAddrMapSection : Section { |
| 285 | Optional<std::vector<BBAddrMapEntry>> Entries; |
| 286 | |
| 287 | BBAddrMapSection() : Section(ChunkKind::BBAddrMap) {} |
| 288 | |
| 289 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 290 | return {{"Entries", Entries.hasValue()}}; |
| 291 | }; |
| 292 | |
| 293 | static bool classof(const Chunk *S) { |
| 294 | return S->Kind == ChunkKind::BBAddrMap; |
| 295 | } |
| 296 | }; |
| 297 | |
| 298 | struct StackSizesSection : Section { |
| 299 | Optional<std::vector<StackSizeEntry>> Entries; |
| 300 | |
| 301 | StackSizesSection() : Section(ChunkKind::StackSizes) {} |
| 302 | |
| 303 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 304 | return {{"Entries", Entries.hasValue()}}; |
| 305 | }; |
| 306 | |
| 307 | static bool classof(const Chunk *S) { |
| 308 | return S->Kind == ChunkKind::StackSizes; |
| 309 | } |
| 310 | |
| 311 | static bool nameMatches(StringRef Name) { |
| 312 | return Name == ".stack_sizes"; |
| 313 | } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 314 | }; |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 315 | |
| 316 | struct DynamicSection : Section { |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 317 | Optional<std::vector<DynamicEntry>> Entries; |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 318 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 319 | DynamicSection() : Section(ChunkKind::Dynamic) {} |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 320 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 321 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 322 | return {{"Entries", Entries.hasValue()}}; |
| 323 | }; |
| 324 | |
| 325 | static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Dynamic; } |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 326 | }; |
| 327 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 328 | struct RawContentSection : Section { |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 329 | Optional<llvm::yaml::Hex64> Info; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 330 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 331 | RawContentSection() : Section(ChunkKind::RawContent) {} |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 332 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 333 | static bool classof(const Chunk *S) { |
| 334 | return S->Kind == ChunkKind::RawContent; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 335 | } |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 336 | |
| 337 | // Is used when a content is read as an array of bytes. |
| 338 | Optional<std::vector<uint8_t>> ContentBuf; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 339 | }; |
| 340 | |
| 341 | struct NoBitsSection : Section { |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 342 | NoBitsSection() : Section(ChunkKind::NoBits) {} |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 343 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 344 | static bool classof(const Chunk *S) { return S->Kind == ChunkKind::NoBits; } |
| 345 | }; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 346 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 347 | struct NoteSection : Section { |
| 348 | Optional<std::vector<ELFYAML::NoteEntry>> Notes; |
| 349 | |
| 350 | NoteSection() : Section(ChunkKind::Note) {} |
| 351 | |
| 352 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 353 | return {{"Notes", Notes.hasValue()}}; |
| 354 | }; |
| 355 | |
| 356 | static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Note; } |
| 357 | }; |
| 358 | |
| 359 | struct HashSection : Section { |
| 360 | Optional<std::vector<uint32_t>> Bucket; |
| 361 | Optional<std::vector<uint32_t>> Chain; |
| 362 | |
| 363 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 364 | return {{"Bucket", Bucket.hasValue()}, {"Chain", Chain.hasValue()}}; |
| 365 | }; |
| 366 | |
| 367 | // The following members are used to override section fields. |
| 368 | // This is useful for creating invalid objects. |
| 369 | Optional<llvm::yaml::Hex64> NBucket; |
| 370 | Optional<llvm::yaml::Hex64> NChain; |
| 371 | |
| 372 | HashSection() : Section(ChunkKind::Hash) {} |
| 373 | |
| 374 | static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Hash; } |
| 375 | }; |
| 376 | |
| 377 | struct GnuHashHeader { |
| 378 | // The number of hash buckets. |
| 379 | // Not used when dumping the object, but can be used to override |
| 380 | // the real number of buckets when emiting an object from a YAML document. |
| 381 | Optional<llvm::yaml::Hex32> NBuckets; |
| 382 | |
| 383 | // Index of the first symbol in the dynamic symbol table |
| 384 | // included in the hash table. |
| 385 | llvm::yaml::Hex32 SymNdx; |
| 386 | |
| 387 | // The number of words in the Bloom filter. |
| 388 | // Not used when dumping the object, but can be used to override the real |
| 389 | // number of words in the Bloom filter when emiting an object from a YAML |
| 390 | // document. |
| 391 | Optional<llvm::yaml::Hex32> MaskWords; |
| 392 | |
| 393 | // A shift constant used by the Bloom filter. |
| 394 | llvm::yaml::Hex32 Shift2; |
| 395 | }; |
| 396 | |
| 397 | struct GnuHashSection : Section { |
| 398 | Optional<GnuHashHeader> Header; |
| 399 | Optional<std::vector<llvm::yaml::Hex64>> BloomFilter; |
| 400 | Optional<std::vector<llvm::yaml::Hex32>> HashBuckets; |
| 401 | Optional<std::vector<llvm::yaml::Hex32>> HashValues; |
| 402 | |
| 403 | GnuHashSection() : Section(ChunkKind::GnuHash) {} |
| 404 | |
| 405 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 406 | return {{"Header", Header.hasValue()}, |
| 407 | {"BloomFilter", BloomFilter.hasValue()}, |
| 408 | {"HashBuckets", HashBuckets.hasValue()}, |
| 409 | {"HashValues", HashValues.hasValue()}}; |
| 410 | }; |
| 411 | |
| 412 | static bool classof(const Chunk *S) { return S->Kind == ChunkKind::GnuHash; } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 413 | }; |
| 414 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 415 | struct VernauxEntry { |
| 416 | uint32_t Hash; |
| 417 | uint16_t Flags; |
| 418 | uint16_t Other; |
| 419 | StringRef Name; |
| 420 | }; |
| 421 | |
| 422 | struct VerneedEntry { |
| 423 | uint16_t Version; |
| 424 | StringRef File; |
| 425 | std::vector<VernauxEntry> AuxV; |
| 426 | }; |
| 427 | |
| 428 | struct VerneedSection : Section { |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 429 | Optional<std::vector<VerneedEntry>> VerneedV; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 430 | llvm::yaml::Hex64 Info; |
| 431 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 432 | VerneedSection() : Section(ChunkKind::Verneed) {} |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 433 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 434 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 435 | return {{"Dependencies", VerneedV.hasValue()}}; |
| 436 | }; |
| 437 | |
| 438 | static bool classof(const Chunk *S) { |
| 439 | return S->Kind == ChunkKind::Verneed; |
| 440 | } |
| 441 | }; |
| 442 | |
| 443 | struct AddrsigSection : Section { |
| 444 | Optional<std::vector<YAMLFlowString>> Symbols; |
| 445 | |
| 446 | AddrsigSection() : Section(ChunkKind::Addrsig) {} |
| 447 | |
| 448 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 449 | return {{"Symbols", Symbols.hasValue()}}; |
| 450 | }; |
| 451 | |
| 452 | static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Addrsig; } |
| 453 | }; |
| 454 | |
| 455 | struct LinkerOption { |
| 456 | StringRef Key; |
| 457 | StringRef Value; |
| 458 | }; |
| 459 | |
| 460 | struct LinkerOptionsSection : Section { |
| 461 | Optional<std::vector<LinkerOption>> Options; |
| 462 | |
| 463 | LinkerOptionsSection() : Section(ChunkKind::LinkerOptions) {} |
| 464 | |
| 465 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 466 | return {{"Options", Options.hasValue()}}; |
| 467 | }; |
| 468 | |
| 469 | static bool classof(const Chunk *S) { |
| 470 | return S->Kind == ChunkKind::LinkerOptions; |
| 471 | } |
| 472 | }; |
| 473 | |
| 474 | struct DependentLibrariesSection : Section { |
| 475 | Optional<std::vector<YAMLFlowString>> Libs; |
| 476 | |
| 477 | DependentLibrariesSection() : Section(ChunkKind::DependentLibraries) {} |
| 478 | |
| 479 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 480 | return {{"Libraries", Libs.hasValue()}}; |
| 481 | }; |
| 482 | |
| 483 | static bool classof(const Chunk *S) { |
| 484 | return S->Kind == ChunkKind::DependentLibraries; |
| 485 | } |
| 486 | }; |
| 487 | |
| 488 | // Represents the call graph profile section entry. |
| 489 | struct CallGraphEntry { |
| 490 | // The symbol of the source of the edge. |
| 491 | StringRef From; |
| 492 | // The symbol index of the destination of the edge. |
| 493 | StringRef To; |
| 494 | // The weight of the edge. |
| 495 | uint64_t Weight; |
| 496 | }; |
| 497 | |
| 498 | struct CallGraphProfileSection : Section { |
| 499 | Optional<std::vector<CallGraphEntry>> Entries; |
| 500 | |
| 501 | CallGraphProfileSection() : Section(ChunkKind::CallGraphProfile) {} |
| 502 | |
| 503 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 504 | return {{"Entries", Entries.hasValue()}}; |
| 505 | }; |
| 506 | |
| 507 | static bool classof(const Chunk *S) { |
| 508 | return S->Kind == ChunkKind::CallGraphProfile; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 509 | } |
| 510 | }; |
| 511 | |
| 512 | struct SymverSection : Section { |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 513 | Optional<std::vector<uint16_t>> Entries; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 514 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 515 | SymverSection() : Section(ChunkKind::Symver) {} |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 516 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 517 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 518 | return {{"Entries", Entries.hasValue()}}; |
| 519 | }; |
| 520 | |
| 521 | static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Symver; } |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 522 | }; |
| 523 | |
| 524 | struct VerdefEntry { |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 525 | Optional<uint16_t> Version; |
| 526 | Optional<uint16_t> Flags; |
| 527 | Optional<uint16_t> VersionNdx; |
| 528 | Optional<uint32_t> Hash; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 529 | std::vector<StringRef> VerNames; |
| 530 | }; |
| 531 | |
| 532 | struct VerdefSection : Section { |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 533 | Optional<std::vector<VerdefEntry>> Entries; |
| 534 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 535 | llvm::yaml::Hex64 Info; |
| 536 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 537 | VerdefSection() : Section(ChunkKind::Verdef) {} |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 538 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 539 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 540 | return {{"Entries", Entries.hasValue()}}; |
| 541 | }; |
| 542 | |
| 543 | static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Verdef; } |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 544 | }; |
| 545 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 546 | struct GroupSection : Section { |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 547 | // Members of a group contain a flag and a list of section indices |
| 548 | // that are part of the group. |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 549 | Optional<std::vector<SectionOrType>> Members; |
| 550 | Optional<StringRef> Signature; /* Info */ |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 551 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 552 | GroupSection() : Section(ChunkKind::Group) {} |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 553 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 554 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 555 | return {{"Members", Members.hasValue()}}; |
| 556 | }; |
| 557 | |
| 558 | static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Group; } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 559 | }; |
| 560 | |
| 561 | struct Relocation { |
| 562 | llvm::yaml::Hex64 Offset; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 563 | YAMLIntUInt Addend; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 564 | ELF_REL Type; |
| 565 | Optional<StringRef> Symbol; |
| 566 | }; |
| 567 | |
| 568 | struct RelocationSection : Section { |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 569 | Optional<std::vector<Relocation>> Relocations; |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 570 | StringRef RelocatableSec; /* Info */ |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 571 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 572 | RelocationSection() : Section(ChunkKind::Relocation) {} |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 573 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 574 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 575 | return {{"Relocations", Relocations.hasValue()}}; |
| 576 | }; |
| 577 | |
| 578 | static bool classof(const Chunk *S) { |
| 579 | return S->Kind == ChunkKind::Relocation; |
| 580 | } |
| 581 | }; |
| 582 | |
| 583 | struct RelrSection : Section { |
| 584 | Optional<std::vector<llvm::yaml::Hex64>> Entries; |
| 585 | |
| 586 | RelrSection() : Section(ChunkKind::Relr) {} |
| 587 | |
| 588 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 589 | return {{"Entries", Entries.hasValue()}}; |
| 590 | }; |
| 591 | |
| 592 | static bool classof(const Chunk *S) { |
| 593 | return S->Kind == ChunkKind::Relr; |
| 594 | } |
| 595 | }; |
| 596 | |
| 597 | struct SymtabShndxSection : Section { |
| 598 | Optional<std::vector<uint32_t>> Entries; |
| 599 | |
| 600 | SymtabShndxSection() : Section(ChunkKind::SymtabShndxSection) {} |
| 601 | |
| 602 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 603 | return {{"Entries", Entries.hasValue()}}; |
| 604 | }; |
| 605 | |
| 606 | static bool classof(const Chunk *S) { |
| 607 | return S->Kind == ChunkKind::SymtabShndxSection; |
| 608 | } |
| 609 | }; |
| 610 | |
| 611 | struct ARMIndexTableEntry { |
| 612 | llvm::yaml::Hex32 Offset; |
| 613 | llvm::yaml::Hex32 Value; |
| 614 | }; |
| 615 | |
| 616 | struct ARMIndexTableSection : Section { |
| 617 | Optional<std::vector<ARMIndexTableEntry>> Entries; |
| 618 | |
| 619 | ARMIndexTableSection() : Section(ChunkKind::ARMIndexTable) {} |
| 620 | |
| 621 | std::vector<std::pair<StringRef, bool>> getEntries() const override { |
| 622 | return {{"Entries", Entries.hasValue()}}; |
| 623 | }; |
| 624 | |
| 625 | static bool classof(const Chunk *S) { |
| 626 | return S->Kind == ChunkKind::ARMIndexTable; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 627 | } |
| 628 | }; |
| 629 | |
| 630 | // Represents .MIPS.abiflags section |
| 631 | struct MipsABIFlags : Section { |
| 632 | llvm::yaml::Hex16 Version; |
| 633 | MIPS_ISA ISALevel; |
| 634 | llvm::yaml::Hex8 ISARevision; |
| 635 | MIPS_AFL_REG GPRSize; |
| 636 | MIPS_AFL_REG CPR1Size; |
| 637 | MIPS_AFL_REG CPR2Size; |
| 638 | MIPS_ABI_FP FpABI; |
| 639 | MIPS_AFL_EXT ISAExtension; |
| 640 | MIPS_AFL_ASE ASEs; |
| 641 | MIPS_AFL_FLAGS1 Flags1; |
| 642 | llvm::yaml::Hex32 Flags2; |
| 643 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 644 | MipsABIFlags() : Section(ChunkKind::MipsABIFlags) {} |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 645 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 646 | static bool classof(const Chunk *S) { |
| 647 | return S->Kind == ChunkKind::MipsABIFlags; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 648 | } |
| 649 | }; |
| 650 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 651 | struct ProgramHeader { |
| 652 | ELF_PT Type; |
| 653 | ELF_PF Flags; |
| 654 | llvm::yaml::Hex64 VAddr; |
| 655 | llvm::yaml::Hex64 PAddr; |
| 656 | Optional<llvm::yaml::Hex64> Align; |
| 657 | Optional<llvm::yaml::Hex64> FileSize; |
| 658 | Optional<llvm::yaml::Hex64> MemSize; |
| 659 | Optional<llvm::yaml::Hex64> Offset; |
| 660 | Optional<StringRef> FirstSec; |
| 661 | Optional<StringRef> LastSec; |
| 662 | |
| 663 | // This vector contains all chunks from [FirstSec, LastSec]. |
| 664 | std::vector<Chunk *> Chunks; |
| 665 | }; |
| 666 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 667 | struct Object { |
| 668 | FileHeader Header; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 669 | Optional<SectionHeaderTable> SectionHeaders; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 670 | std::vector<ProgramHeader> ProgramHeaders; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 671 | |
| 672 | // An object might contain output section descriptions as well as |
| 673 | // custom data that does not belong to any section. |
| 674 | std::vector<std::unique_ptr<Chunk>> Chunks; |
| 675 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 676 | // Although in reality the symbols reside in a section, it is a lot |
| 677 | // cleaner and nicer if we read them from the YAML as a separate |
| 678 | // top-level key, which automatically ensures that invariants like there |
| 679 | // being a single SHT_SYMTAB section are upheld. |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 680 | Optional<std::vector<Symbol>> Symbols; |
| 681 | Optional<std::vector<Symbol>> DynamicSymbols; |
| 682 | Optional<DWARFYAML::Data> DWARF; |
| 683 | |
| 684 | std::vector<Section *> getSections() { |
| 685 | std::vector<Section *> Ret; |
| 686 | for (const std::unique_ptr<Chunk> &Sec : Chunks) |
| 687 | if (auto S = dyn_cast<ELFYAML::Section>(Sec.get())) |
| 688 | Ret.push_back(S); |
| 689 | return Ret; |
| 690 | } |
| 691 | |
| 692 | unsigned getMachine() const; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 693 | }; |
| 694 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 695 | bool shouldAllocateFileSpace(ArrayRef<ProgramHeader> Phdrs, |
| 696 | const NoBitsSection &S); |
| 697 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 698 | } // end namespace ELFYAML |
| 699 | } // end namespace llvm |
| 700 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 701 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::StackSizeEntry) |
| 702 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::BBAddrMapEntry) |
| 703 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::BBAddrMapEntry::BBEntry) |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 704 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::DynamicEntry) |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 705 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::LinkerOption) |
| 706 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::CallGraphEntry) |
| 707 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::NoteEntry) |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 708 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::ProgramHeader) |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 709 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::SectionHeader) |
| 710 | LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::ELFYAML::Chunk>) |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 711 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Symbol) |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 712 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::VerdefEntry) |
| 713 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::VernauxEntry) |
| 714 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::VerneedEntry) |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 715 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Relocation) |
| 716 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::SectionOrType) |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 717 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::ARMIndexTableEntry) |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 718 | |
| 719 | namespace llvm { |
| 720 | namespace yaml { |
| 721 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 722 | template <> struct ScalarTraits<ELFYAML::YAMLIntUInt> { |
| 723 | static void output(const ELFYAML::YAMLIntUInt &Val, void *Ctx, |
| 724 | raw_ostream &Out); |
| 725 | static StringRef input(StringRef Scalar, void *Ctx, |
| 726 | ELFYAML::YAMLIntUInt &Val); |
| 727 | static QuotingType mustQuote(StringRef) { return QuotingType::None; } |
| 728 | }; |
| 729 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 730 | template <> |
| 731 | struct ScalarEnumerationTraits<ELFYAML::ELF_ET> { |
| 732 | static void enumeration(IO &IO, ELFYAML::ELF_ET &Value); |
| 733 | }; |
| 734 | |
| 735 | template <> struct ScalarEnumerationTraits<ELFYAML::ELF_PT> { |
| 736 | static void enumeration(IO &IO, ELFYAML::ELF_PT &Value); |
| 737 | }; |
| 738 | |
| 739 | template <> |
| 740 | struct ScalarEnumerationTraits<ELFYAML::ELF_EM> { |
| 741 | static void enumeration(IO &IO, ELFYAML::ELF_EM &Value); |
| 742 | }; |
| 743 | |
| 744 | template <> |
| 745 | struct ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS> { |
| 746 | static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value); |
| 747 | }; |
| 748 | |
| 749 | template <> |
| 750 | struct ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA> { |
| 751 | static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value); |
| 752 | }; |
| 753 | |
| 754 | template <> |
| 755 | struct ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI> { |
| 756 | static void enumeration(IO &IO, ELFYAML::ELF_ELFOSABI &Value); |
| 757 | }; |
| 758 | |
| 759 | template <> |
| 760 | struct ScalarBitSetTraits<ELFYAML::ELF_EF> { |
| 761 | static void bitset(IO &IO, ELFYAML::ELF_EF &Value); |
| 762 | }; |
| 763 | |
| 764 | template <> struct ScalarBitSetTraits<ELFYAML::ELF_PF> { |
| 765 | static void bitset(IO &IO, ELFYAML::ELF_PF &Value); |
| 766 | }; |
| 767 | |
| 768 | template <> |
| 769 | struct ScalarEnumerationTraits<ELFYAML::ELF_SHT> { |
| 770 | static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value); |
| 771 | }; |
| 772 | |
| 773 | template <> |
| 774 | struct ScalarBitSetTraits<ELFYAML::ELF_SHF> { |
| 775 | static void bitset(IO &IO, ELFYAML::ELF_SHF &Value); |
| 776 | }; |
| 777 | |
| 778 | template <> struct ScalarEnumerationTraits<ELFYAML::ELF_SHN> { |
| 779 | static void enumeration(IO &IO, ELFYAML::ELF_SHN &Value); |
| 780 | }; |
| 781 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 782 | template <> struct ScalarEnumerationTraits<ELFYAML::ELF_STB> { |
| 783 | static void enumeration(IO &IO, ELFYAML::ELF_STB &Value); |
| 784 | }; |
| 785 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 786 | template <> |
| 787 | struct ScalarEnumerationTraits<ELFYAML::ELF_STT> { |
| 788 | static void enumeration(IO &IO, ELFYAML::ELF_STT &Value); |
| 789 | }; |
| 790 | |
| 791 | template <> |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 792 | struct ScalarEnumerationTraits<ELFYAML::ELF_REL> { |
| 793 | static void enumeration(IO &IO, ELFYAML::ELF_REL &Value); |
| 794 | }; |
| 795 | |
| 796 | template <> |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 797 | struct ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG> { |
| 798 | static void enumeration(IO &IO, ELFYAML::ELF_DYNTAG &Value); |
| 799 | }; |
| 800 | |
| 801 | template <> |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 802 | struct ScalarEnumerationTraits<ELFYAML::ELF_RSS> { |
| 803 | static void enumeration(IO &IO, ELFYAML::ELF_RSS &Value); |
| 804 | }; |
| 805 | |
| 806 | template <> |
| 807 | struct ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG> { |
| 808 | static void enumeration(IO &IO, ELFYAML::MIPS_AFL_REG &Value); |
| 809 | }; |
| 810 | |
| 811 | template <> |
| 812 | struct ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP> { |
| 813 | static void enumeration(IO &IO, ELFYAML::MIPS_ABI_FP &Value); |
| 814 | }; |
| 815 | |
| 816 | template <> |
| 817 | struct ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT> { |
| 818 | static void enumeration(IO &IO, ELFYAML::MIPS_AFL_EXT &Value); |
| 819 | }; |
| 820 | |
| 821 | template <> |
| 822 | struct ScalarEnumerationTraits<ELFYAML::MIPS_ISA> { |
| 823 | static void enumeration(IO &IO, ELFYAML::MIPS_ISA &Value); |
| 824 | }; |
| 825 | |
| 826 | template <> |
| 827 | struct ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE> { |
| 828 | static void bitset(IO &IO, ELFYAML::MIPS_AFL_ASE &Value); |
| 829 | }; |
| 830 | |
| 831 | template <> |
| 832 | struct ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1> { |
| 833 | static void bitset(IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value); |
| 834 | }; |
| 835 | |
| 836 | template <> |
| 837 | struct MappingTraits<ELFYAML::FileHeader> { |
| 838 | static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr); |
| 839 | }; |
| 840 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 841 | template <> struct MappingTraits<ELFYAML::SectionHeaderTable> { |
| 842 | static void mapping(IO &IO, ELFYAML::SectionHeaderTable &SecHdrTable); |
| 843 | static std::string validate(IO &IO, ELFYAML::SectionHeaderTable &SecHdrTable); |
| 844 | }; |
| 845 | |
| 846 | template <> struct MappingTraits<ELFYAML::SectionHeader> { |
| 847 | static void mapping(IO &IO, ELFYAML::SectionHeader &SHdr); |
| 848 | }; |
| 849 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 850 | template <> struct MappingTraits<ELFYAML::ProgramHeader> { |
| 851 | static void mapping(IO &IO, ELFYAML::ProgramHeader &FileHdr); |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 852 | static std::string validate(IO &IO, ELFYAML::ProgramHeader &FileHdr); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 853 | }; |
| 854 | |
| 855 | template <> |
| 856 | struct MappingTraits<ELFYAML::Symbol> { |
| 857 | static void mapping(IO &IO, ELFYAML::Symbol &Symbol); |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 858 | static std::string validate(IO &IO, ELFYAML::Symbol &Symbol); |
| 859 | }; |
| 860 | |
| 861 | template <> struct MappingTraits<ELFYAML::StackSizeEntry> { |
| 862 | static void mapping(IO &IO, ELFYAML::StackSizeEntry &Rel); |
| 863 | }; |
| 864 | |
| 865 | template <> struct MappingTraits<ELFYAML::BBAddrMapEntry> { |
| 866 | static void mapping(IO &IO, ELFYAML::BBAddrMapEntry &Rel); |
| 867 | }; |
| 868 | |
| 869 | template <> struct MappingTraits<ELFYAML::BBAddrMapEntry::BBEntry> { |
| 870 | static void mapping(IO &IO, ELFYAML::BBAddrMapEntry::BBEntry &Rel); |
| 871 | }; |
| 872 | |
| 873 | template <> struct MappingTraits<ELFYAML::GnuHashHeader> { |
| 874 | static void mapping(IO &IO, ELFYAML::GnuHashHeader &Rel); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 875 | }; |
| 876 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 877 | template <> struct MappingTraits<ELFYAML::DynamicEntry> { |
| 878 | static void mapping(IO &IO, ELFYAML::DynamicEntry &Rel); |
| 879 | }; |
| 880 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 881 | template <> struct MappingTraits<ELFYAML::NoteEntry> { |
| 882 | static void mapping(IO &IO, ELFYAML::NoteEntry &N); |
| 883 | }; |
| 884 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 885 | template <> struct MappingTraits<ELFYAML::VerdefEntry> { |
| 886 | static void mapping(IO &IO, ELFYAML::VerdefEntry &E); |
| 887 | }; |
| 888 | |
| 889 | template <> struct MappingTraits<ELFYAML::VerneedEntry> { |
| 890 | static void mapping(IO &IO, ELFYAML::VerneedEntry &E); |
| 891 | }; |
| 892 | |
| 893 | template <> struct MappingTraits<ELFYAML::VernauxEntry> { |
| 894 | static void mapping(IO &IO, ELFYAML::VernauxEntry &E); |
| 895 | }; |
| 896 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 897 | template <> struct MappingTraits<ELFYAML::LinkerOption> { |
| 898 | static void mapping(IO &IO, ELFYAML::LinkerOption &Sym); |
| 899 | }; |
| 900 | |
| 901 | template <> struct MappingTraits<ELFYAML::CallGraphEntry> { |
| 902 | static void mapping(IO &IO, ELFYAML::CallGraphEntry &E); |
| 903 | }; |
| 904 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 905 | template <> struct MappingTraits<ELFYAML::Relocation> { |
| 906 | static void mapping(IO &IO, ELFYAML::Relocation &Rel); |
| 907 | }; |
| 908 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 909 | template <> struct MappingTraits<ELFYAML::ARMIndexTableEntry> { |
| 910 | static void mapping(IO &IO, ELFYAML::ARMIndexTableEntry &E); |
| 911 | }; |
| 912 | |
| 913 | template <> struct MappingTraits<std::unique_ptr<ELFYAML::Chunk>> { |
| 914 | static void mapping(IO &IO, std::unique_ptr<ELFYAML::Chunk> &C); |
| 915 | static std::string validate(IO &io, std::unique_ptr<ELFYAML::Chunk> &C); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 916 | }; |
| 917 | |
| 918 | template <> |
| 919 | struct MappingTraits<ELFYAML::Object> { |
| 920 | static void mapping(IO &IO, ELFYAML::Object &Object); |
| 921 | }; |
| 922 | |
| 923 | template <> struct MappingTraits<ELFYAML::SectionOrType> { |
| 924 | static void mapping(IO &IO, ELFYAML::SectionOrType §ionOrType); |
| 925 | }; |
| 926 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 927 | } // end namespace yaml |
| 928 | } // end namespace llvm |
| 929 | |
| 930 | #endif // LLVM_OBJECTYAML_ELFYAML_H |