ELFYAML.h revision e38f640b22979994b42fb2f2aafc44cc39c20e8e
1//===- ELFYAML.h - ELF YAMLIO implementation --------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9/// 10/// \file 11/// \brief This file declares classes for handling the YAML representation 12/// of ELF. 13/// 14//===----------------------------------------------------------------------===// 15 16#ifndef LLVM_OBJECT_ELFYAML_H 17#define LLVM_OBJECT_ELFYAML_H 18 19#include "llvm/Object/YAML.h" 20#include "llvm/Support/ELF.h" 21 22namespace llvm { 23namespace ELFYAML { 24 25// These types are invariant across 32/64-bit ELF, so for simplicity just 26// directly give them their exact sizes. We don't need to worry about 27// endianness because these are just the types in the YAMLIO structures, 28// and are appropriately converted to the necessary endianness when 29// reading/generating binary object files. 30// The naming of these types is intended to be ELF_PREFIX, where PREFIX is 31// the common prefix of the respective constants. E.g. ELF_EM corresponds 32// to the `e_machine` constants, like `EM_X86_64`. 33// In the future, these would probably be better suited by C++11 enum 34// class's with appropriate fixed underlying type. 35LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_ET) 36LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_EM) 37LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFCLASS) 38LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFDATA) 39LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFOSABI) 40LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT) 41// Just use 64, since it can hold 32-bit values too. 42LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF) 43LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STB) 44LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT) 45 46// For now, hardcode 64 bits everywhere that 32 or 64 would be needed 47// since 64-bit can hold 32-bit values too. 48struct FileHeader { 49 ELF_ELFCLASS Class; 50 ELF_ELFDATA Data; 51 ELF_ELFOSABI OSABI; 52 ELF_ET Type; 53 ELF_EM Machine; 54 llvm::yaml::Hex64 Entry; 55}; 56struct Symbol { 57 StringRef Name; 58 ELF_STB Binding; 59 ELF_STT Type; 60 StringRef Section; 61 llvm::yaml::Hex64 Value; 62 llvm::yaml::Hex64 Size; 63}; 64struct Section { 65 StringRef Name; 66 ELF_SHT Type; 67 ELF_SHF Flags; 68 llvm::yaml::Hex64 Address; 69 object::yaml::BinaryRef Content; 70 StringRef Link; 71 llvm::yaml::Hex64 AddressAlign; 72 // For SHT_SYMTAB; should be empty otherwise. 73 std::vector<Symbol> Symbols; 74}; 75struct Object { 76 FileHeader Header; 77 std::vector<Section> Sections; 78}; 79 80} // end namespace ELFYAML 81} // end namespace llvm 82 83LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Section) 84LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Symbol) 85 86namespace llvm { 87namespace yaml { 88 89template <> 90struct ScalarEnumerationTraits<ELFYAML::ELF_ET> { 91 static void enumeration(IO &IO, ELFYAML::ELF_ET &Value); 92}; 93 94template <> 95struct ScalarEnumerationTraits<ELFYAML::ELF_EM> { 96 static void enumeration(IO &IO, ELFYAML::ELF_EM &Value); 97}; 98 99template <> 100struct ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS> { 101 static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value); 102}; 103 104template <> 105struct ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA> { 106 static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value); 107}; 108 109template <> 110struct ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI> { 111 static void enumeration(IO &IO, ELFYAML::ELF_ELFOSABI &Value); 112}; 113 114template <> 115struct ScalarEnumerationTraits<ELFYAML::ELF_SHT> { 116 static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value); 117}; 118 119template <> 120struct ScalarBitSetTraits<ELFYAML::ELF_SHF> { 121 static void bitset(IO &IO, ELFYAML::ELF_SHF &Value); 122}; 123 124template <> 125struct ScalarEnumerationTraits<ELFYAML::ELF_STB> { 126 static void enumeration(IO &IO, ELFYAML::ELF_STB &Value); 127}; 128 129template <> 130struct ScalarEnumerationTraits<ELFYAML::ELF_STT> { 131 static void enumeration(IO &IO, ELFYAML::ELF_STT &Value); 132}; 133 134template <> 135struct MappingTraits<ELFYAML::FileHeader> { 136 static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr); 137}; 138 139template <> 140struct MappingTraits<ELFYAML::Symbol> { 141 static void mapping(IO &IO, ELFYAML::Symbol &Symbol); 142}; 143 144template <> 145struct MappingTraits<ELFYAML::Section> { 146 static void mapping(IO &IO, ELFYAML::Section &Section); 147}; 148 149template <> 150struct MappingTraits<ELFYAML::Object> { 151 static void mapping(IO &IO, ELFYAML::Object &Object); 152}; 153 154} // end namespace yaml 155} // end namespace llvm 156 157#endif 158