2013-06-10 23:44:15 +00:00
|
|
|
//===- ELFYAML.h - ELF YAMLIO implementation --------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief This file declares classes for handling the YAML representation
|
|
|
|
/// of ELF.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_OBJECT_ELFYAML_H
|
|
|
|
#define LLVM_OBJECT_ELFYAML_H
|
|
|
|
|
2014-07-03 02:01:39 +00:00
|
|
|
#include "llvm/MC/YAML.h"
|
2013-06-10 23:44:15 +00:00
|
|
|
#include "llvm/Support/ELF.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace ELFYAML {
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
// and are appropriately converted to the necessary endianness when
|
|
|
|
// reading/generating binary object files.
|
|
|
|
// The naming of these types is intended to be ELF_PREFIX, where PREFIX is
|
|
|
|
// the common prefix of the respective constants. E.g. ELF_EM corresponds
|
|
|
|
// to the `e_machine` constants, like `EM_X86_64`.
|
|
|
|
// In the future, these would probably be better suited by C++11 enum
|
|
|
|
// class's with appropriate fixed underlying type.
|
2013-06-10 23:48:38 +00:00
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_ET)
|
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_EM)
|
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFCLASS)
|
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFDATA)
|
2013-06-19 00:55:28 +00:00
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFOSABI)
|
2014-03-31 09:44:05 +00:00
|
|
|
// Just use 64, since it can hold 32-bit values too.
|
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_EF)
|
2013-06-13 22:19:48 +00:00
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT)
|
2014-11-27 17:20:48 +00:00
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_REL)
|
2015-01-25 13:29:25 +00:00
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_RSS)
|
2013-06-13 22:19:48 +00:00
|
|
|
// Just use 64, since it can hold 32-bit values too.
|
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
|
2013-06-19 00:11:59 +00:00
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
|
2014-06-06 07:41:57 +00:00
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STV)
|
2014-11-06 22:46:24 +00:00
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STO)
|
2013-06-10 23:44:15 +00:00
|
|
|
|
2015-05-07 15:40:48 +00:00
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
|
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)
|
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT)
|
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE)
|
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
|
|
|
|
LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_ISA)
|
|
|
|
|
2013-06-10 23:44:15 +00:00
|
|
|
// For now, hardcode 64 bits everywhere that 32 or 64 would be needed
|
|
|
|
// since 64-bit can hold 32-bit values too.
|
2013-06-11 00:13:52 +00:00
|
|
|
struct FileHeader {
|
2013-06-10 23:44:15 +00:00
|
|
|
ELF_ELFCLASS Class;
|
|
|
|
ELF_ELFDATA Data;
|
2013-06-19 00:55:28 +00:00
|
|
|
ELF_ELFOSABI OSABI;
|
2013-06-10 23:44:15 +00:00
|
|
|
ELF_ET Type;
|
|
|
|
ELF_EM Machine;
|
2014-03-31 09:44:05 +00:00
|
|
|
ELF_EF Flags;
|
2013-06-10 23:44:15 +00:00
|
|
|
llvm::yaml::Hex64 Entry;
|
|
|
|
};
|
2013-06-18 23:14:03 +00:00
|
|
|
struct Symbol {
|
|
|
|
StringRef Name;
|
2013-06-19 00:11:59 +00:00
|
|
|
ELF_STT Type;
|
2013-06-20 20:59:41 +00:00
|
|
|
StringRef Section;
|
2013-06-20 20:59:47 +00:00
|
|
|
llvm::yaml::Hex64 Value;
|
|
|
|
llvm::yaml::Hex64 Size;
|
2014-11-06 22:46:24 +00:00
|
|
|
uint8_t Other;
|
2013-06-18 23:14:03 +00:00
|
|
|
};
|
2013-06-21 00:27:50 +00:00
|
|
|
struct LocalGlobalWeakSymbols {
|
|
|
|
std::vector<Symbol> Local;
|
|
|
|
std::vector<Symbol> Global;
|
|
|
|
std::vector<Symbol> Weak;
|
|
|
|
};
|
2015-02-21 04:28:26 +00:00
|
|
|
|
|
|
|
struct SectionOrType {
|
|
|
|
StringRef sectionNameOrType;
|
|
|
|
};
|
|
|
|
|
2013-06-13 22:19:48 +00:00
|
|
|
struct Section {
|
2015-05-07 15:40:48 +00:00
|
|
|
enum class SectionKind { Group, RawContent, Relocation, MipsABIFlags };
|
2014-04-11 04:13:39 +00:00
|
|
|
SectionKind Kind;
|
2013-06-13 22:19:48 +00:00
|
|
|
StringRef Name;
|
|
|
|
ELF_SHT Type;
|
|
|
|
ELF_SHF Flags;
|
2013-06-13 22:19:54 +00:00
|
|
|
llvm::yaml::Hex64 Address;
|
2013-06-15 00:25:26 +00:00
|
|
|
StringRef Link;
|
2015-02-21 04:28:26 +00:00
|
|
|
StringRef Info;
|
2013-06-14 00:38:02 +00:00
|
|
|
llvm::yaml::Hex64 AddressAlign;
|
2014-04-11 04:13:39 +00:00
|
|
|
Section(SectionKind Kind) : Kind(Kind) {}
|
2014-04-23 11:10:55 +00:00
|
|
|
virtual ~Section();
|
2014-04-11 04:13:39 +00:00
|
|
|
};
|
|
|
|
struct RawContentSection : Section {
|
2014-07-03 02:01:39 +00:00
|
|
|
yaml::BinaryRef Content;
|
2014-05-16 16:01:00 +00:00
|
|
|
llvm::yaml::Hex64 Size;
|
2014-04-11 04:13:39 +00:00
|
|
|
RawContentSection() : Section(SectionKind::RawContent) {}
|
|
|
|
static bool classof(const Section *S) {
|
|
|
|
return S->Kind == SectionKind::RawContent;
|
|
|
|
}
|
|
|
|
};
|
2015-02-21 04:28:26 +00:00
|
|
|
|
|
|
|
struct Group : Section {
|
|
|
|
// Members of a group contain a flag and a list of section indices
|
|
|
|
// that are part of the group.
|
|
|
|
std::vector<SectionOrType> Members;
|
|
|
|
Group() : Section(SectionKind::Group) {}
|
|
|
|
static bool classof(const Section *S) {
|
|
|
|
return S->Kind == SectionKind::Group;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-11 04:13:39 +00:00
|
|
|
struct Relocation {
|
2014-05-15 18:04:09 +00:00
|
|
|
llvm::yaml::Hex64 Offset;
|
|
|
|
int64_t Addend;
|
2014-04-11 04:13:39 +00:00
|
|
|
ELF_REL Type;
|
|
|
|
StringRef Symbol;
|
|
|
|
};
|
|
|
|
struct RelocationSection : Section {
|
|
|
|
std::vector<Relocation> Relocations;
|
|
|
|
RelocationSection() : Section(SectionKind::Relocation) {}
|
|
|
|
static bool classof(const Section *S) {
|
|
|
|
return S->Kind == SectionKind::Relocation;
|
|
|
|
}
|
2013-06-13 22:19:48 +00:00
|
|
|
};
|
2015-05-07 15:40:48 +00:00
|
|
|
|
|
|
|
// Represents .MIPS.abiflags section
|
|
|
|
struct MipsABIFlags : Section {
|
|
|
|
llvm::yaml::Hex16 Version;
|
|
|
|
MIPS_ISA ISALevel;
|
|
|
|
llvm::yaml::Hex8 ISARevision;
|
|
|
|
MIPS_AFL_REG GPRSize;
|
|
|
|
MIPS_AFL_REG CPR1Size;
|
|
|
|
MIPS_AFL_REG CPR2Size;
|
|
|
|
MIPS_ABI_FP FpABI;
|
|
|
|
MIPS_AFL_EXT ISAExtension;
|
|
|
|
MIPS_AFL_ASE ASEs;
|
|
|
|
MIPS_AFL_FLAGS1 Flags1;
|
|
|
|
llvm::yaml::Hex32 Flags2;
|
|
|
|
MipsABIFlags() : Section(SectionKind::MipsABIFlags) {}
|
|
|
|
static bool classof(const Section *S) {
|
|
|
|
return S->Kind == SectionKind::MipsABIFlags;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-10 23:44:15 +00:00
|
|
|
struct Object {
|
2013-06-11 00:13:52 +00:00
|
|
|
FileHeader Header;
|
2014-04-11 04:13:39 +00:00
|
|
|
std::vector<std::unique_ptr<Section>> Sections;
|
2013-06-22 01:38:00 +00:00
|
|
|
// Although in reality the symbols reside in a section, it is a lot
|
|
|
|
// 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.
|
|
|
|
LocalGlobalWeakSymbols Symbols;
|
2013-06-10 23:44:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace ELFYAML
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2014-04-11 04:13:39 +00:00
|
|
|
LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::ELFYAML::Section>)
|
2013-06-18 23:14:03 +00:00
|
|
|
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Symbol)
|
2014-04-11 04:13:39 +00:00
|
|
|
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Relocation)
|
2015-02-21 04:28:26 +00:00
|
|
|
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::SectionOrType)
|
2013-06-13 22:19:48 +00:00
|
|
|
|
2013-06-10 23:44:15 +00:00
|
|
|
namespace llvm {
|
|
|
|
namespace yaml {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<ELFYAML::ELF_ET> {
|
|
|
|
static void enumeration(IO &IO, ELFYAML::ELF_ET &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<ELFYAML::ELF_EM> {
|
|
|
|
static void enumeration(IO &IO, ELFYAML::ELF_EM &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS> {
|
|
|
|
static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA> {
|
|
|
|
static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value);
|
2013-06-19 00:55:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI> {
|
|
|
|
static void enumeration(IO &IO, ELFYAML::ELF_ELFOSABI &Value);
|
2013-06-10 23:44:15 +00:00
|
|
|
};
|
|
|
|
|
2013-06-13 22:19:48 +00:00
|
|
|
template <>
|
2014-03-31 09:44:05 +00:00
|
|
|
struct ScalarBitSetTraits<ELFYAML::ELF_EF> {
|
|
|
|
static void bitset(IO &IO, ELFYAML::ELF_EF &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2013-06-13 22:19:48 +00:00
|
|
|
struct ScalarEnumerationTraits<ELFYAML::ELF_SHT> {
|
|
|
|
static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarBitSetTraits<ELFYAML::ELF_SHF> {
|
|
|
|
static void bitset(IO &IO, ELFYAML::ELF_SHF &Value);
|
|
|
|
};
|
|
|
|
|
2013-06-19 00:11:59 +00:00
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<ELFYAML::ELF_STT> {
|
|
|
|
static void enumeration(IO &IO, ELFYAML::ELF_STT &Value);
|
|
|
|
};
|
2014-06-06 07:41:57 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<ELFYAML::ELF_STV> {
|
|
|
|
static void enumeration(IO &IO, ELFYAML::ELF_STV &Value);
|
|
|
|
};
|
2014-11-06 22:46:24 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarBitSetTraits<ELFYAML::ELF_STO> {
|
|
|
|
static void bitset(IO &IO, ELFYAML::ELF_STO &Value);
|
|
|
|
};
|
2013-06-19 00:11:59 +00:00
|
|
|
|
2014-04-11 04:13:39 +00:00
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<ELFYAML::ELF_REL> {
|
|
|
|
static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
|
|
|
|
};
|
|
|
|
|
2015-01-25 13:29:25 +00:00
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<ELFYAML::ELF_RSS> {
|
|
|
|
static void enumeration(IO &IO, ELFYAML::ELF_RSS &Value);
|
|
|
|
};
|
|
|
|
|
2013-06-10 23:44:15 +00:00
|
|
|
template <>
|
2015-05-07 15:40:48 +00:00
|
|
|
struct ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG> {
|
|
|
|
static void enumeration(IO &IO, ELFYAML::MIPS_AFL_REG &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP> {
|
|
|
|
static void enumeration(IO &IO, ELFYAML::MIPS_ABI_FP &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT> {
|
|
|
|
static void enumeration(IO &IO, ELFYAML::MIPS_AFL_EXT &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<ELFYAML::MIPS_ISA> {
|
|
|
|
static void enumeration(IO &IO, ELFYAML::MIPS_ISA &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE> {
|
|
|
|
static void bitset(IO &IO, ELFYAML::MIPS_AFL_ASE &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1> {
|
|
|
|
static void bitset(IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2013-06-11 00:13:52 +00:00
|
|
|
struct MappingTraits<ELFYAML::FileHeader> {
|
|
|
|
static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr);
|
2013-06-10 23:44:15 +00:00
|
|
|
};
|
|
|
|
|
2013-06-18 23:14:03 +00:00
|
|
|
template <>
|
|
|
|
struct MappingTraits<ELFYAML::Symbol> {
|
|
|
|
static void mapping(IO &IO, ELFYAML::Symbol &Symbol);
|
|
|
|
};
|
|
|
|
|
2013-06-21 00:27:50 +00:00
|
|
|
template <>
|
|
|
|
struct MappingTraits<ELFYAML::LocalGlobalWeakSymbols> {
|
|
|
|
static void mapping(IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols);
|
|
|
|
};
|
|
|
|
|
2014-04-11 04:13:39 +00:00
|
|
|
template <> struct MappingTraits<ELFYAML::Relocation> {
|
|
|
|
static void mapping(IO &IO, ELFYAML::Relocation &Rel);
|
|
|
|
};
|
|
|
|
|
2013-06-13 22:19:48 +00:00
|
|
|
template <>
|
2014-04-11 04:13:39 +00:00
|
|
|
struct MappingTraits<std::unique_ptr<ELFYAML::Section>> {
|
|
|
|
static void mapping(IO &IO, std::unique_ptr<ELFYAML::Section> &Section);
|
2014-05-16 16:01:00 +00:00
|
|
|
static StringRef validate(IO &io, std::unique_ptr<ELFYAML::Section> &Section);
|
2013-06-13 22:19:48 +00:00
|
|
|
};
|
|
|
|
|
2013-06-10 23:44:15 +00:00
|
|
|
template <>
|
|
|
|
struct MappingTraits<ELFYAML::Object> {
|
|
|
|
static void mapping(IO &IO, ELFYAML::Object &Object);
|
|
|
|
};
|
|
|
|
|
2015-02-21 04:28:26 +00:00
|
|
|
template <> struct MappingTraits<ELFYAML::SectionOrType> {
|
|
|
|
static void mapping(IO &IO, ELFYAML::SectionOrType §ionOrType);
|
|
|
|
};
|
|
|
|
|
2013-06-10 23:44:15 +00:00
|
|
|
} // end namespace yaml
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|