[PATCH] [AArch64] Add missing PCRel relocations for AArch64 in RuntimeDyldELF
Bradley Smith
bradley.smith at arm.com
Wed Feb 5 02:44:42 PST 2014
This patch adds the missing AArch64 relocations needed by the test added in r200404 so that the test can be re-enabled for AArch64, (also reverts r200592).
(http://llvm.org/bugs/show_bug.cgi?id=18686)
http://llvm-reviews.chandlerc.com/D2696
Files:
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
test/ExecutionEngine/MCJIT/non-extern-addend-smallcodemodel.ll
test/ExecutionEngine/MCJIT/non-extern-addend.ll
Index: lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
===================================================================
--- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
+++ lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
@@ -454,6 +454,48 @@
assert((*TargetPtr >> 21 & 0x3) == 0 && "invalid shift for relocation");
break;
}
+ case ELF::R_AARCH64_ADR_PREL_PG_HI21: {
+ // Operation: Page(S+A) - Page(P)
+ uint64_t Result = ((Value + Addend) & ~0xfffU) - (FinalAddress & ~0xfffU);
+
+ // Check that -2^32 <= X < 2^32
+ assert(static_cast<int64_t>(Result) >= (-1LL << 32) &&
+ static_cast<int64_t>(Result) < (1LL << 32) &&
+ "overflow check failed for relocation");
+
+ // AArch64 code is emitted with .rela relocations. The data already in any
+ // bits affected by the relocation on entry is garbage.
+ *TargetPtr &= 0x9f00001fU;
+ // Immediate goes in bits 30:29 + 5:23 of ADRP instruction, taken
+ // from bits 32:12 of X.
+ *TargetPtr |= ((Result & 0x3000U) << (29 - 12));
+ *TargetPtr |= ((Result & 0x1ffffc000ULL) >> (14 - 5));
+ break;
+ }
+ case ELF::R_AARCH64_LDST32_ABS_LO12_NC: {
+ // Operation: S + A
+ uint64_t Result = Value + Addend;
+
+ // AArch64 code is emitted with .rela relocations. The data already in any
+ // bits affected by the relocation on entry is garbage.
+ *TargetPtr &= 0xffc003ffU;
+ // Immediate goes in bits 21:10 of LD/ST instruction, taken
+ // from bits 11:2 of X
+ *TargetPtr |= ((Result & 0xffc) << (10 - 2));
+ break;
+ }
+ case ELF::R_AARCH64_LDST64_ABS_LO12_NC: {
+ // Operation: S + A
+ uint64_t Result = Value + Addend;
+
+ // AArch64 code is emitted with .rela relocations. The data already in any
+ // bits affected by the relocation on entry is garbage.
+ *TargetPtr &= 0xffc003ffU;
+ // Immediate goes in bits 21:10 of LD/ST instruction, taken
+ // from bits 11:3 of X
+ *TargetPtr |= ((Result & 0xff8) << (10 - 3));
+ break;
+ }
}
}
Index: test/ExecutionEngine/MCJIT/non-extern-addend-smallcodemodel.ll
===================================================================
--- test/ExecutionEngine/MCJIT/non-extern-addend-smallcodemodel.ll
+++ /dev/null
@@ -1,25 +0,0 @@
-; RUN: %lli_mcjit -code-model=small %s > /dev/null
-; XFAIL: aarch64
-;
-; FIXME: Merge this file with non-extern-addend.ll once AArch64 supports PC-rel
-; relocations in ELF. (The code is identical, only the run line differs).
-;
-define i32 @foo(i32 %x, i32 %y, double %d) {
-entry:
- %d.int64 = bitcast double %d to i64
- %d.top64 = lshr i64 %d.int64, 32
- %d.top = trunc i64 %d.top64 to i32
- %d.bottom = trunc i64 %d.int64 to i32
- %topCorrect = icmp eq i32 %d.top, 3735928559
- %bottomCorrect = icmp eq i32 %d.bottom, 4277009102
- %right = and i1 %topCorrect, %bottomCorrect
- %nRight = xor i1 %right, true
- %retVal = zext i1 %nRight to i32
- ret i32 %retVal
-}
-
-define i32 @main() {
-entry:
- %call = call i32 @foo(i32 0, i32 1, double 0xDEADBEEFFEEDFACE)
- ret i32 %call
-}
Index: test/ExecutionEngine/MCJIT/non-extern-addend.ll
===================================================================
--- test/ExecutionEngine/MCJIT/non-extern-addend.ll
+++ test/ExecutionEngine/MCJIT/non-extern-addend.ll
@@ -1,4 +1,5 @@
; RUN: %lli_mcjit %s > /dev/null
+; RUN: %lli_mcjit -code-model=small %s > /dev/null
define i32 @foo(i32 %x, i32 %y, double %d) {
entry:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2696.1.patch
Type: text/x-patch
Size: 3459 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140205/bf89298f/attachment.bin>
More information about the llvm-commits
mailing list