[llvm] r243991 - [RuntimeDyld] Adapt PPC64 relocations to PPC32

Hal Finkel hfinkel at anl.gov
Tue Aug 4 08:29:00 PDT 2015


Author: hfinkel
Date: Tue Aug  4 10:29:00 2015
New Revision: 243991

URL: http://llvm.org/viewvc/llvm-project?rev=243991&view=rev
Log:
[RuntimeDyld] Adapt PPC64 relocations to PPC32

Begin adapting some of the implemented PPC64 relocations for PPC32 (with a
test case).

Patch by Pierre-Andre Saulais!

Added:
    llvm/trunk/test/ExecutionEngine/RuntimeDyld/PowerPC/
    llvm/trunk/test/ExecutionEngine/RuntimeDyld/PowerPC/lit.local.cfg
    llvm/trunk/test/ExecutionEngine/RuntimeDyld/PowerPC/ppc32_elf_rel_addr16.s
Modified:
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp?rev=243991&r1=243990&r2=243991&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp Tue Aug  4 10:29:00 2015
@@ -887,6 +887,26 @@ static inline uint16_t applyPPChighesta
   return ((value + 0x8000) >> 48) & 0xffff;
 }
 
+void RuntimeDyldELF::resolvePPC32Relocation(const SectionEntry &Section,
+                                            uint64_t Offset, uint64_t Value,
+                                            uint32_t Type, int64_t Addend) {
+  uint8_t *LocalAddress = Section.Address + Offset;
+  switch (Type) {
+  default:
+    llvm_unreachable("Relocation type not implemented yet!");
+    break;
+  case ELF::R_PPC_ADDR16_LO:
+    writeInt16BE(LocalAddress, applyPPClo(Value + Addend));
+    break;
+  case ELF::R_PPC_ADDR16_HI:
+    writeInt16BE(LocalAddress, applyPPChi(Value + Addend));
+    break;
+  case ELF::R_PPC_ADDR16_HA:
+    writeInt16BE(LocalAddress, applyPPCha(Value + Addend));
+    break;
+  }
+}
+
 void RuntimeDyldELF::resolvePPC64Relocation(const SectionEntry &Section,
                                             uint64_t Offset, uint64_t Value,
                                             uint32_t Type, int64_t Addend) {
@@ -1075,6 +1095,9 @@ void RuntimeDyldELF::resolveRelocation(c
     else
       llvm_unreachable("Mips ABI not handled");
     break;
+  case Triple::ppc:
+    resolvePPC32Relocation(Section, Offset, Value, Type, Addend);
+    break;
   case Triple::ppc64: // Fall through.
   case Triple::ppc64le:
     resolvePPC64Relocation(Section, Offset, Value, Type, Addend);

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h?rev=243991&r1=243990&r2=243991&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h Tue Aug  4 10:29:00 2015
@@ -43,6 +43,9 @@ class RuntimeDyldELF : public RuntimeDyl
   void resolveMIPSRelocation(const SectionEntry &Section, uint64_t Offset,
                              uint32_t Value, uint32_t Type, int32_t Addend);
 
+  void resolvePPC32Relocation(const SectionEntry &Section, uint64_t Offset,
+                              uint64_t Value, uint32_t Type, int64_t Addend);
+
   void resolvePPC64Relocation(const SectionEntry &Section, uint64_t Offset,
                               uint64_t Value, uint32_t Type, int64_t Addend);
 

Added: llvm/trunk/test/ExecutionEngine/RuntimeDyld/PowerPC/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/RuntimeDyld/PowerPC/lit.local.cfg?rev=243991&view=auto
==============================================================================
--- llvm/trunk/test/ExecutionEngine/RuntimeDyld/PowerPC/lit.local.cfg (added)
+++ llvm/trunk/test/ExecutionEngine/RuntimeDyld/PowerPC/lit.local.cfg Tue Aug  4 10:29:00 2015
@@ -0,0 +1,3 @@
+if not 'PowerPC' in config.root.targets:
+    config.unsupported = True
+

Added: llvm/trunk/test/ExecutionEngine/RuntimeDyld/PowerPC/ppc32_elf_rel_addr16.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/RuntimeDyld/PowerPC/ppc32_elf_rel_addr16.s?rev=243991&view=auto
==============================================================================
--- llvm/trunk/test/ExecutionEngine/RuntimeDyld/PowerPC/ppc32_elf_rel_addr16.s (added)
+++ llvm/trunk/test/ExecutionEngine/RuntimeDyld/PowerPC/ppc32_elf_rel_addr16.s Tue Aug  4 10:29:00 2015
@@ -0,0 +1,47 @@
+# RUN: llvm-mc -triple=powerpc-unknown-linux-gnu -filetype=obj -o %T/ppc32_elf_rel_addr16.o %s
+# RUN: llvm-rtdyld -triple=powerpc-unknown-linux-gnu -verify -check=%s %T/ppc32_elf_rel_addr16.o
+	.text
+	.file	"ppc32_elf_rel_addr16.ll"
+	.globl	lookup
+	.align	2
+	.type	lookup, at function
+lookup:                                 # @lookup
+.Lfunc_begin0:
+# BB#0:
+	stw 31, -4(1)
+	stwu 1, -16(1)
+insn_hi:
+# Check the higher 16-bits of the symbol's absolute address
+# rtdyld-check: decode_operand(insn_hi, 1) = elements[31:16]
+	lis 4, elements at ha
+	slwi 3, 3, 2
+	mr 31, 1
+insn_lo:
+# Check the lower 16-bits of the symbol's absolute address
+# rtdyld-check: decode_operand(insn_lo, 2) = elements[15:0]
+	la 4, elements at l(4)
+	lwzx 3, 4, 3
+	addi 1, 1, 16
+	lwz 31, -4(1)
+	blr
+.Lfunc_end0:
+	.size	lookup, .Lfunc_end0-.Lfunc_begin0
+
+	.type	elements, at object        # @elements
+	.data
+	.globl	elements
+	.align	2
+elements:
+	.long	14                      # 0xe
+	.long	4                       # 0x4
+	.long	1                       # 0x1
+	.long	3                       # 0x3
+	.long	13                      # 0xd
+	.long	0                       # 0x0
+	.long	32                      # 0x20
+	.long	334                     # 0x14e
+	.size	elements, 32
+
+
+	.ident	"clang version 3.7.0 "
+	.section	".note.GNU-stack","", at progbits





More information about the llvm-commits mailing list