tstellar / rpms / llvm

Forked from rpms/llvm 5 years ago
Clone
146ec0c
From 29cf3bd00fe84ddab138c9311fe288bb9da8a273 Mon Sep 17 00:00:00 2001
146ec0c
From: root <root@mammon-seattle-raw.austin.arm.com>
146ec0c
Date: Thu, 9 Mar 2017 12:22:48 -0600
146ec0c
Subject: [PATCH] Fix R_AARCH64_MOVW_UABS_G3 relocation
146ec0c
146ec0c
Summary: The relocation is missing mask so an address that
146ec0c
has non-zero bits in 47:43 may overwrite the register
146ec0c
number. (Frequently shows up as target register changed
146ec0c
to xzr....)
146ec0c
146ec0c
Reviewers: t.p.northover, lhames
146ec0c
Subscribers: davide, aemerson, rengolin, llvm-commits
146ec0c
Differential Revision: https://reviews.llvm.org/D27609
146ec0c
---
146ec0c
 llvm-3.9.1.src/include/llvm/Object/ELFObjectFile.h |   2 +-
146ec0c
 llvm-3.9.1.src/include/llvm/Object/RelocVisitor.h  |   1 +
146ec0c
 .../ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp |  67 +++++++++-----
146ec0c
 .../RuntimeDyld/AArch64/ELF_ARM64_BE-relocations.s | 102 +++++++++++++++++++++
146ec0c
 .../RuntimeDyld/AArch64/ELF_ARM64_relocations.s    |  99 ++++++++++++++++++++
146ec0c
 5 files changed, 249 insertions(+), 22 deletions(-)
146ec0c
 create mode 100644 llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_BE-relocations.s
146ec0c
 create mode 100644 llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_relocations.s
146ec0c
146ec0c
diff --git a/llvm-3.9.1.src/include/llvm/Object/ELFObjectFile.h b/llvm-3.9.1.src/include/llvm/Object/ELFObjectFile.h
146ec0c
index 07c6364..d3b83f9 100644
146ec0c
--- a/llvm-3.9.1.src/include/llvm/Object/ELFObjectFile.h
146ec0c
+++ b/llvm-3.9.1.src/include/llvm/Object/ELFObjectFile.h
146ec0c
@@ -907,7 +907,7 @@ unsigned ELFObjectFile<ELFT>::getArch() const {
146ec0c
   case ELF::EM_X86_64:
146ec0c
     return Triple::x86_64;
146ec0c
   case ELF::EM_AARCH64:
146ec0c
-    return Triple::aarch64;
146ec0c
+    return IsLittleEndian ? Triple::aarch64 : Triple::aarch64_be;
146ec0c
   case ELF::EM_ARM:
146ec0c
     return Triple::arm;
146ec0c
   case ELF::EM_AVR:
146ec0c
diff --git a/llvm-3.9.1.src/include/llvm/Object/RelocVisitor.h b/llvm-3.9.1.src/include/llvm/Object/RelocVisitor.h
146ec0c
index 5e0df98..b59e8ec 100644
146ec0c
--- a/llvm-3.9.1.src/include/llvm/Object/RelocVisitor.h
146ec0c
+++ b/llvm-3.9.1.src/include/llvm/Object/RelocVisitor.h
146ec0c
@@ -86,6 +86,7 @@ private:
146ec0c
           return RelocToApply();
146ec0c
         }
146ec0c
       case Triple::aarch64:
146ec0c
+      case Triple::aarch64_be:
146ec0c
         switch (RelocType) {
146ec0c
         case llvm::ELF::R_AARCH64_ABS32:
146ec0c
           return visitELF_AARCH64_ABS32(R, Value);
146ec0c
diff --git a/llvm-3.9.1.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/llvm-3.9.1.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
146ec0c
index 9cbdb13..9e04b5d 100644
146ec0c
--- a/llvm-3.9.1.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
146ec0c
+++ b/llvm-3.9.1.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
146ec0c
@@ -309,6 +309,8 @@ void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section,
146ec0c
   uint32_t *TargetPtr =
146ec0c
       reinterpret_cast<uint32_t *>(Section.getAddressWithOffset(Offset));
146ec0c
   uint64_t FinalAddress = Section.getLoadAddressWithOffset(Offset);
146ec0c
+  // Data should use target endian. Code should always use little endian.
146ec0c
+  bool isBE = Arch == Triple::aarch64_be;
146ec0c
 
146ec0c
   DEBUG(dbgs() << "resolveAArch64Relocation, LocalAddress: 0x"
146ec0c
                << format("%llx", Section.getAddressWithOffset(Offset))
146ec0c
@@ -324,14 +326,22 @@ void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section,
146ec0c
   case ELF::R_AARCH64_ABS64: {
146ec0c
     uint64_t *TargetPtr =
146ec0c
         reinterpret_cast<uint64_t *>(Section.getAddressWithOffset(Offset));
146ec0c
-    *TargetPtr = Value + Addend;
146ec0c
+    if (isBE)
146ec0c
+      support::ubig64_t::ref{TargetPtr} = Value + Addend;
146ec0c
+    else
146ec0c
+      support::ulittle64_t::ref{TargetPtr} = Value + Addend;
146ec0c
     break;
146ec0c
   }
146ec0c
   case ELF::R_AARCH64_PREL32: {
146ec0c
     uint64_t Result = Value + Addend - FinalAddress;
146ec0c
     assert(static_cast<int64_t>(Result) >= INT32_MIN &&
146ec0c
            static_cast<int64_t>(Result) <= UINT32_MAX);
146ec0c
-    *TargetPtr = static_cast<uint32_t>(Result & 0xffffffffU);
146ec0c
+    if (isBE)
146ec0c
+      support::ubig32_t::ref{TargetPtr} =
146ec0c
+        static_cast<uint32_t>(Result & 0xffffffffU);
146ec0c
+    else
146ec0c
+      support::ulittle32_t::ref{TargetPtr} =
146ec0c
+        static_cast<uint32_t>(Result & 0xffffffffU);
146ec0c
     break;
146ec0c
   }
146ec0c
   case ELF::R_AARCH64_CALL26: // fallthrough
146ec0c
@@ -339,6 +349,7 @@ void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section,
146ec0c
     // Operation: S+A-P. Set Call or B immediate value to bits fff_fffc of the
146ec0c
     // calculation.
146ec0c
     uint64_t BranchImm = Value + Addend - FinalAddress;
146ec0c
+    uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr};
146ec0c
 
146ec0c
     // "Check that -2^27 <= result < 2^27".
146ec0c
     assert(isInt<28>(BranchImm));
146ec0c
@@ -352,91 +363,105 @@ void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section,
146ec0c
   }
146ec0c
   case ELF::R_AARCH64_MOVW_UABS_G3: {
146ec0c
     uint64_t Result = Value + Addend;
146ec0c
+    uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr};
146ec0c
 
146ec0c
     // AArch64 code is emitted with .rela relocations. The data already in any
146ec0c
     // bits affected by the relocation on entry is garbage.
146ec0c
-    *TargetPtr &= 0xffe0001fU;
146ec0c
+    TargetValue &= 0xffe0001fU;
146ec0c
     // Immediate goes in bits 20:5 of MOVZ/MOVK instruction
146ec0c
-    *TargetPtr |= Result >> (48 - 5);
146ec0c
+    TargetValue |= ((Result & 0xffff000000000000ULL) >> (48 - 5));
146ec0c
     // Shift must be "lsl #48", in bits 22:21
146ec0c
-    assert((*TargetPtr >> 21 & 0x3) == 3 && "invalid shift for relocation");
146ec0c
+    assert((TargetValue >> 21 & 0x3) == 3 && "invalid shift for relocation");
146ec0c
+    support::ulittle32_t::ref{TargetPtr} = TargetValue;
146ec0c
     break;
146ec0c
   }
146ec0c
   case ELF::R_AARCH64_MOVW_UABS_G2_NC: {
146ec0c
     uint64_t Result = Value + Addend;
146ec0c
+    uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr};
146ec0c
 
146ec0c
     // AArch64 code is emitted with .rela relocations. The data already in any
146ec0c
     // bits affected by the relocation on entry is garbage.
146ec0c
-    *TargetPtr &= 0xffe0001fU;
146ec0c
+    TargetValue &= 0xffe0001fU;
146ec0c
     // Immediate goes in bits 20:5 of MOVZ/MOVK instruction
146ec0c
-    *TargetPtr |= ((Result & 0xffff00000000ULL) >> (32 - 5));
146ec0c
+    TargetValue |= ((Result & 0xffff00000000ULL) >> (32 - 5));
146ec0c
     // Shift must be "lsl #32", in bits 22:21
146ec0c
-    assert((*TargetPtr >> 21 & 0x3) == 2 && "invalid shift for relocation");
146ec0c
+    assert((TargetValue >> 21 & 0x3) == 2 && "invalid shift for relocation");
146ec0c
+    support::ulittle32_t::ref{TargetPtr} = TargetValue;
146ec0c
     break;
146ec0c
   }
146ec0c
   case ELF::R_AARCH64_MOVW_UABS_G1_NC: {
146ec0c
     uint64_t Result = Value + Addend;
146ec0c
+    uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr};
146ec0c
 
146ec0c
     // AArch64 code is emitted with .rela relocations. The data already in any
146ec0c
     // bits affected by the relocation on entry is garbage.
146ec0c
-    *TargetPtr &= 0xffe0001fU;
146ec0c
+    TargetValue &= 0xffe0001fU;
146ec0c
     // Immediate goes in bits 20:5 of MOVZ/MOVK instruction
146ec0c
-    *TargetPtr |= ((Result & 0xffff0000U) >> (16 - 5));
146ec0c
+    TargetValue |= ((Result & 0xffff0000U) >> (16 - 5));
146ec0c
     // Shift must be "lsl #16", in bits 22:2
146ec0c
-    assert((*TargetPtr >> 21 & 0x3) == 1 && "invalid shift for relocation");
146ec0c
+    assert((TargetValue >> 21 & 0x3) == 1 && "invalid shift for relocation");
146ec0c
+    support::ulittle32_t::ref{TargetPtr} = TargetValue;
146ec0c
     break;
146ec0c
   }
146ec0c
   case ELF::R_AARCH64_MOVW_UABS_G0_NC: {
146ec0c
     uint64_t Result = Value + Addend;
146ec0c
+    uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr};
146ec0c
 
146ec0c
     // AArch64 code is emitted with .rela relocations. The data already in any
146ec0c
     // bits affected by the relocation on entry is garbage.
146ec0c
-    *TargetPtr &= 0xffe0001fU;
146ec0c
+    TargetValue &= 0xffe0001fU;
146ec0c
     // Immediate goes in bits 20:5 of MOVZ/MOVK instruction
146ec0c
-    *TargetPtr |= ((Result & 0xffffU) << 5);
146ec0c
+    TargetValue |= ((Result & 0xffffU) << 5);
146ec0c
     // Shift must be "lsl #0", in bits 22:21.
146ec0c
-    assert((*TargetPtr >> 21 & 0x3) == 0 && "invalid shift for relocation");
146ec0c
+    assert((TargetValue >> 21 & 0x3) == 0 && "invalid shift for relocation");
146ec0c
+    support::ulittle32_t::ref{TargetPtr} = TargetValue;
146ec0c
     break;
146ec0c
   }
146ec0c
   case ELF::R_AARCH64_ADR_PREL_PG_HI21: {
146ec0c
     // Operation: Page(S+A) - Page(P)
146ec0c
     uint64_t Result =
146ec0c
         ((Value + Addend) & ~0xfffULL) - (FinalAddress & ~0xfffULL);
146ec0c
+    uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr};
146ec0c
 
146ec0c
     // Check that -2^32 <= X < 2^32
146ec0c
     assert(isInt<33>(Result) && "overflow check failed for relocation");
146ec0c
 
146ec0c
     // AArch64 code is emitted with .rela relocations. The data already in any
146ec0c
     // bits affected by the relocation on entry is garbage.
146ec0c
-    *TargetPtr &= 0x9f00001fU;
146ec0c
+    TargetValue &= 0x9f00001fU;
146ec0c
     // Immediate goes in bits 30:29 + 5:23 of ADRP instruction, taken
146ec0c
     // from bits 32:12 of X.
146ec0c
-    *TargetPtr |= ((Result & 0x3000U) << (29 - 12));
146ec0c
-    *TargetPtr |= ((Result & 0x1ffffc000ULL) >> (14 - 5));
146ec0c
+    TargetValue |= ((Result & 0x3000U) << (29 - 12));
146ec0c
+    TargetValue |= ((Result & 0x1ffffc000ULL) >> (14 - 5));
146ec0c
+    support::ulittle32_t::ref{TargetPtr} = TargetValue;
146ec0c
     break;
146ec0c
   }
146ec0c
   case ELF::R_AARCH64_LDST32_ABS_LO12_NC: {
146ec0c
     // Operation: S + A
146ec0c
     uint64_t Result = Value + Addend;
146ec0c
+    uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr};
146ec0c
 
146ec0c
     // AArch64 code is emitted with .rela relocations. The data already in any
146ec0c
     // bits affected by the relocation on entry is garbage.
146ec0c
-    *TargetPtr &= 0xffc003ffU;
146ec0c
+    TargetValue &= 0xffc003ffU;
146ec0c
     // Immediate goes in bits 21:10 of LD/ST instruction, taken
146ec0c
     // from bits 11:2 of X
146ec0c
-    *TargetPtr |= ((Result & 0xffc) << (10 - 2));
146ec0c
+    TargetValue |= ((Result & 0xffc) << (10 - 2));
146ec0c
+    support::ulittle32_t::ref{TargetPtr} = TargetValue;
146ec0c
     break;
146ec0c
   }
146ec0c
   case ELF::R_AARCH64_LDST64_ABS_LO12_NC: {
146ec0c
     // Operation: S + A
146ec0c
     uint64_t Result = Value + Addend;
146ec0c
+    uint32_t TargetValue = support::ulittle32_t::ref{TargetPtr};
146ec0c
 
146ec0c
     // AArch64 code is emitted with .rela relocations. The data already in any
146ec0c
     // bits affected by the relocation on entry is garbage.
146ec0c
-    *TargetPtr &= 0xffc003ffU;
146ec0c
+    TargetValue &= 0xffc003ffU;
146ec0c
     // Immediate goes in bits 21:10 of LD/ST instruction, taken
146ec0c
     // from bits 11:3 of X
146ec0c
-    *TargetPtr |= ((Result & 0xff8) << (10 - 3));
146ec0c
+    TargetValue |= ((Result & 0xff8) << (10 - 3));
146ec0c
+    support::ulittle32_t::ref{TargetPtr} = TargetValue;
146ec0c
     break;
146ec0c
   }
146ec0c
   }
146ec0c
diff --git a/llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_BE-relocations.s b/llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_BE-relocations.s
146ec0c
new file mode 100644
146ec0c
index 0000000..01d01e5
146ec0c
--- /dev/null
146ec0c
+++ b/llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_BE-relocations.s
146ec0c
@@ -0,0 +1,102 @@
146ec0c
+# RUN: llvm-mc -triple=aarch64_be-none-linux-gnu -filetype=obj -o %T/be-reloc.o %s
146ec0c
+# RUN: llvm-rtdyld -triple=aarch64_be-none-linux-gnu -verify -dummy-extern f=0x0123456789abcdef -check=%s %T/be-reloc.o
146ec0c
+
146ec0c
+        .text
146ec0c
+        .globl  g
146ec0c
+        .p2align        2
146ec0c
+        .type   g,@function
146ec0c
+g:
146ec0c
+# R_AARCH64_MOVW_UABS_G3
146ec0c
+        movz    x0, #:abs_g3:f
146ec0c
+# R_AARCH64_MOVW_UABS_G2_NC
146ec0c
+        movk    x0, #:abs_g2_nc:f
146ec0c
+# R_AARCH64_MOVW_UABS_G1_NC
146ec0c
+        movk    x0, #:abs_g1_nc:f
146ec0c
+# R_AARCH64_MOVW_UABS_G0_NC
146ec0c
+        movk    x0, #:abs_g0_nc:f
146ec0c
+        ret
146ec0c
+        .Lfunc_end0:
146ec0c
+        .size   g, .Lfunc_end0-g
146ec0c
+
146ec0c
+        .type   k,@object
146ec0c
+        .data
146ec0c
+        .globl  k
146ec0c
+        .p2align        3
146ec0c
+k:
146ec0c
+        .xword  f
146ec0c
+        .size   k, 8
146ec0c
+
146ec0c
+# LE instructions read as BE
146ec0c
+# rtdyld-check: *{4}(g) = 0x6024e0d2
146ec0c
+# rtdyld-check: *{4}(g + 4) = 0xe0acc8f2
146ec0c
+# rtdyld-check: *{4}(g + 8) = 0x6035b1f2
146ec0c
+# rtdyld-check: *{4}(g + 12) = 0xe0bd99f2
146ec0c
+# rtdyld-check: *{8}k = f
146ec0c
+# RUN: llvm-mc -triple=aarch64_be-none-linux-gnu -filetype=obj -o %T/be-reloc.o %s
146ec0c
+# RUN: llvm-rtdyld -triple=aarch64_be-none-linux-gnu -verify -dummy-extern f=0x0123456789abcdef -check=%s %T/be-reloc.o
146ec0c
+
146ec0c
+        .text
146ec0c
+        .globl  g
146ec0c
+        .p2align        2
146ec0c
+        .type   g,@function
146ec0c
+g:
146ec0c
+# R_AARCH64_MOVW_UABS_G3
146ec0c
+        movz    x0, #:abs_g3:f
146ec0c
+# R_AARCH64_MOVW_UABS_G2_NC
146ec0c
+        movk    x0, #:abs_g2_nc:f
146ec0c
+# R_AARCH64_MOVW_UABS_G1_NC
146ec0c
+        movk    x0, #:abs_g1_nc:f
146ec0c
+# R_AARCH64_MOVW_UABS_G0_NC
146ec0c
+        movk    x0, #:abs_g0_nc:f
146ec0c
+        ret
146ec0c
+        .Lfunc_end0:
146ec0c
+        .size   g, .Lfunc_end0-g
146ec0c
+
146ec0c
+        .type   k,@object
146ec0c
+        .data
146ec0c
+        .globl  k
146ec0c
+        .p2align        3
146ec0c
+k:
146ec0c
+        .xword  f
146ec0c
+        .size   k, 8
146ec0c
+
146ec0c
+# LE instructions read as BE
146ec0c
+# rtdyld-check: *{4}(g) = 0x6024e0d2
146ec0c
+# rtdyld-check: *{4}(g + 4) = 0xe0acc8f2
146ec0c
+# rtdyld-check: *{4}(g + 8) = 0x6035b1f2
146ec0c
+# rtdyld-check: *{4}(g + 12) = 0xe0bd99f2
146ec0c
+# rtdyld-check: *{8}k = f
146ec0c
+# RUN: llvm-mc -triple=aarch64_be-none-linux-gnu -filetype=obj -o %T/be-reloc.o %s
146ec0c
+# RUN: llvm-rtdyld -triple=aarch64_be-none-linux-gnu -verify -dummy-extern f=0x0123456789abcdef -check=%s %T/be-reloc.o
146ec0c
+
146ec0c
+        .text
146ec0c
+        .globl  g
146ec0c
+        .p2align        2
146ec0c
+        .type   g,@function
146ec0c
+g:
146ec0c
+# R_AARCH64_MOVW_UABS_G3
146ec0c
+        movz    x0, #:abs_g3:f
146ec0c
+# R_AARCH64_MOVW_UABS_G2_NC
146ec0c
+        movk    x0, #:abs_g2_nc:f
146ec0c
+# R_AARCH64_MOVW_UABS_G1_NC
146ec0c
+        movk    x0, #:abs_g1_nc:f
146ec0c
+# R_AARCH64_MOVW_UABS_G0_NC
146ec0c
+        movk    x0, #:abs_g0_nc:f
146ec0c
+        ret
146ec0c
+        .Lfunc_end0:
146ec0c
+        .size   g, .Lfunc_end0-g
146ec0c
+
146ec0c
+        .type   k,@object
146ec0c
+        .data
146ec0c
+        .globl  k
146ec0c
+        .p2align        3
146ec0c
+k:
146ec0c
+        .xword  f
146ec0c
+        .size   k, 8
146ec0c
+
146ec0c
+# LE instructions read as BE
146ec0c
+# rtdyld-check: *{4}(g) = 0x6024e0d2
146ec0c
+# rtdyld-check: *{4}(g + 4) = 0xe0acc8f2
146ec0c
+# rtdyld-check: *{4}(g + 8) = 0x6035b1f2
146ec0c
+# rtdyld-check: *{4}(g + 12) = 0xe0bd99f2
146ec0c
+# rtdyld-check: *{8}k = f
146ec0c
diff --git a/llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_relocations.s b/llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_relocations.s
146ec0c
new file mode 100644
146ec0c
index 0000000..e07fa97
146ec0c
--- /dev/null
146ec0c
+++ b/llvm-3.9.1.src/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_relocations.s
146ec0c
@@ -0,0 +1,99 @@
146ec0c
+# RUN: llvm-mc -triple=arm64-none-linux-gnu -filetype=obj -o %T/reloc.o %s
146ec0c
+# RUN: llvm-rtdyld -triple=arm64-none-linux-gnu -verify -dummy-extern f=0x0123456789abcdef -check=%s %T/reloc.o
146ec0c
+
146ec0c
+        .text
146ec0c
+        .globl  g
146ec0c
+        .p2align        2
146ec0c
+        .type   g,@function
146ec0c
+g:
146ec0c
+# R_AARCH64_MOVW_UABS_G3
146ec0c
+        movz    x0, #:abs_g3:f
146ec0c
+# R_AARCH64_MOVW_UABS_G2_NC
146ec0c
+        movk    x0, #:abs_g2_nc:f
146ec0c
+# R_AARCH64_MOVW_UABS_G1_NC
146ec0c
+        movk    x0, #:abs_g1_nc:f
146ec0c
+# R_AARCH64_MOVW_UABS_G0_NC
146ec0c
+        movk    x0, #:abs_g0_nc:f
146ec0c
+        ret
146ec0c
+        .Lfunc_end0:
146ec0c
+        .size   g, .Lfunc_end0-g
146ec0c
+
146ec0c
+        .type   k,@object
146ec0c
+        .data
146ec0c
+        .globl  k
146ec0c
+        .p2align        3
146ec0c
+k:
146ec0c
+        .xword  f
146ec0c
+        .size   k, 8
146ec0c
+
146ec0c
+# rtdyld-check: *{4}(g) = 0xd2e02460
146ec0c
+# rtdyld-check: *{4}(g + 4) = 0xf2c8ace0
146ec0c
+# rtdyld-check: *{4}(g + 8) = 0xf2b13560
146ec0c
+# rtdyld-check: *{4}(g + 12) = 0xf299bde0
146ec0c
+# rtdyld-check: *{8}k = f
146ec0c
+# RUN: llvm-mc -triple=arm64-none-linux-gnu -filetype=obj -o %T/reloc.o %s
146ec0c
+# RUN: llvm-rtdyld -triple=arm64-none-linux-gnu -verify -dummy-extern f=0x0123456789abcdef -check=%s %T/reloc.o
146ec0c
+
146ec0c
+        .text
146ec0c
+        .globl  g
146ec0c
+        .p2align        2
146ec0c
+        .type   g,@function
146ec0c
+g:
146ec0c
+# R_AARCH64_MOVW_UABS_G3
146ec0c
+        movz    x0, #:abs_g3:f
146ec0c
+# R_AARCH64_MOVW_UABS_G2_NC
146ec0c
+        movk    x0, #:abs_g2_nc:f
146ec0c
+# R_AARCH64_MOVW_UABS_G1_NC
146ec0c
+        movk    x0, #:abs_g1_nc:f
146ec0c
+# R_AARCH64_MOVW_UABS_G0_NC
146ec0c
+        movk    x0, #:abs_g0_nc:f
146ec0c
+        ret
146ec0c
+        .Lfunc_end0:
146ec0c
+        .size   g, .Lfunc_end0-g
146ec0c
+
146ec0c
+        .type   k,@object
146ec0c
+        .data
146ec0c
+        .globl  k
146ec0c
+        .p2align        3
146ec0c
+k:
146ec0c
+        .xword  f
146ec0c
+        .size   k, 8
146ec0c
+
146ec0c
+# rtdyld-check: *{4}(g) = 0xd2e02460
146ec0c
+# rtdyld-check: *{4}(g + 4) = 0xf2c8ace0
146ec0c
+# rtdyld-check: *{4}(g + 8) = 0xf2b13560
146ec0c
+# rtdyld-check: *{4}(g + 12) = 0xf299bde0
146ec0c
+# rtdyld-check: *{8}k = f
146ec0c
+# RUN: llvm-mc -triple=arm64-none-linux-gnu -filetype=obj -o %T/reloc.o %s
146ec0c
+# RUN: llvm-rtdyld -triple=arm64-none-linux-gnu -verify -dummy-extern f=0x0123456789abcdef -check=%s %T/reloc.o
146ec0c
+
146ec0c
+        .text
146ec0c
+        .globl  g
146ec0c
+        .p2align        2
146ec0c
+        .type   g,@function
146ec0c
+g:
146ec0c
+# R_AARCH64_MOVW_UABS_G3
146ec0c
+        movz    x0, #:abs_g3:f
146ec0c
+# R_AARCH64_MOVW_UABS_G2_NC
146ec0c
+        movk    x0, #:abs_g2_nc:f
146ec0c
+# R_AARCH64_MOVW_UABS_G1_NC
146ec0c
+        movk    x0, #:abs_g1_nc:f
146ec0c
+# R_AARCH64_MOVW_UABS_G0_NC
146ec0c
+        movk    x0, #:abs_g0_nc:f
146ec0c
+        ret
146ec0c
+        .Lfunc_end0:
146ec0c
+        .size   g, .Lfunc_end0-g
146ec0c
+
146ec0c
+        .type   k,@object
146ec0c
+        .data
146ec0c
+        .globl  k
146ec0c
+        .p2align        3
146ec0c
+k:
146ec0c
+        .xword  f
146ec0c
+        .size   k, 8
146ec0c
+
146ec0c
+# rtdyld-check: *{4}(g) = 0xd2e02460
146ec0c
+# rtdyld-check: *{4}(g + 4) = 0xf2c8ace0
146ec0c
+# rtdyld-check: *{4}(g + 8) = 0xf2b13560
146ec0c
+# rtdyld-check: *{4}(g + 12) = 0xf299bde0
146ec0c
+# rtdyld-check: *{8}k = f
146ec0c
-- 
146ec0c
2.12.0
146ec0c