<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Oct 2, 2015 at 3:00 PM, Davide Italiano via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: davide<br>
Date: Fri Oct  2 17:00:42 2015<br>
New Revision: 249195<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=249195&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=249195&view=rev</a><br>
Log:<br>
[ELF2/AArch64] Add support for R_AARCH64_ADR_PREL_PG_H121<br>
<br>
Modified:<br>
    lld/trunk/ELF/Target.cpp<br>
    lld/trunk/test/elf2/aarch64-relocs.s<br>
<br>
Modified: lld/trunk/ELF/Target.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=249195&r1=249194&r2=249195&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=249195&r1=249194&r2=249195&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Target.cpp (original)<br>
+++ lld/trunk/ELF/Target.cpp Fri Oct  2 17:00:42 2015<br>
@@ -253,16 +253,31 @@ bool AArch64TargetInfo::relocNeedsPlt(ui<br>
   return false;<br>
 }<br>
<br>
+static void AArch64UpdateAdr(uint8_t *Location, uint64_t Imm) {<br>
+  uint32_t ImmLo = (Imm & 0x3) << 29;<br>
+  uint32_t ImmHi = ((Imm & 0x1FFFFC) >> 2) << 5;<br>
+  uint64_t Mask = (0x3 << 29) | (0x7FFFF << 5);<br>
+  write32le(Location, (read32le(Location) & ~Mask) | ImmLo | ImmHi);<br>
+}<br>
+<br>
+static uint64_t AArch64GetPage(uint64_t Address) {<br>
+  return (Address & (~static_cast<uint64_t>(0xFFF)));<br></blockquote><div><br></div><div>nit: we usually don't enclose an expression after return with () even if with &?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+}<br>
+<br>
 static void handle_ADR_PREL_LO21(uint8_t *Location, uint64_t S, int64_t A,<br>
                                  uint64_t P) {<br>
   uint64_t X = S + A - P;<br>
   if (!isInt<21>(X))<br>
     error("Relocation R_AARCH64_ADR_PREL_LO21 out of range");<br>
-  uint32_t Imm = X & 0x1FFFFF;<br>
-  uint32_t ImmLo = (Imm & 0x3) << 29;<br>
-  uint32_t ImmHi = ((Imm & 0x1FFFFC) >> 2) << 5;<br>
-  uint64_t Mask = (0x3 << 29) | (0x7FFFF << 5);<br>
-  write32le(Location, (read32le(Location) & ~Mask) | ImmLo | ImmHi);<br>
+  AArch64UpdateAdr(Location, X & 0x1FFFFF);<br>
+}<br>
+<br>
+static void handle_ADR_PREL_PG_HI21(uint8_t *Location, uint64_t S, int64_t A,<br>
+                                    uint64_t P) {<br>
+  uint64_t X = AArch64GetPage(S + A) - AArch64GetPage(P);<br>
+  if (!isInt<33>(X))<br>
+    error("Relocation R_AARCH64_ADR_PREL_PG_HI21 out of range");<br>
+  AArch64UpdateAdr(Location, (X >> 12) & 0x1FFFFF); // X[32:12]<br>
 }<br>
<br>
 void AArch64TargetInfo::relocateOne(uint8_t *Buf, const void *RelP,<br>
@@ -279,6 +294,9 @@ void AArch64TargetInfo::relocateOne(uint<br>
   case R_AARCH64_ADR_PREL_LO21:<br>
     handle_ADR_PREL_LO21(Location, S, A, P);<br>
     break;<br>
+  case R_AARCH64_ADR_PREL_PG_HI21:<br>
+    handle_ADR_PREL_PG_HI21(Location, S, A, P);<br>
+    break;<br>
   default:<br>
     error(Twine("unrecognized reloc ") + Twine(Type));<br>
     break;<br>
<br>
Modified: lld/trunk/test/elf2/aarch64-relocs.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/aarch64-relocs.s?rev=249195&r1=249194&r2=249195&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/aarch64-relocs.s?rev=249195&r1=249194&r2=249195&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/aarch64-relocs.s (original)<br>
+++ lld/trunk/test/elf2/aarch64-relocs.s Fri Oct  2 17:00:42 2015<br>
@@ -16,3 +16,17 @@ msgend:<br>
 # CHECK: msg:<br>
 # CHECK:        4:<br>
 # #4 is the adr immediate value.<br>
+<br>
+.section .R_AARCH64_ADR_PREL_PG_H121,"ax",@progbits<br>
+  adrp x1,mystr<br>
+mystr:<br>
+  .asciz "blah"<br>
+  .size mystr, 4<br>
+<br>
+# S = 0x11012, A = 0x4, P = 0x11012<br>
+# PAGE(S + A) = 0x11000<br>
+# PAGE(P) = 0x11000<br>
+#<br>
+# CHECK: Disassembly of section .R_AARCH64_ADR_PREL_PG_H121:<br>
+# CHECK-NEXT: $x.2:<br>
+# CHECK-NEXT:   11012:       01 00 00 90     adrp    x1, #0<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>