From bd1e97920ae282c0a8353173941ef5cef44c94cd Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Fri, 23 Oct 2015 06:05:55 +0000 Subject: [PATCH] [AVR] Add ELF constants to headers Also adds a 'trivial' ELF file. This was generated by assembling and linking a file with the symbol main which contains a single return instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251096 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/ELFObjectFile.h | 4 ++ include/llvm/Support/ELF.h | 27 ++++++++ include/llvm/Support/ELFRelocs/AVR.def | 40 +++++++++++ lib/Object/ELFYAML.cpp | 19 ++++++ .../Object/Inputs/trivial-object-test.elf-avr | Bin 0 -> 840 bytes test/Object/obj2yaml.test | 62 ++++++++++++++++++ 6 files changed, 152 insertions(+) create mode 100644 include/llvm/Support/ELFRelocs/AVR.def create mode 100755 test/Object/Inputs/trivial-object-test.elf-avr diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index 3a9739afbeb..c5d1bb29dd8 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -829,6 +829,8 @@ StringRef ELFObjectFile::getFileFormatName() const { return "ELF32-x86-64"; case ELF::EM_ARM: return (IsLittleEndian ? "ELF32-arm-little" : "ELF32-arm-big"); + case ELF::EM_AVR: + return "ELF32-avr"; case ELF::EM_HEXAGON: return "ELF32-hexagon"; case ELF::EM_MIPS: @@ -878,6 +880,8 @@ unsigned ELFObjectFile::getArch() const { return Triple::aarch64; case ELF::EM_ARM: return Triple::arm; + case ELF::EM_AVR: + return Triple::avr; case ELF::EM_HEXAGON: return Triple::hexagon; case ELF::EM_MIPS: diff --git a/include/llvm/Support/ELF.h b/include/llvm/Support/ELF.h index 57db13ae24a..6245bbb29ad 100644 --- a/include/llvm/Support/ELF.h +++ b/include/llvm/Support/ELF.h @@ -429,6 +429,33 @@ enum { #include "ELFRelocs/ARM.def" }; +// AVR specific e_flags +enum : unsigned { + EF_AVR_ARCH_AVR1 = 1, + EF_AVR_ARCH_AVR2 = 2, + EF_AVR_ARCH_AVR25 = 25, + EF_AVR_ARCH_AVR3 = 3, + EF_AVR_ARCH_AVR31 = 31, + EF_AVR_ARCH_AVR35 = 35, + EF_AVR_ARCH_AVR4 = 4, + EF_AVR_ARCH_AVR5 = 5, + EF_AVR_ARCH_AVR51 = 51, + EF_AVR_ARCH_AVR6 = 6, + EF_AVR_ARCH_AVRTINY = 100, + EF_AVR_ARCH_XMEGA1 = 101, + EF_AVR_ARCH_XMEGA2 = 102, + EF_AVR_ARCH_XMEGA3 = 103, + EF_AVR_ARCH_XMEGA4 = 104, + EF_AVR_ARCH_XMEGA5 = 105, + EF_AVR_ARCH_XMEGA6 = 106, + EF_AVR_ARCH_XMEGA7 = 107 +}; + +// ELF Relocation types for AVR +enum { +#include "ELFRelocs/AVR.def" +}; + // Mips Specific e_flags enum : unsigned { EF_MIPS_NOREORDER = 0x00000001, // Don't reorder instructions diff --git a/include/llvm/Support/ELFRelocs/AVR.def b/include/llvm/Support/ELFRelocs/AVR.def new file mode 100644 index 00000000000..5692d6cb9aa --- /dev/null +++ b/include/llvm/Support/ELFRelocs/AVR.def @@ -0,0 +1,40 @@ + +#ifndef ELF_RELOC +#error "ELF_RELOC must be defined" +#endif + +ELF_RELOC(R_AVR_NONE, 0) +ELF_RELOC(R_AVR_32, 1) +ELF_RELOC(R_AVR_7_PCREL, 2) +ELF_RELOC(R_AVR_13_PCREL, 3) +ELF_RELOC(R_AVR_16, 4) +ELF_RELOC(R_AVR_16_PM, 5) +ELF_RELOC(R_AVR_LO8_LDI, 6) +ELF_RELOC(R_AVR_HI8_LDI, 7) +ELF_RELOC(R_AVR_HH8_LDI, 8) +ELF_RELOC(R_AVR_LO8_LDI_NEG, 9) +ELF_RELOC(R_AVR_HI8_LDI_NEG, 10) +ELF_RELOC(R_AVR_HH8_LDI_NEG, 11) +ELF_RELOC(R_AVR_LO8_LDI_PM, 12) +ELF_RELOC(R_AVR_HI8_LDI_PM, 13) +ELF_RELOC(R_AVR_HH8_LDI_PM, 14) +ELF_RELOC(R_AVR_LO8_LDI_PM_NEG, 15) +ELF_RELOC(R_AVR_HI8_LDI_PM_NEG, 16) +ELF_RELOC(R_AVR_HH8_LDI_PM_NEG, 17) +ELF_RELOC(R_AVR_CALL, 18) +ELF_RELOC(R_AVR_LDI, 19) +ELF_RELOC(R_AVR_6, 20) +ELF_RELOC(R_AVR_6_ADIW, 21) +ELF_RELOC(R_AVR_MS8_LDI, 22) +ELF_RELOC(R_AVR_MS8_LDI_NEG, 23) +ELF_RELOC(R_AVR_LO8_LDI_GS, 24) +ELF_RELOC(R_AVR_HI8_LDI_GS, 25) +ELF_RELOC(R_AVR_8, 26) +ELF_RELOC(R_AVR_8_LO8, 27) +ELF_RELOC(R_AVR_8_HI8, 28) +ELF_RELOC(R_AVR_8_HLO8, 29) +ELF_RELOC(R_AVR_SYM_DIFF, 30) +ELF_RELOC(R_AVR_16_LDST, 31) +ELF_RELOC(R_AVR_LDS_STS_16, 33) +ELF_RELOC(R_AVR_PORT6, 34) +ELF_RELOC(R_AVR_PORT5, 35) diff --git a/lib/Object/ELFYAML.cpp b/lib/Object/ELFYAML.cpp index 7a9cf6fcf9f..6866b4d7844 100644 --- a/lib/Object/ELFYAML.cpp +++ b/lib/Object/ELFYAML.cpp @@ -317,6 +317,25 @@ void ScalarBitSetTraits::bitset(IO &IO, BCase(EF_HEXAGON_ISA_V4) BCase(EF_HEXAGON_ISA_V5) break; + case ELF::EM_AVR: + BCase(EF_AVR_ARCH_AVR1) + BCase(EF_AVR_ARCH_AVR2) + BCase(EF_AVR_ARCH_AVR25) + BCase(EF_AVR_ARCH_AVR3) + BCase(EF_AVR_ARCH_AVR31) + BCase(EF_AVR_ARCH_AVR35) + BCase(EF_AVR_ARCH_AVR4) + BCase(EF_AVR_ARCH_AVR51) + BCase(EF_AVR_ARCH_AVR6) + BCase(EF_AVR_ARCH_AVRTINY) + BCase(EF_AVR_ARCH_XMEGA1) + BCase(EF_AVR_ARCH_XMEGA2) + BCase(EF_AVR_ARCH_XMEGA3) + BCase(EF_AVR_ARCH_XMEGA4) + BCase(EF_AVR_ARCH_XMEGA5) + BCase(EF_AVR_ARCH_XMEGA6) + BCase(EF_AVR_ARCH_XMEGA7) + break; default: llvm_unreachable("Unsupported architecture"); } diff --git a/test/Object/Inputs/trivial-object-test.elf-avr b/test/Object/Inputs/trivial-object-test.elf-avr new file mode 100755 index 0000000000000000000000000000000000000000..e0ff8a3d55692d0699c8bab3318ccd128fb5fac0 GIT binary patch literal 840 zcma)4F;2rk5L_oA0t#emBm@P5Dphy_(9qF9bvf`!M2h3cz9Liv9zaJ!1r0TC;755u zn7Q-H!4eW9?d{FY+exVr zJ?L}fkt~9SZ9pF@Yk%)-zRI9_$i2Nq_GQfXy7O-CWsq5Kbq+B(mKQN#WiHXa5BG5pu(qtJ9#wh5AKHziH_%@Tah*=%;Myixz)r@i*`h=0@=T z2l6@>J18W#&05xY(m3j?Ci6vE)qdw@ zWs%q9E(pJE%AyuZy70%sozVWjmOZ%m&-gY7zAK$SIo}g;h@h{F;5_)g)