Index: llvm/trunk/include/llvm/Object/ELFObjectFile.h =================================================================== --- llvm/trunk/include/llvm/Object/ELFObjectFile.h +++ llvm/trunk/include/llvm/Object/ELFObjectFile.h @@ -835,6 +835,8 @@ return "ELF32-avr"; case ELF::EM_HEXAGON: return "ELF32-hexagon"; + case ELF::EM_LANAI: + return "ELF32-lanai"; case ELF::EM_MIPS: return "ELF32-mips"; case ELF::EM_PPC: @@ -891,6 +893,8 @@ return Triple::avr; case ELF::EM_HEXAGON: return Triple::hexagon; + case ELF::EM_LANAI: + return Triple::lanai; case ELF::EM_MIPS: switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) { case ELF::ELFCLASS32: Index: llvm/trunk/include/llvm/Object/RelocVisitor.h =================================================================== --- llvm/trunk/include/llvm/Object/RelocVisitor.h +++ llvm/trunk/include/llvm/Object/RelocVisitor.h @@ -175,6 +175,14 @@ case llvm::ELF::R_ARM_ABS32: return visitELF_ARM_ABS32(R, Value); } + case Triple::lanai: + switch (RelocType) { + case llvm::ELF::R_LANAI_32: + return visitELF_Lanai_32(R, Value); + default: + HasError = true; + return RelocToApply(); + } case Triple::mipsel: case Triple::mips: switch (RelocType) { @@ -311,6 +319,13 @@ return RelocToApply(Res, 4); } + /// Lanai ELF + RelocToApply visitELF_Lanai_32(RelocationRef R, uint64_t Value) { + int64_t Addend = getELFAddend(R); + uint32_t Res = (Value + Addend) & 0xFFFFFFFF; + return RelocToApply(Res, 4); + } + /// MIPS ELF RelocToApply visitELF_MIPS_32(RelocationRef R, uint64_t Value) { uint32_t Res = Value & 0xFFFFFFFF; Index: llvm/trunk/include/llvm/Support/ELF.h =================================================================== --- llvm/trunk/include/llvm/Support/ELF.h +++ llvm/trunk/include/llvm/Support/ELF.h @@ -315,6 +315,11 @@ // such numbers for an official value for WebAssembly. As soon as one is // allocated, this enum will be updated to use it. EM_WEBASSEMBLY = 0x4157, // WebAssembly architecture + + // A request has been made to the maintainer of the official registry for + // an official value for Lanai. As soon as one is allocated, this enum will be + // updated to use it. + EM_LANAI = 0x8123, // Lanai 32-bit processor }; // Object file classes. @@ -589,6 +594,11 @@ #include "ELFRelocs/Hexagon.def" }; +// ELF Relocation type for Lanai. +enum { +#include "ELFRelocs/Lanai.def" +}; + // ELF Relocation types for S390/zSeries enum { #include "ELFRelocs/SystemZ.def" Index: llvm/trunk/include/llvm/Support/ELFRelocs/Lanai.def =================================================================== --- llvm/trunk/include/llvm/Support/ELFRelocs/Lanai.def +++ llvm/trunk/include/llvm/Support/ELFRelocs/Lanai.def @@ -0,0 +1,19 @@ + +#ifndef ELF_RELOC +#error "ELF_RELOC must be defined" +#endif + +// No relocation +ELF_RELOC(R_LANAI_NONE, 0) +// 21-bit symbol relocation +ELF_RELOC(R_LANAI_21, 1) +// 21-bit symbol relocation with last two bits masked to 0 +ELF_RELOC(R_LANAI_21_F, 2) +// 25-bit branch targets +ELF_RELOC(R_LANAI_25, 3) +// General 32-bit relocation +ELF_RELOC(R_LANAI_32, 4) +// Upper 16-bits of a symbolic relocation +ELF_RELOC(R_LANAI_HI16, 5) +// Lower 16-bits of a symbolic relocation +ELF_RELOC(R_LANAI_LO16, 6) Index: llvm/trunk/lib/MC/MCObjectFileInfo.cpp =================================================================== --- llvm/trunk/lib/MC/MCObjectFileInfo.cpp +++ llvm/trunk/lib/MC/MCObjectFileInfo.cpp @@ -356,6 +356,11 @@ TTypeEncoding = dwarf::DW_EH_PE_absptr; } break; + case Triple::lanai: + LSDAEncoding = dwarf::DW_EH_PE_absptr; + PersonalityEncoding = dwarf::DW_EH_PE_absptr; + TTypeEncoding = dwarf::DW_EH_PE_absptr; + break; case Triple::mips: case Triple::mipsel: case Triple::mips64: Index: llvm/trunk/lib/Object/ELF.cpp =================================================================== --- llvm/trunk/lib/Object/ELF.cpp +++ llvm/trunk/lib/Object/ELF.cpp @@ -61,6 +61,13 @@ break; } break; + case ELF::EM_LANAI: + switch (Type) { +#include "llvm/Support/ELFRelocs/Lanai.def" + default: + break; + } + break; case ELF::EM_PPC: switch (Type) { #include "llvm/Support/ELFRelocs/PowerPC.def" Index: llvm/trunk/test/DebugInfo/Lanai/lit.local.cfg =================================================================== --- llvm/trunk/test/DebugInfo/Lanai/lit.local.cfg +++ llvm/trunk/test/DebugInfo/Lanai/lit.local.cfg @@ -0,0 +1,2 @@ +if not 'Lanai' in config.root.targets: + config.unsupported = True Index: llvm/trunk/test/DebugInfo/Lanai/processes-relocations.ll =================================================================== --- llvm/trunk/test/DebugInfo/Lanai/processes-relocations.ll +++ llvm/trunk/test/DebugInfo/Lanai/processes-relocations.ll @@ -0,0 +1,19 @@ +; RUN: llvm-dwarfdump %p/Inputs/lanai-processes-relocations.elf 2>&1 | FileCheck %s + +; FIXME: Use llc with this file as input instead of binary file. +; NOTE: this test is currently not using llc, but using a binary input as the +; rest of the backend is not yet in tree. Once the Lanai backend is in tree, +; the binary file will be removed and this test will use llc. + +; CHECK-NOT: failed to compute relocation + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4} +!llvm.ident = !{!5} + +!0 = !{i32 786449, !1, i32 12, !"clang version 3.6.0 ", i1 false, !"", i32 0, !2, !2, !2, !2, !2, !"", i32 1} ; [ DW_TAG_compile_unit ] [/a/empty.c] [DW_LANG_C99] +!1 = !{!"empty.c", !"/a"} +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{!"clang version 3.6.0 "} Index: llvm/trunk/test/Object/Lanai/lit.local.cfg =================================================================== --- llvm/trunk/test/Object/Lanai/lit.local.cfg +++ llvm/trunk/test/Object/Lanai/lit.local.cfg @@ -0,0 +1,2 @@ +if not 'Lanai' in config.root.targets: + config.unsupported = True Index: llvm/trunk/test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml =================================================================== --- llvm/trunk/test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml +++ llvm/trunk/test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml @@ -0,0 +1,66 @@ +# RUN: yaml2obj -format=elf %s > %t +# RUN: llvm-readobj -r %t | FileCheck %s + +# CHECK : Relocations [ +# CHECK-NEXT: Section (2) .rel.text { +# CHECK-NEXT: 0x0 R_LANAI_32 main 0x0 +# CHECK-NEXT: 0x4 R_LANAI_NONE - 0x0 +# CHECK-NEXT: 0x8 R_LANAI_21 - 0x0 +# CHECK-NEXT: 0xC R_LANAI_21_F - 0x0 +# CHECK-NEXT: 0x10 R_LANAI_25 - 0x0 +# CHECK-NEXT: 0x14 R_LANAI_HI16 - 0x0 +# CHECK-NEXT: 0x18 R_LANAI_LO16 - 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_LANAI +Sections: + - Type: SHT_PROGBITS + Name: .text + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Content: 0000000000000000 + - Type: SHT_REL + Name: .rel.text + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x0 + Symbol: main + Type: R_LANAI_32 + - Offset: 0x4 + Symbol: a + Type: R_LANAI_NONE + - Offset: 0x8 + Symbol: b + Type: R_LANAI_21 + - Offset: 0xC + Symbol: c + Type: R_LANAI_21_F + - Offset: 0x10 + Symbol: d + Type: R_LANAI_25 + - Offset: 0x14 + Symbol: e + Type: R_LANAI_HI16 + - Offset: 0x18 + Symbol: f + Type: R_LANAI_LO16 + + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + + Global: + - Name: main + Type: STT_FUNC + Section: .text + Size: 0x08 Index: llvm/trunk/test/tools/llvm-readobj/Inputs/relocs.py =================================================================== --- llvm/trunk/test/tools/llvm-readobj/Inputs/relocs.py +++ llvm/trunk/test/tools/llvm-readobj/Inputs/relocs.py @@ -991,6 +991,14 @@ R_HEX_TPREL_16_X = 84 R_HEX_TPREL_11_X = 85 +class Relocs_Elf_Lanai(Enum): + R_LANAI_NONE = 0 + R_LANAI_21 = 1 + R_LANAI_21_F = 2 + R_LANAI_25 = 3 + R_LANAI_32 = 4 + R_LANAI_HI16 = 5 + R_LANAI_LO16 = 6 class Relocs_Coff_i386(Enum): IMAGE_REL_I386_ABSOLUTE = 0x0000 @@ -1103,6 +1111,7 @@ craftElf("relocs.obj.elf-mips", "mips-unknown-linux", Relocs_Elf_Mips.entries(), "lui $2, %hi(sym)") craftElf("relocs.obj.elf-mips64el", "mips64el-unknown-linux", Relocs_Elf_Mips.entries(), "lui $2, %hi(sym)") #craftElf("relocs.obj.elf-hexagon", "hexagon-unknown-unknown", Relocs_Elf_Hexagon.entries(), ...) +#craftElf("relocs.obj.elf-lanai", "lanai-unknown-unknown", Relocs_Elf_Lanai.entries(), "mov hi(x), %r4") craftCoff("relocs.obj.coff-i386", "i386-pc-win32", Relocs_Coff_i386.entries(), "mov foo@imgrel(%ebx, %ecx, 4), %eax") craftCoff("relocs.obj.coff-x86_64", "x86_64-pc-win32", Relocs_Coff_X86_64.entries(), "mov foo@imgrel(%ebx, %ecx, 4), %eax") Index: llvm/trunk/test/tools/llvm-readobj/file-headers.test =================================================================== --- llvm/trunk/test/tools/llvm-readobj/file-headers.test +++ llvm/trunk/test/tools/llvm-readobj/file-headers.test @@ -24,6 +24,8 @@ RUN: | FileCheck %s -check-prefix COFF-UNKNOWN RUN: llvm-readobj -h %p/Inputs/magic.coff-importlib \ RUN: | FileCheck %s -check-prefix COFF-IMPORTLIB +RUN: llvm-readobj -h %p/Inputs/trivial.obj.elf-lanai \ +RUN: | FileCheck %s -check-prefix ELF-LANAI COFF-ARM: File: {{(.*[/\\])?}}trivial.obj.coff-arm COFF-ARM-NEXT: Format: COFF-ARM @@ -335,3 +337,33 @@ COFF-IMPORTLIB-NEXT: Name type: noprefix COFF-IMPORTLIB-NEXT: Symbol: __imp__func COFF-IMPORTLIB-NEXT: Symbol: _func + +ELF-LANAI: Format: ELF32-lanai +ELF-LANAI-NEXT: Arch: lanai +ELF-LANAI-NEXT: AddressSize: 32bit +ELF-LANAI-NEXT: LoadName: +ELF-LANAI-NEXT: ElfHeader { +ELF-LANAI-NEXT: Ident { +ELF-LANAI-NEXT: Magic: (7F 45 4C 46) +ELF-LANAI-NEXT: Class: 32-bit (0x1) +ELF-LANAI-NEXT: DataEncoding: BigEndian (0x2) +ELF-LANAI-NEXT: FileVersion: 1 +ELF-LANAI-NEXT: OS/ABI: SystemV (0x0) +ELF-LANAI-NEXT: ABIVersion: 0 +ELF-LANAI-NEXT: Unused: (00 00 00 00 00 00 00) +ELF-LANAI-NEXT: } +ELF-LANAI-NEXT: Type: Relocatable (0x1) +ELF-LANAI-NEXT: Machine: EM_LANAI (0x8123) +ELF-LANAI-NEXT: Version: 1 +ELF-LANAI-NEXT: Entry: 0x0 +ELF-LANAI-NEXT: ProgramHeaderOffset: 0x0 +ELF-LANAI-NEXT: SectionHeaderOffset: 0x1A0 +ELF-LANAI-NEXT: Flags [ (0x0) +ELF-LANAI-NEXT: ] +ELF-LANAI-NEXT: HeaderSize: 52 +ELF-LANAI-NEXT: ProgramHeaderEntrySize: 0 +ELF-LANAI-NEXT: ProgramHeaderCount: 0 +ELF-LANAI-NEXT: SectionHeaderEntrySize: 40 +ELF-LANAI-NEXT: SectionHeaderCount: 8 +ELF-LANAI-NEXT: StringTableSectionIndex: 1 +ELF-LANAI-NEXT: } Index: llvm/trunk/test/tools/llvm-readobj/reloc-types.test =================================================================== --- llvm/trunk/test/tools/llvm-readobj/reloc-types.test +++ llvm/trunk/test/tools/llvm-readobj/reloc-types.test @@ -7,6 +7,7 @@ RUN: llvm-readobj -r -expand-relocs %p/Inputs/relocs.obj.elf-x86_64 | FileCheck %s -check-prefix ELF-64 RUN: llvm-readobj -r -expand-relocs %p/Inputs/relocs.obj.elf-aarch64 | FileCheck %s -check-prefix ELF-AARCH64 RUN: llvm-readobj -r -expand-relocs %p/Inputs/relocs.obj.elf-arm | FileCheck %s -check-prefix ELF-ARM +RUN: llvm-readobj -r -expand-relocs %p/Inputs/relocs.obj.elf-lanai | FileCheck %s -check-prefix ELF-LANAI RUN: llvm-readobj -r -expand-relocs %p/Inputs/relocs.obj.elf-mips | FileCheck %s -check-prefix ELF-MIPS RUN: llvm-readobj -r -expand-relocs %p/Inputs/relocs.obj.elf-mips64el | FileCheck %s -check-prefix ELF-MIPS64EL RUN: llvm-readobj -r -expand-relocs %p/Inputs/relocs.obj.elf-ppc64 | FileCheck %s -check-prefix ELF-PPC64 @@ -405,6 +406,14 @@ ELF-ARM: Type: R_ARM_THM_TLS_DESCSEQ32 (130) ELF-ARM: Type: R_ARM_IRELATIVE (160) +ELF-LANAI: Type: R_LANAI_NONE (0) +ELF-LANAI: Type: R_LANAI_21 (1) +ELF-LANAI: Type: R_LANAI_21_F (2) +ELF-LANAI: Type: R_LANAI_25 (3) +ELF-LANAI: Type: R_LANAI_32 (4) +ELF-LANAI: Type: R_LANAI_HI16 (5) +ELF-LANAI: Type: R_LANAI_LO16 (6) + ELF-MIPS: Type: R_MIPS_NONE (0) ELF-MIPS: Type: R_MIPS_16 (1) ELF-MIPS: Type: R_MIPS_32 (2) Index: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp +++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp @@ -476,6 +476,7 @@ res = "Unknown"; } break; + case ELF::EM_LANAI: case ELF::EM_AARCH64: { std::string fmtbuf; raw_string_ostream fmt(fmtbuf); Index: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp +++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp @@ -769,7 +769,8 @@ ENUM_ENT(EM_78KOR, "EM_78KOR"), ENUM_ENT(EM_56800EX, "EM_56800EX"), ENUM_ENT(EM_AMDGPU, "EM_AMDGPU"), - ENUM_ENT(EM_WEBASSEMBLY, "EM_WEBASSEMBLY") + ENUM_ENT(EM_WEBASSEMBLY, "EM_WEBASSEMBLY"), + ENUM_ENT(EM_LANAI, "EM_LANAI"), }; static const EnumEntry ElfSymbolBindings[] = {