Index: include/llvm/Object/ELFObjectFile.h =================================================================== --- include/llvm/Object/ELFObjectFile.h +++ 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: include/llvm/Object/RelocVisitor.h =================================================================== --- include/llvm/Object/RelocVisitor.h +++ 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: include/llvm/Support/ELF.h =================================================================== --- include/llvm/Support/ELF.h +++ 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: include/llvm/Support/ELFRelocs/Lanai.def =================================================================== --- include/llvm/Support/ELFRelocs/Lanai.def +++ include/llvm/Support/ELFRelocs/Lanai.def @@ -0,0 +1,12 @@ + +#ifndef ELF_RELOC +#error "ELF_RELOC must be defined" +#endif + +ELF_RELOC(R_LANAI_NONE, 0) +ELF_RELOC(R_LANAI_21, 1) +ELF_RELOC(R_LANAI_21_F, 2) +ELF_RELOC(R_LANAI_25, 3) +ELF_RELOC(R_LANAI_32, 4) +ELF_RELOC(R_LANAI_HI16, 5) +ELF_RELOC(R_LANAI_LO16, 6) Index: lib/MC/MCObjectFileInfo.cpp =================================================================== --- lib/MC/MCObjectFileInfo.cpp +++ 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: lib/Object/ELF.cpp =================================================================== --- lib/Object/ELF.cpp +++ 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: lib/Object/ELFYAML.cpp =================================================================== --- lib/Object/ELFYAML.cpp +++ lib/Object/ELFYAML.cpp @@ -194,6 +194,7 @@ ECase(EM_78KOR) ECase(EM_56800EX) ECase(EM_AMDGPU) + ECase(EM_LANAI) #undef ECase } @@ -526,6 +527,9 @@ case ELF::EM_ARM: #include "llvm/Support/ELFRelocs/ARM.def" break; + case ELF::EM_LANAI: +#include "llvm/Support/ELFRelocs/Lanai.def" + break; default: llvm_unreachable("Unsupported architecture"); } Index: test/Object/Lanai/lit.local.cfg =================================================================== --- test/Object/Lanai/lit.local.cfg +++ test/Object/Lanai/lit.local.cfg @@ -0,0 +1,2 @@ +if not 'Lanai' in config.root.targets: + config.unsupported = True Index: test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml =================================================================== --- test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml +++ test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml @@ -0,0 +1,41 @@ +# 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: } +# 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: 0 + Symbol: main + Type: R_LANAI_32 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + + Global: + - Name: main + Type: STT_FUNC + Section: .text + Size: 0x08