diff options
Diffstat (limited to 'lib/Object/ELFYAML.cpp')
-rw-r--r-- | lib/Object/ELFYAML.cpp | 409 |
1 files changed, 76 insertions, 333 deletions
diff --git a/lib/Object/ELFYAML.cpp b/lib/Object/ELFYAML.cpp index f513c11..cce05cf 100644 --- a/lib/Object/ELFYAML.cpp +++ b/lib/Object/ELFYAML.cpp @@ -30,6 +30,7 @@ ScalarEnumerationTraits<ELFYAML::ELF_ET>::enumeration(IO &IO, ECase(ET_DYN) ECase(ET_CORE) #undef ECase + IO.enumFallback<Hex16>(Value); } void @@ -414,354 +415,44 @@ void ScalarBitSetTraits<ELFYAML::ELF_STO>::bitset(IO &IO, #undef BCaseMask } +void ScalarEnumerationTraits<ELFYAML::ELF_RSS>::enumeration( + IO &IO, ELFYAML::ELF_RSS &Value) { +#define ECase(X) IO.enumCase(Value, #X, ELF::X); + ECase(RSS_UNDEF) + ECase(RSS_GP) + ECase(RSS_GP0) + ECase(RSS_LOC) +#undef ECase +} + void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration( IO &IO, ELFYAML::ELF_REL &Value) { const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); assert(Object && "The IO context is not initialized"); -#define ECase(X) IO.enumCase(Value, #X, ELF::X); +#define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X); switch (Object->Header.Machine) { case ELF::EM_X86_64: - ECase(R_X86_64_NONE) - ECase(R_X86_64_64) - ECase(R_X86_64_PC32) - ECase(R_X86_64_GOT32) - ECase(R_X86_64_PLT32) - ECase(R_X86_64_COPY) - ECase(R_X86_64_GLOB_DAT) - ECase(R_X86_64_JUMP_SLOT) - ECase(R_X86_64_RELATIVE) - ECase(R_X86_64_GOTPCREL) - ECase(R_X86_64_32) - ECase(R_X86_64_32S) - ECase(R_X86_64_16) - ECase(R_X86_64_PC16) - ECase(R_X86_64_8) - ECase(R_X86_64_PC8) - ECase(R_X86_64_DTPMOD64) - ECase(R_X86_64_DTPOFF64) - ECase(R_X86_64_TPOFF64) - ECase(R_X86_64_TLSGD) - ECase(R_X86_64_TLSLD) - ECase(R_X86_64_DTPOFF32) - ECase(R_X86_64_GOTTPOFF) - ECase(R_X86_64_TPOFF32) - ECase(R_X86_64_PC64) - ECase(R_X86_64_GOTOFF64) - ECase(R_X86_64_GOTPC32) - ECase(R_X86_64_GOT64) - ECase(R_X86_64_GOTPCREL64) - ECase(R_X86_64_GOTPC64) - ECase(R_X86_64_GOTPLT64) - ECase(R_X86_64_PLTOFF64) - ECase(R_X86_64_SIZE32) - ECase(R_X86_64_SIZE64) - ECase(R_X86_64_GOTPC32_TLSDESC) - ECase(R_X86_64_TLSDESC_CALL) - ECase(R_X86_64_TLSDESC) - ECase(R_X86_64_IRELATIVE) +#include "llvm/Support/ELFRelocs/x86_64.def" break; case ELF::EM_MIPS: - ECase(R_MIPS_NONE) - ECase(R_MIPS_16) - ECase(R_MIPS_32) - ECase(R_MIPS_REL32) - ECase(R_MIPS_26) - ECase(R_MIPS_HI16) - ECase(R_MIPS_LO16) - ECase(R_MIPS_GPREL16) - ECase(R_MIPS_LITERAL) - ECase(R_MIPS_GOT16) - ECase(R_MIPS_PC16) - ECase(R_MIPS_CALL16) - ECase(R_MIPS_GPREL32) - ECase(R_MIPS_UNUSED1) - ECase(R_MIPS_UNUSED2) - ECase(R_MIPS_SHIFT5) - ECase(R_MIPS_SHIFT6) - ECase(R_MIPS_64) - ECase(R_MIPS_GOT_DISP) - ECase(R_MIPS_GOT_PAGE) - ECase(R_MIPS_GOT_OFST) - ECase(R_MIPS_GOT_HI16) - ECase(R_MIPS_GOT_LO16) - ECase(R_MIPS_SUB) - ECase(R_MIPS_INSERT_A) - ECase(R_MIPS_INSERT_B) - ECase(R_MIPS_DELETE) - ECase(R_MIPS_HIGHER) - ECase(R_MIPS_HIGHEST) - ECase(R_MIPS_CALL_HI16) - ECase(R_MIPS_CALL_LO16) - ECase(R_MIPS_SCN_DISP) - ECase(R_MIPS_REL16) - ECase(R_MIPS_ADD_IMMEDIATE) - ECase(R_MIPS_PJUMP) - ECase(R_MIPS_RELGOT) - ECase(R_MIPS_JALR) - ECase(R_MIPS_TLS_DTPMOD32) - ECase(R_MIPS_TLS_DTPREL32) - ECase(R_MIPS_TLS_DTPMOD64) - ECase(R_MIPS_TLS_DTPREL64) - ECase(R_MIPS_TLS_GD) - ECase(R_MIPS_TLS_LDM) - ECase(R_MIPS_TLS_DTPREL_HI16) - ECase(R_MIPS_TLS_DTPREL_LO16) - ECase(R_MIPS_TLS_GOTTPREL) - ECase(R_MIPS_TLS_TPREL32) - ECase(R_MIPS_TLS_TPREL64) - ECase(R_MIPS_TLS_TPREL_HI16) - ECase(R_MIPS_TLS_TPREL_LO16) - ECase(R_MIPS_GLOB_DAT) - ECase(R_MIPS_PC21_S2) - ECase(R_MIPS_PC26_S2) - ECase(R_MIPS_PC18_S3) - ECase(R_MIPS_PC19_S2) - ECase(R_MIPS_PCHI16) - ECase(R_MIPS_PCLO16) - ECase(R_MIPS16_GOT16) - ECase(R_MIPS16_HI16) - ECase(R_MIPS16_LO16) - ECase(R_MIPS_COPY) - ECase(R_MIPS_JUMP_SLOT) - ECase(R_MICROMIPS_26_S1) - ECase(R_MICROMIPS_HI16) - ECase(R_MICROMIPS_LO16) - ECase(R_MICROMIPS_GOT16) - ECase(R_MICROMIPS_PC16_S1) - ECase(R_MICROMIPS_CALL16) - ECase(R_MICROMIPS_GOT_DISP) - ECase(R_MICROMIPS_GOT_PAGE) - ECase(R_MICROMIPS_GOT_OFST) - ECase(R_MICROMIPS_TLS_GD) - ECase(R_MICROMIPS_TLS_LDM) - ECase(R_MICROMIPS_TLS_DTPREL_HI16) - ECase(R_MICROMIPS_TLS_DTPREL_LO16) - ECase(R_MICROMIPS_TLS_TPREL_HI16) - ECase(R_MICROMIPS_TLS_TPREL_LO16) - ECase(R_MIPS_NUM) - ECase(R_MIPS_PC32) +#include "llvm/Support/ELFRelocs/Mips.def" break; case ELF::EM_HEXAGON: - ECase(R_HEX_NONE) - ECase(R_HEX_B22_PCREL) - ECase(R_HEX_B15_PCREL) - ECase(R_HEX_B7_PCREL) - ECase(R_HEX_LO16) - ECase(R_HEX_HI16) - ECase(R_HEX_32) - ECase(R_HEX_16) - ECase(R_HEX_8) - ECase(R_HEX_GPREL16_0) - ECase(R_HEX_GPREL16_1) - ECase(R_HEX_GPREL16_2) - ECase(R_HEX_GPREL16_3) - ECase(R_HEX_HL16) - ECase(R_HEX_B13_PCREL) - ECase(R_HEX_B9_PCREL) - ECase(R_HEX_B32_PCREL_X) - ECase(R_HEX_32_6_X) - ECase(R_HEX_B22_PCREL_X) - ECase(R_HEX_B15_PCREL_X) - ECase(R_HEX_B13_PCREL_X) - ECase(R_HEX_B9_PCREL_X) - ECase(R_HEX_B7_PCREL_X) - ECase(R_HEX_16_X) - ECase(R_HEX_12_X) - ECase(R_HEX_11_X) - ECase(R_HEX_10_X) - ECase(R_HEX_9_X) - ECase(R_HEX_8_X) - ECase(R_HEX_7_X) - ECase(R_HEX_6_X) - ECase(R_HEX_32_PCREL) - ECase(R_HEX_COPY) - ECase(R_HEX_GLOB_DAT) - ECase(R_HEX_JMP_SLOT) - ECase(R_HEX_RELATIVE) - ECase(R_HEX_PLT_B22_PCREL) - ECase(R_HEX_GOTREL_LO16) - ECase(R_HEX_GOTREL_HI16) - ECase(R_HEX_GOTREL_32) - ECase(R_HEX_GOT_LO16) - ECase(R_HEX_GOT_HI16) - ECase(R_HEX_GOT_32) - ECase(R_HEX_GOT_16) - ECase(R_HEX_DTPMOD_32) - ECase(R_HEX_DTPREL_LO16) - ECase(R_HEX_DTPREL_HI16) - ECase(R_HEX_DTPREL_32) - ECase(R_HEX_DTPREL_16) - ECase(R_HEX_GD_PLT_B22_PCREL) - ECase(R_HEX_GD_GOT_LO16) - ECase(R_HEX_GD_GOT_HI16) - ECase(R_HEX_GD_GOT_32) - ECase(R_HEX_GD_GOT_16) - ECase(R_HEX_IE_LO16) - ECase(R_HEX_IE_HI16) - ECase(R_HEX_IE_32) - ECase(R_HEX_IE_GOT_LO16) - ECase(R_HEX_IE_GOT_HI16) - ECase(R_HEX_IE_GOT_32) - ECase(R_HEX_IE_GOT_16) - ECase(R_HEX_TPREL_LO16) - ECase(R_HEX_TPREL_HI16) - ECase(R_HEX_TPREL_32) - ECase(R_HEX_TPREL_16) - ECase(R_HEX_6_PCREL_X) - ECase(R_HEX_GOTREL_32_6_X) - ECase(R_HEX_GOTREL_16_X) - ECase(R_HEX_GOTREL_11_X) - ECase(R_HEX_GOT_32_6_X) - ECase(R_HEX_GOT_16_X) - ECase(R_HEX_GOT_11_X) - ECase(R_HEX_DTPREL_32_6_X) - ECase(R_HEX_DTPREL_16_X) - ECase(R_HEX_DTPREL_11_X) - ECase(R_HEX_GD_GOT_32_6_X) - ECase(R_HEX_GD_GOT_16_X) - ECase(R_HEX_GD_GOT_11_X) - ECase(R_HEX_IE_32_6_X) - ECase(R_HEX_IE_16_X) - ECase(R_HEX_IE_GOT_32_6_X) - ECase(R_HEX_IE_GOT_16_X) - ECase(R_HEX_IE_GOT_11_X) - ECase(R_HEX_TPREL_32_6_X) - ECase(R_HEX_TPREL_16_X) - ECase(R_HEX_TPREL_11_X) +#include "llvm/Support/ELFRelocs/Hexagon.def" break; case ELF::EM_386: - ECase(R_386_NONE) - ECase(R_386_32) - ECase(R_386_PC32) - ECase(R_386_GOT32) - ECase(R_386_PLT32) - ECase(R_386_COPY) - ECase(R_386_GLOB_DAT) - ECase(R_386_JUMP_SLOT) - ECase(R_386_RELATIVE) - ECase(R_386_GOTOFF) - ECase(R_386_GOTPC) - ECase(R_386_32PLT) - ECase(R_386_TLS_TPOFF) - ECase(R_386_TLS_IE) - ECase(R_386_TLS_GOTIE) - ECase(R_386_TLS_LE) - ECase(R_386_TLS_GD) - ECase(R_386_TLS_LDM) - ECase(R_386_16) - ECase(R_386_PC16) - ECase(R_386_8) - ECase(R_386_PC8) - ECase(R_386_TLS_GD_32) - ECase(R_386_TLS_GD_PUSH) - ECase(R_386_TLS_GD_CALL) - ECase(R_386_TLS_GD_POP) - ECase(R_386_TLS_LDM_32) - ECase(R_386_TLS_LDM_PUSH) - ECase(R_386_TLS_LDM_CALL) - ECase(R_386_TLS_LDM_POP) - ECase(R_386_TLS_LDO_32) - ECase(R_386_TLS_IE_32) - ECase(R_386_TLS_LE_32) - ECase(R_386_TLS_DTPMOD32) - ECase(R_386_TLS_DTPOFF32) - ECase(R_386_TLS_TPOFF32) - ECase(R_386_TLS_GOTDESC) - ECase(R_386_TLS_DESC_CALL) - ECase(R_386_TLS_DESC) - ECase(R_386_IRELATIVE) - ECase(R_386_NUM) +#include "llvm/Support/ELFRelocs/i386.def" break; case ELF::EM_AARCH64: - ECase(R_AARCH64_NONE) - ECase(R_AARCH64_ABS64) - ECase(R_AARCH64_ABS32) - ECase(R_AARCH64_ABS16) - ECase(R_AARCH64_PREL64) - ECase(R_AARCH64_PREL32) - ECase(R_AARCH64_PREL16) - ECase(R_AARCH64_MOVW_UABS_G0) - ECase(R_AARCH64_MOVW_UABS_G0_NC) - ECase(R_AARCH64_MOVW_UABS_G1) - ECase(R_AARCH64_MOVW_UABS_G1_NC) - ECase(R_AARCH64_MOVW_UABS_G2) - ECase(R_AARCH64_MOVW_UABS_G2_NC) - ECase(R_AARCH64_MOVW_UABS_G3) - ECase(R_AARCH64_MOVW_SABS_G0) - ECase(R_AARCH64_MOVW_SABS_G1) - ECase(R_AARCH64_MOVW_SABS_G2) - ECase(R_AARCH64_LD_PREL_LO19) - ECase(R_AARCH64_ADR_PREL_LO21) - ECase(R_AARCH64_ADR_PREL_PG_HI21) - ECase(R_AARCH64_ADD_ABS_LO12_NC) - ECase(R_AARCH64_LDST8_ABS_LO12_NC) - ECase(R_AARCH64_TSTBR14) - ECase(R_AARCH64_CONDBR19) - ECase(R_AARCH64_JUMP26) - ECase(R_AARCH64_CALL26) - ECase(R_AARCH64_LDST16_ABS_LO12_NC) - ECase(R_AARCH64_LDST32_ABS_LO12_NC) - ECase(R_AARCH64_LDST64_ABS_LO12_NC) - ECase(R_AARCH64_LDST128_ABS_LO12_NC) - ECase(R_AARCH64_GOTREL64) - ECase(R_AARCH64_GOTREL32) - ECase(R_AARCH64_ADR_GOT_PAGE) - ECase(R_AARCH64_LD64_GOT_LO12_NC) - ECase(R_AARCH64_TLSLD_MOVW_DTPREL_G2) - ECase(R_AARCH64_TLSLD_MOVW_DTPREL_G1) - ECase(R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC) - ECase(R_AARCH64_TLSLD_MOVW_DTPREL_G0) - ECase(R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC) - ECase(R_AARCH64_TLSLD_ADD_DTPREL_HI12) - ECase(R_AARCH64_TLSLD_ADD_DTPREL_LO12) - ECase(R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC) - ECase(R_AARCH64_TLSLD_LDST8_DTPREL_LO12) - ECase(R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC) - ECase(R_AARCH64_TLSLD_LDST16_DTPREL_LO12) - ECase(R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC) - ECase(R_AARCH64_TLSLD_LDST32_DTPREL_LO12) - ECase(R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC) - ECase(R_AARCH64_TLSLD_LDST64_DTPREL_LO12) - ECase(R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC) - ECase(R_AARCH64_TLSIE_MOVW_GOTTPREL_G1) - ECase(R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC) - ECase(R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21) - ECase(R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC) - ECase(R_AARCH64_TLSIE_LD_GOTTPREL_PREL19) - ECase(R_AARCH64_TLSLE_MOVW_TPREL_G2) - ECase(R_AARCH64_TLSLE_MOVW_TPREL_G1) - ECase(R_AARCH64_TLSLE_MOVW_TPREL_G1_NC) - ECase(R_AARCH64_TLSLE_MOVW_TPREL_G0) - ECase(R_AARCH64_TLSLE_MOVW_TPREL_G0_NC) - ECase(R_AARCH64_TLSLE_ADD_TPREL_HI12) - ECase(R_AARCH64_TLSLE_ADD_TPREL_LO12) - ECase(R_AARCH64_TLSLE_ADD_TPREL_LO12_NC) - ECase(R_AARCH64_TLSLE_LDST8_TPREL_LO12) - ECase(R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC) - ECase(R_AARCH64_TLSLE_LDST16_TPREL_LO12) - ECase(R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC) - ECase(R_AARCH64_TLSLE_LDST32_TPREL_LO12) - ECase(R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC) - ECase(R_AARCH64_TLSLE_LDST64_TPREL_LO12) - ECase(R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC) - ECase(R_AARCH64_TLSDESC_ADR_PAGE) - ECase(R_AARCH64_TLSDESC_LD64_LO12_NC) - ECase(R_AARCH64_TLSDESC_ADD_LO12_NC) - ECase(R_AARCH64_TLSDESC_CALL) - ECase(R_AARCH64_COPY) - ECase(R_AARCH64_GLOB_DAT) - ECase(R_AARCH64_JUMP_SLOT) - ECase(R_AARCH64_RELATIVE) - ECase(R_AARCH64_TLS_DTPREL64) - ECase(R_AARCH64_TLS_DTPMOD64) - ECase(R_AARCH64_TLS_TPREL64) - ECase(R_AARCH64_TLSDESC) - ECase(R_AARCH64_IRELATIVE) +#include "llvm/Support/ELFRelocs/AArch64.def" + break; + case ELF::EM_ARM: +#include "llvm/Support/ELFRelocs/ARM.def" break; default: llvm_unreachable("Unsupported architecture"); } -#undef ECase +#undef ELF_RELOC } void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO, @@ -815,6 +506,7 @@ static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) { IO.mapOptional("Address", Section.Address, Hex64(0)); IO.mapOptional("Link", Section.Link, StringRef()); IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0)); + IO.mapOptional("Info", Section.Info, StringRef()); } static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) { @@ -825,10 +517,19 @@ static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) { static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) { commonSectionMapping(IO, Section); - IO.mapOptional("Info", Section.Info, StringRef()); IO.mapOptional("Relocations", Section.Relocations); } +static void groupSectionMapping(IO &IO, ELFYAML::Group &group) { + commonSectionMapping(IO, group); + IO.mapRequired("Members", group.Members); +} + +void MappingTraits<ELFYAML::SectionOrType>::mapping( + IO &IO, ELFYAML::SectionOrType §ionOrType) { + IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType); +} + void MappingTraits<std::unique_ptr<ELFYAML::Section>>::mapping( IO &IO, std::unique_ptr<ELFYAML::Section> &Section) { ELFYAML::ELF_SHT sectionType; @@ -844,6 +545,11 @@ void MappingTraits<std::unique_ptr<ELFYAML::Section>>::mapping( Section.reset(new ELFYAML::RelocationSection()); sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get())); break; + case ELF::SHT_GROUP: + if (!IO.outputting()) + Section.reset(new ELFYAML::Group()); + groupSectionMapping(IO, *cast<ELFYAML::Group>(Section.get())); + break; default: if (!IO.outputting()) Section.reset(new ELFYAML::RawContentSection()); @@ -859,12 +565,49 @@ StringRef MappingTraits<std::unique_ptr<ELFYAML::Section>>::validate( return "Section size must be greater or equal to the content size"; } +namespace { +struct NormalizedMips64RelType { + NormalizedMips64RelType(IO &) + : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)), + Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)), + Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)), + SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {} + NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original) + : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF), + Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {} + + ELFYAML::ELF_REL denormalize(IO &) { + ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24; + return Res; + } + + ELFYAML::ELF_REL Type; + ELFYAML::ELF_REL Type2; + ELFYAML::ELF_REL Type3; + ELFYAML::ELF_RSS SpecSym; +}; +} + void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO, ELFYAML::Relocation &Rel) { + const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); + assert(Object && "The IO context is not initialized"); + IO.mapRequired("Offset", Rel.Offset); IO.mapRequired("Symbol", Rel.Symbol); - IO.mapRequired("Type", Rel.Type); - IO.mapOptional("Addend", Rel.Addend); + + if (Object->Header.Machine == ELFYAML::ELF_EM(ELF::EM_MIPS) && + Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) { + MappingNormalization<NormalizedMips64RelType, ELFYAML::ELF_REL> Key( + IO, Rel.Type); + IO.mapRequired("Type", Key->Type); + IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE)); + IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE)); + IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF)); + } else + IO.mapRequired("Type", Rel.Type); + + IO.mapOptional("Addend", Rel.Addend, (int64_t)0); } void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) { |