summaryrefslogtreecommitdiff
path: root/include/llvm/Object/ELFYAML.h
diff options
context:
space:
mode:
authorSimon Atanasyan <simon@atanasyan.com>2014-04-11 04:13:39 +0000
committerSimon Atanasyan <simon@atanasyan.com>2014-04-11 04:13:39 +0000
commiteb0c9094acd5f5a28c0adafb1784797d1d7a4e2d (patch)
treed94849c02e0a4a546c075081bb4ace35f0ea2937 /include/llvm/Object/ELFYAML.h
parent77cf856e56dc568ebe760e7de820323fdcf825a4 (diff)
downloadllvm-eb0c9094acd5f5a28c0adafb1784797d1d7a4e2d.tar.gz
llvm-eb0c9094acd5f5a28c0adafb1784797d1d7a4e2d.tar.bz2
llvm-eb0c9094acd5f5a28c0adafb1784797d1d7a4e2d.tar.xz
[yaml2obj][ELF] ELF Relocations Support.
The patch implements support for both relocation record formats: Elf_Rel and Elf_Rela. It is possible to define relocation against symbol only. Relocations against sections will be implemented later. Now yaml2obj recognizes X86_64, MIPS and Hexagon relocation types. Example of relocation section specification: Sections: - Name: .text Type: SHT_PROGBITS Content: "0000000000000000" AddressAlign: 16 Flags: [SHF_ALLOC] - Name: .rel.text Type: SHT_REL Info: .text AddressAlign: 4 Relocations: - Offset: 0x1 Symbol: glob1 Type: R_MIPS_32 - Offset: 0x2 Symbol: glob2 Type: R_MIPS_CALL16 The patch reviewed by Michael Spencer, Sean Silva, Shankar Easwaran. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206017 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Object/ELFYAML.h')
-rw-r--r--include/llvm/Object/ELFYAML.h44
1 files changed, 39 insertions, 5 deletions
diff --git a/include/llvm/Object/ELFYAML.h b/include/llvm/Object/ELFYAML.h
index 1eba660208..38707776ab 100644
--- a/include/llvm/Object/ELFYAML.h
+++ b/include/llvm/Object/ELFYAML.h
@@ -40,6 +40,7 @@ LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFOSABI)
// Just use 64, since it can hold 32-bit values too.
LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_EF)
LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_REL)
// Just use 64, since it can hold 32-bit values too.
LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
@@ -68,17 +69,40 @@ struct LocalGlobalWeakSymbols {
std::vector<Symbol> Weak;
};
struct Section {
+ enum class SectionKind { RawContent, Relocation };
+ SectionKind Kind;
StringRef Name;
ELF_SHT Type;
ELF_SHF Flags;
llvm::yaml::Hex64 Address;
- object::yaml::BinaryRef Content;
StringRef Link;
+ StringRef Info;
llvm::yaml::Hex64 AddressAlign;
+ Section(SectionKind Kind) : Kind(Kind) {}
+};
+struct RawContentSection : Section {
+ object::yaml::BinaryRef Content;
+ RawContentSection() : Section(SectionKind::RawContent) {}
+ static bool classof(const Section *S) {
+ return S->Kind == SectionKind::RawContent;
+ }
+};
+struct Relocation {
+ uint32_t Offset;
+ uint32_t Addend;
+ 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;
+ }
};
struct Object {
FileHeader Header;
- std::vector<Section> Sections;
+ std::vector<std::unique_ptr<Section>> Sections;
// 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
@@ -89,8 +113,9 @@ struct Object {
} // end namespace ELFYAML
} // end namespace llvm
-LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Section)
+LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::ELFYAML::Section>)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Symbol)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Relocation)
namespace llvm {
namespace yaml {
@@ -141,6 +166,11 @@ struct ScalarEnumerationTraits<ELFYAML::ELF_STT> {
};
template <>
+struct ScalarEnumerationTraits<ELFYAML::ELF_REL> {
+ static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
+};
+
+template <>
struct MappingTraits<ELFYAML::FileHeader> {
static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr);
};
@@ -155,9 +185,13 @@ struct MappingTraits<ELFYAML::LocalGlobalWeakSymbols> {
static void mapping(IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols);
};
+template <> struct MappingTraits<ELFYAML::Relocation> {
+ static void mapping(IO &IO, ELFYAML::Relocation &Rel);
+};
+
template <>
-struct MappingTraits<ELFYAML::Section> {
- static void mapping(IO &IO, ELFYAML::Section &Section);
+struct MappingTraits<std::unique_ptr<ELFYAML::Section>> {
+ static void mapping(IO &IO, std::unique_ptr<ELFYAML::Section> &Section);
};
template <>