[PATCH] D94612: [LLD][ELF][AArch64] Add support for R_AARCH64_LD64_GOTPAGE_LO15 relocation

Adhemerval Zanella via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 13 09:35:38 PST 2021


zatrazz created this revision.
zatrazz added reviewers: grimar, peter.smith, ruiu, MaskRay.
Herald added subscribers: danielkiss, kristof.beyls, arichardson, emaste.
Herald added a reviewer: espindola.
zatrazz requested review of this revision.
Herald added a project: LLVM.

It is not used by LLVM, but GCC might generates it when compiling
with -fpie, as indicated by PR#40357 [1].

The testcase depends on https://reviews.llvm.org/D94611 to parse
gotpage_lo15.

[1] https://bugs.llvm.org/show_bug.cgi?id=40357


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94612

Files:
  lld/ELF/Arch/AArch64.cpp
  lld/ELF/InputSection.cpp
  lld/ELF/Relocations.cpp
  lld/ELF/Relocations.h
  lld/test/ELF/aarch64-gotpage.s


Index: lld/test/ELF/aarch64-gotpage.s
===================================================================
--- /dev/null
+++ lld/test/ELF/aarch64-gotpage.s
@@ -0,0 +1,24 @@
+# REQUIRES: aarch64
+# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %s -o %t.o
+# RUN: ld.lld -pie %t.o -o %t
+# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOCS %s
+
+# Check if the R_AARCH64_LD64_GOTPAGE_LO15 generates the GOT entries.
+# RELOCS:      Relocations [
+# RELOCS-NEXT:   Section (5) .rela.dyn {
+# RELOCS-NEXT:     0x{{[0-9A-F]+}} R_AARCH64_RELATIVE - 0x{{[0-9A-F]+}}
+# RELOCS-NEXT:     0x{{[0-9A-F]+}} R_AARCH64_RELATIVE - 0x{{[0-9A-F]+}}
+# RELOCS-NEXT:   }
+# RELOCS-NEXT: ]
+
+	.globl	_start
+	.type	_start, at function
+_start:
+	adrp    x0, _GLOBAL_OFFSET_TABLE_
+	ldr     x0, [x0, #:gotpage_lo15:global1]
+	ldr     x1, [x0, #:gotpage_lo15:global2]
+
+	.type   global1, at object
+	.comm   global1,4,4
+	.type   global2, at object
+	.comm   global2,8,8
Index: lld/ELF/Relocations.h
===================================================================
--- lld/ELF/Relocations.h
+++ lld/ELF/Relocations.h
@@ -78,6 +78,7 @@
   // of a relocation type, there are some relocations whose semantics are
   // unique to a target. Such relocation are marked with R_<TARGET_NAME>.
   R_AARCH64_GOT_PAGE_PC,
+  R_AARCH64_GOT_PAGE,
   R_AARCH64_PAGE_PC,
   R_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC,
   R_AARCH64_TLSDESC_PAGE,
Index: lld/ELF/Relocations.cpp
===================================================================
--- lld/ELF/Relocations.cpp
+++ lld/ELF/Relocations.cpp
@@ -381,7 +381,8 @@
 // TLS variables uses GOT differently than the regular variables.
 static bool needsGot(RelExpr expr) {
   return oneof<R_GOT, R_GOT_OFF, R_MIPS_GOT_LOCAL_PAGE, R_MIPS_GOT_OFF,
-               R_MIPS_GOT_OFF32, R_AARCH64_GOT_PAGE_PC, R_GOT_PC, R_GOTPLT>(
+               R_MIPS_GOT_OFF32, R_AARCH64_GOT_PAGE_PC, R_GOT_PC, R_GOTPLT,
+               R_AARCH64_GOT_PAGE>(
       expr);
 }
 
Index: lld/ELF/InputSection.cpp
===================================================================
--- lld/ELF/InputSection.cpp
+++ lld/ELF/InputSection.cpp
@@ -705,6 +705,8 @@
   case R_AARCH64_GOT_PAGE_PC:
   case R_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC:
     return getAArch64Page(sym.getGotVA() + a) - getAArch64Page(p);
+  case R_AARCH64_GOT_PAGE:
+    return sym.getGotVA() - getAArch64Page(p);
   case R_GOT_PC:
   case R_RELAX_TLS_GD_TO_IE:
     return sym.getGotVA() + a - p;
Index: lld/ELF/Arch/AArch64.cpp
===================================================================
--- lld/ELF/Arch/AArch64.cpp
+++ lld/ELF/Arch/AArch64.cpp
@@ -146,6 +146,8 @@
   case R_AARCH64_LD64_GOT_LO12_NC:
   case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
     return R_GOT;
+  case R_AARCH64_LD64_GOTPAGE_LO15:
+    return R_AARCH64_GOT_PAGE;
   case R_AARCH64_ADR_GOT_PAGE:
   case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
     return R_AARCH64_GOT_PAGE_PC;
@@ -398,6 +400,10 @@
     checkAlignment(loc, val, 16, rel);
     or32AArch64Imm(loc, getBits(val, 4, 11));
     break;
+  case  R_AARCH64_LD64_GOTPAGE_LO15:
+    checkAlignment(loc, val, 8, rel);
+    or32AArch64Imm(loc, getBits(val, 3, 14));
+    break;
   case R_AARCH64_MOVW_UABS_G0:
     checkUInt(loc, val, 16, rel);
     LLVM_FALLTHROUGH;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94612.316434.patch
Type: text/x-patch
Size: 3270 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210113/2dc49462/attachment.bin>


More information about the llvm-commits mailing list