From ea54ef2b77d0e4bb1ea00329535c4c5941e78f10 Mon Sep 17 00:00:00 2001 From: Jacques Pienaar Date: Tue, 1 Mar 2016 21:21:42 +0000 Subject: [PATCH] [lanai] Add ELF enum value and relocations. Add ELF enum value and relocations for Lanai backed. General Lanai backend discussion on llvm-dev thread "[RFC] Lanai backend" (http://lists.llvm.org/pipermail/llvm-dev/2016-February/095118.html). Differential Revision: http://reviews.llvm.org/D17008 llvm-svn: 262394 --- include/llvm/Object/ELFObjectFile.h | 4 ++ include/llvm/Object/RelocVisitor.h | 15 ++++ include/llvm/Support/ELF.h | 10 +++ include/llvm/Support/ELFRelocs/Lanai.def | 19 +++++ lib/MC/MCObjectFileInfo.cpp | 5 ++ lib/Object/ELF.cpp | 7 ++ .../Inputs/lanai-processes-relocations.elf | Bin 0 -> 1144 bytes test/DebugInfo/Lanai/lit.local.cfg | 2 + test/DebugInfo/Lanai/processes-relocations.ll | 19 +++++ test/Object/Lanai/lit.local.cfg | 2 + test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml | 66 ++++++++++++++++++ .../llvm-readobj/Inputs/relocs.obj.elf-lanai | Bin 0 -> 428 bytes test/tools/llvm-readobj/Inputs/relocs.py | 9 +++ .../llvm-readobj/Inputs/trivial.obj.elf-lanai | Bin 0 -> 736 bytes test/tools/llvm-readobj/file-headers.test | 32 +++++++++ test/tools/llvm-readobj/reloc-types.test | 9 +++ tools/llvm-objdump/llvm-objdump.cpp | 1 + tools/llvm-readobj/ELFDumper.cpp | 3 +- 18 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 include/llvm/Support/ELFRelocs/Lanai.def create mode 100644 test/DebugInfo/Inputs/lanai-processes-relocations.elf create mode 100644 test/DebugInfo/Lanai/lit.local.cfg create mode 100644 test/DebugInfo/Lanai/processes-relocations.ll create mode 100644 test/Object/Lanai/lit.local.cfg create mode 100644 test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml create mode 100644 test/tools/llvm-readobj/Inputs/relocs.obj.elf-lanai create mode 100644 test/tools/llvm-readobj/Inputs/trivial.obj.elf-lanai diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index 5d826da4c2f..d927aace242 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -835,6 +835,8 @@ StringRef ELFObjectFile::getFileFormatName() const { 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 @@ unsigned ELFObjectFile::getArch() const { 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: diff --git a/include/llvm/Object/RelocVisitor.h b/include/llvm/Object/RelocVisitor.h index d5e4258cb0a..f171f8e1fd4 100644 --- a/include/llvm/Object/RelocVisitor.h +++ b/include/llvm/Object/RelocVisitor.h @@ -175,6 +175,14 @@ private: 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 @@ private: 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; diff --git a/include/llvm/Support/ELF.h b/include/llvm/Support/ELF.h index 775bf99662b..26354dc1b9b 100644 --- a/include/llvm/Support/ELF.h +++ b/include/llvm/Support/ELF.h @@ -315,6 +315,11 @@ enum { // 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 @@ enum { #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" diff --git a/include/llvm/Support/ELFRelocs/Lanai.def b/include/llvm/Support/ELFRelocs/Lanai.def new file mode 100644 index 00000000000..77ecb048403 --- /dev/null +++ b/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) diff --git a/lib/MC/MCObjectFileInfo.cpp b/lib/MC/MCObjectFileInfo.cpp index 2948f69aee8..477463c7368 100644 --- a/lib/MC/MCObjectFileInfo.cpp +++ b/lib/MC/MCObjectFileInfo.cpp @@ -356,6 +356,11 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(Triple T) { 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: diff --git a/lib/Object/ELF.cpp b/lib/Object/ELF.cpp index 12b772d930b..95093894237 100644 --- a/lib/Object/ELF.cpp +++ b/lib/Object/ELF.cpp @@ -61,6 +61,13 @@ StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type) { 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" diff --git a/test/DebugInfo/Inputs/lanai-processes-relocations.elf b/test/DebugInfo/Inputs/lanai-processes-relocations.elf new file mode 100644 index 0000000000000000000000000000000000000000..88d519a2cdfbc091a24451011cb31e59c64dcd4c GIT binary patch literal 1144 zcma)5y>1jS5FTGHq#?^e1c)HeNeC$g@kR;?6qJyFh^Ro&oqT&HoYOH+PBwNkGLKl=9QWxoVwz0aB4X$3#V&hHfGw8>@=VMaFfA)iT zjd~b2`s!Dd1#e=%5$lN^A0Lg(c7uDBTLVPV;Y_U;=7SShnPOVMZb&;@ znpE5-!kej^jAq7#MP8QkDh|Q=kU!-2J;AK})&0GE=9ADG4 zA3S@p?Sm=a${WjRZI`$yNMkj@j1d=A8xOf+1X$V;X1cJ$XZFAL6@`5M$*at)i*M@GbT10hLg`m}?Y^FD4e zNGARE!DX$0Y74^y_&S{T#v0!@o-14b-liFOY;!7OuKmkZ{*&REXn6d3n&X{@n- mOi={pU6X#FkQB^1*UA6GT(ob%{Nsv!0hqyAUxV|02Y&z)rFtO% literal 0 HcmV?d00001 diff --git a/test/DebugInfo/Lanai/lit.local.cfg b/test/DebugInfo/Lanai/lit.local.cfg new file mode 100644 index 00000000000..f1b8b4f4e21 --- /dev/null +++ b/test/DebugInfo/Lanai/lit.local.cfg @@ -0,0 +1,2 @@ +if not 'Lanai' in config.root.targets: + config.unsupported = True diff --git a/test/DebugInfo/Lanai/processes-relocations.ll b/test/DebugInfo/Lanai/processes-relocations.ll new file mode 100644 index 00000000000..8a8378af8cf --- /dev/null +++ b/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 "} diff --git a/test/Object/Lanai/lit.local.cfg b/test/Object/Lanai/lit.local.cfg new file mode 100644 index 00000000000..f1b8b4f4e21 --- /dev/null +++ b/test/Object/Lanai/lit.local.cfg @@ -0,0 +1,2 @@ +if not 'Lanai' in config.root.targets: + config.unsupported = True diff --git a/test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml b/test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml new file mode 100644 index 00000000000..3a31a3901a2 --- /dev/null +++ b/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 diff --git a/test/tools/llvm-readobj/Inputs/relocs.obj.elf-lanai b/test/tools/llvm-readobj/Inputs/relocs.obj.elf-lanai new file mode 100644 index 0000000000000000000000000000000000000000..c0bb9a046942cb78a784d3172034be3b20d069a8 GIT binary patch literal 428 zcmb<-^>JflVq|~=#ztiz8%coS30TeqOlmN&GJutXv|z(Xs2IqvAUU94 Z8N`4X=64{IApnRKfEZ*S2!qrK000hu5NrSd literal 0 HcmV?d00001 diff --git a/test/tools/llvm-readobj/Inputs/relocs.py b/test/tools/llvm-readobj/Inputs/relocs.py index 62dbd627ca5..48a1ffb0994 100644 --- a/test/tools/llvm-readobj/Inputs/relocs.py +++ b/test/tools/llvm-readobj/Inputs/relocs.py @@ -991,6 +991,14 @@ class Relocs_Elf_Hexagon(Enum): 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-arm", "arm-unknown-unknown", Relocs_Elf_AR 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") diff --git a/test/tools/llvm-readobj/Inputs/trivial.obj.elf-lanai b/test/tools/llvm-readobj/Inputs/trivial.obj.elf-lanai new file mode 100644 index 0000000000000000000000000000000000000000..13bb30ca6fd9abb1c2cb970e5728a7251495722c GIT binary patch literal 736 zcma)4F-yZx5dP9uTf{;X=_XWN9Q0w;!CkB!iXv4UoL<|2!89o^uSG$SIypF01zr7V z{slLOLcB}zYORY0clX_WcQ2QF@9v;pwK5jQVhz>^PbS`DZa22;D8PDtiAI?r3ad73 zYXF=)0#8FA{{Z`qxR1CL)^vPI`9X<#mw@}%=&R;+AScPV4)mO3hi8LbbC64 zXoh6!BGd|fsn7^I&au99RJG@~v>W*7NY{r}Zr_!j@H_}V(2h7fI@=7jY+Zp{wQQ2V z>BL?IZK)-vE25GP@K4vEIx{mtYlDoM=rwmb%Ooj#7QWe9j1t3pW#JlwIUbSHE|4eX z-7?4fZIN>AHYv+3X)#8LVUCqnPOs-@MtU{B&NtuMr##mi;krpN+yy0h4kKLGC1sxX Hz~|ZDF^x_W literal 0 HcmV?d00001 diff --git a/test/tools/llvm-readobj/file-headers.test b/test/tools/llvm-readobj/file-headers.test index 2d67089d611..4fe8210c4dd 100644 --- a/test/tools/llvm-readobj/file-headers.test +++ b/test/tools/llvm-readobj/file-headers.test @@ -24,6 +24,8 @@ RUN: llvm-readobj -h %p/Inputs/magic.coff-unknown \ 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: Type: code 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: } diff --git a/test/tools/llvm-readobj/reloc-types.test b/test/tools/llvm-readobj/reloc-types.test index 36e2f7010bd..74148c07015 100644 --- a/test/tools/llvm-readobj/reloc-types.test +++ b/test/tools/llvm-readobj/reloc-types.test @@ -7,6 +7,7 @@ RUN: llvm-readobj -r -expand-relocs %p/Inputs/relocs.obj.elf-i386 | FileChec 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_DESCSEQ16 (129) 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) diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index a89fb76117a..8a61716e346 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -476,6 +476,7 @@ static std::error_code getRelocationValueString(const ELFObjectFile *Obj, res = "Unknown"; } break; + case ELF::EM_LANAI: case ELF::EM_AARCH64: { std::string fmtbuf; raw_string_ostream fmt(fmtbuf); diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index ae924cd92b0..fbfd6d1b797 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -769,7 +769,8 @@ static const EnumEntry ElfMachineType[] = { 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[] = {