[AVR] Add ELF constants to headers
authorDylan McKay <dylanmckay34@gmail.com>
Fri, 23 Oct 2015 06:05:55 +0000 (06:05 +0000)
committerDylan McKay <dylanmckay34@gmail.com>
Fri, 23 Oct 2015 06:05:55 +0000 (06:05 +0000)
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.

llvm-svn: 251096

llvm/include/llvm/Object/ELFObjectFile.h
llvm/include/llvm/Support/ELF.h
llvm/include/llvm/Support/ELFRelocs/AVR.def [new file with mode: 0644]
llvm/lib/Object/ELFYAML.cpp
llvm/test/Object/Inputs/trivial-object-test.elf-avr [new file with mode: 0755]
llvm/test/Object/obj2yaml.test

index 3a9739a..c5d1bb2 100644 (file)
@@ -829,6 +829,8 @@ StringRef ELFObjectFile<ELFT>::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<ELFT>::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:
index 57db13a..6245bbb 100644 (file)
@@ -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/llvm/include/llvm/Support/ELFRelocs/AVR.def b/llvm/include/llvm/Support/ELFRelocs/AVR.def
new file mode 100644 (file)
index 0000000..5692d6c
--- /dev/null
@@ -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)
index 7a9cf6f..6866b4d 100644 (file)
@@ -317,6 +317,25 @@ void ScalarBitSetTraits<ELFYAML::ELF_EF>::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/llvm/test/Object/Inputs/trivial-object-test.elf-avr b/llvm/test/Object/Inputs/trivial-object-test.elf-avr
new file mode 100755 (executable)
index 0000000..e0ff8a3
Binary files /dev/null and b/llvm/test/Object/Inputs/trivial-object-test.elf-avr differ
index 39c51c2..60d46a8 100644 (file)
@@ -3,6 +3,7 @@ RUN: obj2yaml %p/Inputs/trivial-object-test.coff-x86-64 | FileCheck %s --check-p
 RUN: obj2yaml %p/Inputs/trivial-object-test.elf-mipsel | FileCheck %s --check-prefix ELF-MIPSEL
 RUN: obj2yaml %p/Inputs/trivial-object-test.elf-mips64el | FileCheck %s --check-prefix ELF-MIPS64EL
 RUN: obj2yaml %p/Inputs/trivial-object-test.elf-x86-64 | FileCheck %s --check-prefix ELF-X86-64
+RUN: obj2yaml %p/Inputs/trivial-object-test.elf-avr | FileCheck %s --check-prefix ELF-AVR
 RUN: obj2yaml %p/Inputs/unwind-section.elf-x86-64 \
 RUN:   | FileCheck %s --check-prefix ELF-X86-64-UNWIND
 
@@ -409,6 +410,67 @@ ELF-X86-64-NEXT:       Size:            0x0000000000000026
 ELF-X86-64-NEXT:     - Name:            SomeOtherFunction
 ELF-X86-64-NEXT:     - Name:            puts
 
+
+ELF-AVR:      FileHeader:      
+ELF-AVR-NEXT:   Class:           ELFCLASS32
+ELF-AVR-NEXT:   Data:            ELFDATA2LSB
+ELF-AVR-NEXT:   Type:            ET_EXEC
+ELF-AVR-NEXT:   Machine:         EM_AVR
+ELF-AVR-NEXT:   Flags:           [ EF_AVR_ARCH_AVR2 ]
+ELF-AVR-NEXT: Sections:        
+ELF-AVR-NEXT:   - Name:            .text
+ELF-AVR-NEXT:     Type:            SHT_PROGBITS
+ELF-AVR-NEXT:     Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+ELF-AVR-NEXT:     AddressAlign:    0x0000000000000002
+ELF-AVR-NEXT:     Content:         C20E0895
+ELF-AVR-NEXT:   - Name:            .data
+ELF-AVR-NEXT:     Type:            SHT_PROGBITS
+ELF-AVR-NEXT:     Flags:           [ SHF_WRITE, SHF_ALLOC ]
+ELF-AVR-NEXT:     Address:         0x0000000000800060
+ELF-AVR-NEXT:     AddressAlign:    0x0000000000000001
+ELF-AVR-NEXT:     Content:         ''
+ELF-AVR-NEXT: Symbols:         
+ELF-AVR-NEXT:   Local:           
+ELF-AVR-NEXT:     - Type:            STT_SECTION
+ELF-AVR-NEXT:       Section:         .text
+ELF-AVR-NEXT:     - Type:            STT_SECTION
+ELF-AVR-NEXT:       Section:         .data
+ELF-AVR-NEXT:       Value:           0x0000000000800060
+ELF-AVR-NEXT:     - Name:            a.o
+ELF-AVR-NEXT:       Type:            STT_FILE
+ELF-AVR-NEXT:     - Name:            main
+ELF-AVR-NEXT:       Section:         .text
+ELF-AVR-NEXT:   Global:          
+ELF-AVR-NEXT:     - Name:            __trampolines_start
+ELF-AVR-NEXT:       Section:         .text
+ELF-AVR-NEXT:     - Name:            _etext
+ELF-AVR-NEXT:       Section:         .text
+ELF-AVR-NEXT:       Value:           0x0000000000000004
+ELF-AVR-NEXT:     - Name:            __data_load_end
+ELF-AVR-NEXT:       Value:           0x0000000000000004
+ELF-AVR-NEXT:     - Name:            __trampolines_end
+ELF-AVR-NEXT:       Section:         .text
+ELF-AVR-NEXT:     - Name:            __data_load_start
+ELF-AVR-NEXT:       Value:           0x0000000000000004
+ELF-AVR-NEXT:     - Name:            __dtors_end
+ELF-AVR-NEXT:       Section:         .text
+ELF-AVR-NEXT:     - Name:            __eeprom_end
+ELF-AVR-NEXT:       Section:         .data
+ELF-AVR-NEXT:       Value:           0x0000000000810000
+ELF-AVR-NEXT:     - Name:            __ctors_start
+ELF-AVR-NEXT:       Section:         .text
+ELF-AVR-NEXT:     - Name:            __dtors_start
+ELF-AVR-NEXT:       Section:         .text
+ELF-AVR-NEXT:     - Name:            __ctors_end
+ELF-AVR-NEXT:       Section:         .text
+ELF-AVR-NEXT:     - Name:            _edata
+ELF-AVR-NEXT:       Section:         .data
+ELF-AVR-NEXT:       Value:           0x0000000000800060
+ELF-AVR-NEXT:     - Name:            _end
+ELF-AVR-NEXT:       Section:         .data
+ELF-AVR-NEXT:       Value:           0x0000000000800060
+
+
 ELF-X86-64-UNWIND:      - Name:            .eh_frame
 ELF-X86-64-UNWIND-NEXT:   Type:            SHT_X86_64_UNWIND
 ELF-X86-64-UNWIND-NEXT:   Flags:           [ SHF_ALLOC ]