[llvm-branch-commits] [lld] [PAC][lld][AArch64][ELF] Support signed GOT with tiny code model (PR #113816)

Daniil Kovalev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Dec 15 23:43:22 PST 2024


https://github.com/kovdan01 updated https://github.com/llvm/llvm-project/pull/113816

>From ec3a34c2cb55f3179739c2c068e1c3d1c1de5b9a Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Fri, 25 Oct 2024 21:28:18 +0300
Subject: [PATCH 01/10] [PAC][lld][AArch64][ELF] Support signed GOT with tiny
 code model

Support `R_AARCH64_AUTH_GOT_ADR_PREL_LO21` and `R_AARCH64_AUTH_GOT_LD_PREL19`
GOT-generating relocations.
---
 lld/ELF/Arch/AArch64.cpp                     |  5 ++
 lld/ELF/InputSection.cpp                     |  1 +
 lld/ELF/Relocations.cpp                      | 11 +--
 lld/ELF/Relocations.h                        |  1 +
 lld/test/ELF/aarch64-got-relocations-pauth.s | 73 ++++++++++++++++++++
 5 files changed, 87 insertions(+), 4 deletions(-)

diff --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp
index 9571e0e9566fc3..b63551d0f682e5 100644
--- a/lld/ELF/Arch/AArch64.cpp
+++ b/lld/ELF/Arch/AArch64.cpp
@@ -205,6 +205,9 @@ RelExpr AArch64::getRelExpr(RelType type, const Symbol &s,
   case R_AARCH64_AUTH_LD64_GOT_LO12_NC:
   case R_AARCH64_AUTH_GOT_ADD_LO12_NC:
     return RE_AARCH64_AUTH_GOT;
+  case R_AARCH64_AUTH_GOT_LD_PREL19:
+  case R_AARCH64_AUTH_GOT_ADR_PREL_LO21:
+    return RE_AARCH64_AUTH_GOT_PC;
   case R_AARCH64_LD64_GOTPAGE_LO15:
     return RE_AARCH64_GOT_PAGE;
   case R_AARCH64_ADR_GOT_PAGE:
@@ -548,6 +551,7 @@ void AArch64::relocate(uint8_t *loc, const Relocation &rel,
     write32AArch64Addr(loc, val >> 12);
     break;
   case R_AARCH64_ADR_PREL_LO21:
+  case R_AARCH64_AUTH_GOT_ADR_PREL_LO21:
     checkInt(ctx, loc, val, 21, rel);
     write32AArch64Addr(loc, val);
     break;
@@ -568,6 +572,7 @@ void AArch64::relocate(uint8_t *loc, const Relocation &rel,
   case R_AARCH64_CONDBR19:
   case R_AARCH64_LD_PREL_LO19:
   case R_AARCH64_GOT_LD_PREL19:
+  case R_AARCH64_AUTH_GOT_LD_PREL19:
     checkAlignment(ctx, loc, val, 4, rel);
     checkInt(ctx, loc, val, 21, rel);
     writeMaskedBits32le(loc, (val & 0x1FFFFC) << 3, 0x1FFFFC << 3);
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 26dc5c606f57f9..76af4ec4193a4f 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -817,6 +817,7 @@ uint64_t InputSectionBase::getRelocTargetVA(Ctx &ctx, const Relocation &r,
   case RE_AARCH64_GOT_PAGE:
     return r.sym->getGotVA(ctx) + a - getAArch64Page(ctx.in.got->getVA());
   case R_GOT_PC:
+  case R_AARCH64_AUTH_GOT_PC:
   case R_RELAX_TLS_GD_TO_IE:
     return r.sym->getGotVA(ctx) + a - p;
   case R_GOTPLT_GOTREL:
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 07cbdb7806fde1..690b4933bb809e 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -197,8 +197,9 @@ static bool needsPlt(RelExpr expr) {
 }
 
 bool lld::elf::needsGot(RelExpr expr) {
-  return oneof<R_GOT, RE_AARCH64_AUTH_GOT, R_GOT_OFF, RE_MIPS_GOT_LOCAL_PAGE,
-               RE_MIPS_GOT_OFF, RE_MIPS_GOT_OFF32, RE_AARCH64_GOT_PAGE_PC,
+  return oneof<R_GOT, RE_AARCH64_AUTH_GOT, RE_AARCH64_AUTH_GOT_PC, R_GOT_OFF,
+               RE_MIPS_GOT_LOCAL_PAGE, RE_MIPS_GOT_OFF, RE_MIPS_GOT_OFF32,
+               RE_AARCH64_GOT_PAGE_PC, RE_AARCH64_AUTH_GOT_PAGE_PC,
                RE_AARCH64_AUTH_GOT_PAGE_PC, R_GOT_PC, R_GOTPLT,
                RE_AARCH64_GOT_PAGE, RE_LOONGARCH_GOT, RE_LOONGARCH_GOT_PAGE_PC>(
       expr);
@@ -981,7 +982,8 @@ bool RelocationScanner::isStaticLinkTimeConstant(RelExpr e, RelType type,
             R_GOTPLTONLY_PC, R_PLT_PC, R_PLT_GOTREL, R_PLT_GOTPLT,
             R_GOTPLT_GOTREL, R_GOTPLT_PC, RE_PPC32_PLTREL, RE_PPC64_CALL_PLT,
             RE_PPC64_RELAX_TOC, RE_RISCV_ADD, RE_AARCH64_GOT_PAGE,
-            RE_AARCH64_AUTH_GOT, RE_LOONGARCH_PLT_PAGE_PC, RE_LOONGARCH_GOT,
+            RE_AARCH64_AUTH_GOT, RE_AARCH64_AUTH_GOT_PC,
+            RE_LOONGARCH_PLT_PAGE_PC, RE_LOONGARCH_GOT,
             RE_LOONGARCH_GOT_PAGE_PC>(e))
     return true;
 
@@ -1096,7 +1098,8 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
     } else if (!sym.isTls() || ctx.arg.emachine != EM_LOONGARCH) {
       // Many LoongArch TLS relocs reuse the RE_LOONGARCH_GOT type, in which
       // case the NEEDS_GOT flag shouldn't get set.
-      if (expr == RE_AARCH64_AUTH_GOT || expr == RE_AARCH64_AUTH_GOT_PAGE_PC)
+      if (expr == RE_AARCH64_AUTH_GOT || expr == RE_AARCH64_AUTH_GOT_PAGE_PC ||
+          expr == RE_AARCH64_AUTH_GOT_PAGE_PC)
         sym.setFlags(NEEDS_GOT | NEEDS_GOT_AUTH);
       else
         sym.setFlags(NEEDS_GOT | NEEDS_GOT_NONAUTH);
diff --git a/lld/ELF/Relocations.h b/lld/ELF/Relocations.h
index d993ab77adc3cc..fde25a230b72e6 100644
--- a/lld/ELF/Relocations.h
+++ b/lld/ELF/Relocations.h
@@ -95,6 +95,7 @@ enum RelExpr {
   RE_AARCH64_AUTH_GOT_PAGE_PC,
   RE_AARCH64_GOT_PAGE,
   RE_AARCH64_AUTH_GOT,
+  RE_AARCH64_AUTH_GOT_PC,
   RE_AARCH64_PAGE_PC,
   RE_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC,
   RE_AARCH64_TLSDESC_PAGE,
diff --git a/lld/test/ELF/aarch64-got-relocations-pauth.s b/lld/test/ELF/aarch64-got-relocations-pauth.s
index 985ab302259ea3..ef871d2af93671 100644
--- a/lld/test/ELF/aarch64-got-relocations-pauth.s
+++ b/lld/test/ELF/aarch64-got-relocations-pauth.s
@@ -77,6 +77,79 @@ _start:
   adrp x1, :got_auth:zed
   add  x1, x1, :got_auth_lo12:zed
 
+#--- ok-tiny.s
+
+# RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux ok-tiny.s -o ok-tiny.o
+
+# RUN: ld.lld ok-tiny.o a.so -pie -o external-tiny
+# RUN: llvm-readelf -r -S -x .got external-tiny | FileCheck %s --check-prefix=EXTERNAL-TINY
+
+# RUN: ld.lld ok-tiny.o a.o -pie -o local-tiny
+# RUN: llvm-readelf -r -S -x .got -s local-tiny | FileCheck %s --check-prefix=LOCAL-TINY
+
+# EXTERNAL-TINY:      Offset            Info             Type                    Symbol's Value   Symbol's Name + Addend
+# EXTERNAL-TINY-NEXT: 0000000000020380  000000010000e201 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 bar + 0
+# EXTERNAL-TINY-NEXT: 0000000000020388  000000020000e201 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 zed + 0
+
+## Symbol's values for bar and zed are equal since they contain no content (see Inputs/shared.s)
+# LOCAL-TINY:         Offset            Info             Type                    Symbol's Value   Symbol's Name + Addend
+# LOCAL-TINY-NEXT:    0000000000020320  0000000000000411 R_AARCH64_AUTH_RELATIVE 10260
+# LOCAL-TINY-NEXT:    0000000000020328  0000000000000411 R_AARCH64_AUTH_RELATIVE 10260
+
+# EXTERNAL-TINY:      Hex dump of section '.got':
+# EXTERNAL-TINY-NEXT: 0x00020380 00000000 00000080 00000000 000000a0
+#                                               ^^
+#                                               0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
+#                                                                 ^^
+#                                                                 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+
+# LOCAL-TINY: Symbol table '.symtab' contains {{.*}} entries:
+# LOCAL-TINY:    Num:    Value          Size Type    Bind   Vis       Ndx Name
+# LOCAL-TINY:         0000000000010260     0 FUNC    GLOBAL DEFAULT     6 bar
+# LOCAL-TINY:         0000000000010260     0 NOTYPE  GLOBAL DEFAULT     6 zed
+
+# LOCAL-TINY:         Hex dump of section '.got':
+# LOCAL-TINY-NEXT:    0x00020320 00000000 00000080 00000000 000000a0
+#                                               ^^
+#                                               0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
+#                                                                 ^^
+#                                                                 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+
+# RUN: llvm-objdump -d external-tiny | FileCheck %s --check-prefix=EXTERNAL-TINY-ASM
+
+# EXTERNAL-TINY-ASM:      <_start>:
+# EXTERNAL-TINY-ASM-NEXT: adr x0, 0x20380
+# EXTERNAL-TINY-ASM-NEXT: ldr x1, [x0]
+# EXTERNAL-TINY-ASM-NEXT: adr x0, 0x20380
+# EXTERNAL-TINY-ASM-NEXT: ldr x1, 0x20380
+# EXTERNAL-TINY-ASM-NEXT: adr x0, 0x20388
+# EXTERNAL-TINY-ASM-NEXT: ldr x1, [x0]
+# EXTERNAL-TINY-ASM-NEXT: adr x0, 0x20388
+# EXTERNAL-TINY-ASM-NEXT: ldr x1, 0x20388
+
+# RUN: llvm-objdump -d local-tiny | FileCheck %s --check-prefix=LOCAL-TINY-ASM
+
+# LOCAL-TINY-ASM:         <_start>:
+# LOCAL-TINY-ASM-NEXT:    adr x0, 0x20320
+# LOCAL-TINY-ASM-NEXT:    ldr x1, [x0]
+# LOCAL-TINY-ASM-NEXT:    adr x0, 0x20320
+# LOCAL-TINY-ASM-NEXT:    ldr x1, 0x20320
+# LOCAL-TINY-ASM-NEXT:    adr x0, 0x20328
+# LOCAL-TINY-ASM-NEXT:    ldr x1, [x0]
+# LOCAL-TINY-ASM-NEXT:    adr x0, 0x20328
+# LOCAL-TINY-ASM-NEXT:    ldr x1, 0x20328
+
+.globl _start
+_start:
+  adr  x0, :got_auth:bar
+  ldr  x1, [x0]
+  adr  x0, :got_auth:bar
+  ldr  x1, :got_auth:bar
+  adr  x0, :got_auth:zed
+  ldr  x1, [x0]
+  adr  x0, :got_auth:zed
+  ldr  x1, :got_auth:zed
+
 #--- err.s
 # RUN: llvm-mc -filetype=obj -triple=aarch64 err.s -o err.o
 # RUN: not ld.lld err.o a.so -pie -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR --implicit-check-not=error:

>From c8af5cfc5eaef63084d2d3c7e17527e9c156fc13 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Fri, 1 Nov 2024 13:18:43 +0300
Subject: [PATCH 02/10] Use `##` for comments in tests

---
 lld/test/ELF/aarch64-got-relocations-pauth.s | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/lld/test/ELF/aarch64-got-relocations-pauth.s b/lld/test/ELF/aarch64-got-relocations-pauth.s
index ef871d2af93671..1a9f8fd8a675f1 100644
--- a/lld/test/ELF/aarch64-got-relocations-pauth.s
+++ b/lld/test/ELF/aarch64-got-relocations-pauth.s
@@ -98,10 +98,10 @@ _start:
 
 # EXTERNAL-TINY:      Hex dump of section '.got':
 # EXTERNAL-TINY-NEXT: 0x00020380 00000000 00000080 00000000 000000a0
-#                                               ^^
-#                                               0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
-#                                                                 ^^
-#                                                                 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+##                                              ^^
+##                                              0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
+##                                                                ^^
+##                                                                0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
 
 # LOCAL-TINY: Symbol table '.symtab' contains {{.*}} entries:
 # LOCAL-TINY:    Num:    Value          Size Type    Bind   Vis       Ndx Name
@@ -110,10 +110,10 @@ _start:
 
 # LOCAL-TINY:         Hex dump of section '.got':
 # LOCAL-TINY-NEXT:    0x00020320 00000000 00000080 00000000 000000a0
-#                                               ^^
-#                                               0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
-#                                                                 ^^
-#                                                                 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+##                                              ^^
+##                                              0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
+##                                                                ^^
+##                                                                0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
 
 # RUN: llvm-objdump -d external-tiny | FileCheck %s --check-prefix=EXTERNAL-TINY-ASM
 

>From c56e0397cda62c0124e4e75427653aad64e29f23 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Mon, 18 Nov 2024 08:33:11 +0300
Subject: [PATCH 03/10] Address review comments

---
 lld/test/ELF/aarch64-got-relocations-pauth.s | 44 ++++++--------------
 1 file changed, 13 insertions(+), 31 deletions(-)

diff --git a/lld/test/ELF/aarch64-got-relocations-pauth.s b/lld/test/ELF/aarch64-got-relocations-pauth.s
index 1a9f8fd8a675f1..34b99ccdc463a1 100644
--- a/lld/test/ELF/aarch64-got-relocations-pauth.s
+++ b/lld/test/ELF/aarch64-got-relocations-pauth.s
@@ -79,7 +79,7 @@ _start:
 
 #--- ok-tiny.s
 
-# RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux ok-tiny.s -o ok-tiny.o
+# RUN: llvm-mc -filetype=obj -triple=aarch64 ok-tiny.s -o ok-tiny.o
 
 # RUN: ld.lld ok-tiny.o a.so -pie -o external-tiny
 # RUN: llvm-readelf -r -S -x .got external-tiny | FileCheck %s --check-prefix=EXTERNAL-TINY
@@ -88,16 +88,16 @@ _start:
 # RUN: llvm-readelf -r -S -x .got -s local-tiny | FileCheck %s --check-prefix=LOCAL-TINY
 
 # EXTERNAL-TINY:      Offset            Info             Type                    Symbol's Value   Symbol's Name + Addend
-# EXTERNAL-TINY-NEXT: 0000000000020380  000000010000e201 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 bar + 0
-# EXTERNAL-TINY-NEXT: 0000000000020388  000000020000e201 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 zed + 0
+# EXTERNAL-TINY-NEXT: 0000000000020368  000000010000e201 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 bar + 0
+# EXTERNAL-TINY-NEXT: 0000000000020370  000000020000e201 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 zed + 0
 
 ## Symbol's values for bar and zed are equal since they contain no content (see Inputs/shared.s)
 # LOCAL-TINY:         Offset            Info             Type                    Symbol's Value   Symbol's Name + Addend
-# LOCAL-TINY-NEXT:    0000000000020320  0000000000000411 R_AARCH64_AUTH_RELATIVE 10260
-# LOCAL-TINY-NEXT:    0000000000020328  0000000000000411 R_AARCH64_AUTH_RELATIVE 10260
+# LOCAL-TINY-NEXT:    0000000000020308  0000000000000411 R_AARCH64_AUTH_RELATIVE 10248
+# LOCAL-TINY-NEXT:    0000000000020310  0000000000000411 R_AARCH64_AUTH_RELATIVE 10248
 
 # EXTERNAL-TINY:      Hex dump of section '.got':
-# EXTERNAL-TINY-NEXT: 0x00020380 00000000 00000080 00000000 000000a0
+# EXTERNAL-TINY-NEXT: 0x00020368 00000000 00000080 00000000 000000a0
 ##                                              ^^
 ##                                              0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
 ##                                                                ^^
@@ -105,11 +105,11 @@ _start:
 
 # LOCAL-TINY: Symbol table '.symtab' contains {{.*}} entries:
 # LOCAL-TINY:    Num:    Value          Size Type    Bind   Vis       Ndx Name
-# LOCAL-TINY:         0000000000010260     0 FUNC    GLOBAL DEFAULT     6 bar
-# LOCAL-TINY:         0000000000010260     0 NOTYPE  GLOBAL DEFAULT     6 zed
+# LOCAL-TINY:         0000000000010248     0 FUNC    GLOBAL DEFAULT     6 bar
+# LOCAL-TINY:         0000000000010248     0 NOTYPE  GLOBAL DEFAULT     6 zed
 
 # LOCAL-TINY:         Hex dump of section '.got':
-# LOCAL-TINY-NEXT:    0x00020320 00000000 00000080 00000000 000000a0
+# LOCAL-TINY-NEXT:    0x00020308 00000000 00000080 00000000 000000a0
 ##                                              ^^
 ##                                              0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
 ##                                                                ^^
@@ -118,36 +118,18 @@ _start:
 # RUN: llvm-objdump -d external-tiny | FileCheck %s --check-prefix=EXTERNAL-TINY-ASM
 
 # EXTERNAL-TINY-ASM:      <_start>:
-# EXTERNAL-TINY-ASM-NEXT: adr x0, 0x20380
-# EXTERNAL-TINY-ASM-NEXT: ldr x1, [x0]
-# EXTERNAL-TINY-ASM-NEXT: adr x0, 0x20380
-# EXTERNAL-TINY-ASM-NEXT: ldr x1, 0x20380
-# EXTERNAL-TINY-ASM-NEXT: adr x0, 0x20388
-# EXTERNAL-TINY-ASM-NEXT: ldr x1, [x0]
-# EXTERNAL-TINY-ASM-NEXT: adr x0, 0x20388
-# EXTERNAL-TINY-ASM-NEXT: ldr x1, 0x20388
+# EXTERNAL-TINY-ASM-NEXT: adr x0, 0x20368
+# EXTERNAL-TINY-ASM-NEXT: ldr x1, 0x20370
 
 # RUN: llvm-objdump -d local-tiny | FileCheck %s --check-prefix=LOCAL-TINY-ASM
 
 # LOCAL-TINY-ASM:         <_start>:
-# LOCAL-TINY-ASM-NEXT:    adr x0, 0x20320
-# LOCAL-TINY-ASM-NEXT:    ldr x1, [x0]
-# LOCAL-TINY-ASM-NEXT:    adr x0, 0x20320
-# LOCAL-TINY-ASM-NEXT:    ldr x1, 0x20320
-# LOCAL-TINY-ASM-NEXT:    adr x0, 0x20328
-# LOCAL-TINY-ASM-NEXT:    ldr x1, [x0]
-# LOCAL-TINY-ASM-NEXT:    adr x0, 0x20328
-# LOCAL-TINY-ASM-NEXT:    ldr x1, 0x20328
+# LOCAL-TINY-ASM-NEXT:    adr x0, 0x20308
+# LOCAL-TINY-ASM-NEXT:    ldr x1, 0x20310
 
 .globl _start
 _start:
   adr  x0, :got_auth:bar
-  ldr  x1, [x0]
-  adr  x0, :got_auth:bar
-  ldr  x1, :got_auth:bar
-  adr  x0, :got_auth:zed
-  ldr  x1, [x0]
-  adr  x0, :got_auth:zed
   ldr  x1, :got_auth:zed
 
 #--- err.s

>From 15c9908d745c72b456a4a29fc64f4bdf7a9cd290 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Mon, 2 Dec 2024 01:26:30 +0300
Subject: [PATCH 04/10] Remove unneeded blank line in test

---
 lld/test/ELF/aarch64-got-relocations-pauth.s | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lld/test/ELF/aarch64-got-relocations-pauth.s b/lld/test/ELF/aarch64-got-relocations-pauth.s
index 34b99ccdc463a1..5a1d009c3ee282 100644
--- a/lld/test/ELF/aarch64-got-relocations-pauth.s
+++ b/lld/test/ELF/aarch64-got-relocations-pauth.s
@@ -78,7 +78,6 @@ _start:
   add  x1, x1, :got_auth_lo12:zed
 
 #--- ok-tiny.s
-
 # RUN: llvm-mc -filetype=obj -triple=aarch64 ok-tiny.s -o ok-tiny.o
 
 # RUN: ld.lld ok-tiny.o a.so -pie -o external-tiny

>From 6dd8d2cb761e556f188214fa501267e554c56779 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Wed, 4 Dec 2024 14:50:34 +0300
Subject: [PATCH 05/10] Fix build after #118424

---
 lld/ELF/InputSection.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 76af4ec4193a4f..efa7ba3e7cb063 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -817,7 +817,7 @@ uint64_t InputSectionBase::getRelocTargetVA(Ctx &ctx, const Relocation &r,
   case RE_AARCH64_GOT_PAGE:
     return r.sym->getGotVA(ctx) + a - getAArch64Page(ctx.in.got->getVA());
   case R_GOT_PC:
-  case R_AARCH64_AUTH_GOT_PC:
+  case RE_AARCH64_AUTH_GOT_PC:
   case R_RELAX_TLS_GD_TO_IE:
     return r.sym->getGotVA(ctx) + a - p;
   case R_GOTPLT_GOTREL:

>From ea684e2eb12f83c257aa25299578ea2ea84c20c7 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Wed, 4 Dec 2024 14:50:52 +0300
Subject: [PATCH 06/10] Change reloc codes in tests (see also #118214)

---
 lld/test/ELF/aarch64-got-relocations-pauth.s | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lld/test/ELF/aarch64-got-relocations-pauth.s b/lld/test/ELF/aarch64-got-relocations-pauth.s
index 5a1d009c3ee282..149d6e71b70216 100644
--- a/lld/test/ELF/aarch64-got-relocations-pauth.s
+++ b/lld/test/ELF/aarch64-got-relocations-pauth.s
@@ -87,8 +87,8 @@ _start:
 # RUN: llvm-readelf -r -S -x .got -s local-tiny | FileCheck %s --check-prefix=LOCAL-TINY
 
 # EXTERNAL-TINY:      Offset            Info             Type                    Symbol's Value   Symbol's Name + Addend
-# EXTERNAL-TINY-NEXT: 0000000000020368  000000010000e201 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 bar + 0
-# EXTERNAL-TINY-NEXT: 0000000000020370  000000020000e201 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 zed + 0
+# EXTERNAL-TINY-NEXT: 0000000000020368  0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 bar + 0
+# EXTERNAL-TINY-NEXT: 0000000000020370  0000000200000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 zed + 0
 
 ## Symbol's values for bar and zed are equal since they contain no content (see Inputs/shared.s)
 # LOCAL-TINY:         Offset            Info             Type                    Symbol's Value   Symbol's Name + Addend

>From ce971584f9038e4adcb27a0f1aa2f4530d2d9ee5 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Wed, 4 Dec 2024 15:02:51 +0300
Subject: [PATCH 07/10] Fix formatting

---
 lld/ELF/Relocations.cpp | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 690b4933bb809e..7ed80b39a75a88 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -975,16 +975,15 @@ bool RelocationScanner::isStaticLinkTimeConstant(RelExpr e, RelType type,
                                                  const Symbol &sym,
                                                  uint64_t relOff) const {
   // These expressions always compute a constant
-  if (oneof<R_GOTPLT, R_GOT_OFF, R_RELAX_HINT, RE_MIPS_GOT_LOCAL_PAGE,
-            RE_MIPS_GOTREL, RE_MIPS_GOT_OFF, RE_MIPS_GOT_OFF32,
-            RE_MIPS_GOT_GP_PC, RE_AARCH64_GOT_PAGE_PC,
-            RE_AARCH64_AUTH_GOT_PAGE_PC, R_GOT_PC, R_GOTONLY_PC,
-            R_GOTPLTONLY_PC, R_PLT_PC, R_PLT_GOTREL, R_PLT_GOTPLT,
-            R_GOTPLT_GOTREL, R_GOTPLT_PC, RE_PPC32_PLTREL, RE_PPC64_CALL_PLT,
-            RE_PPC64_RELAX_TOC, RE_RISCV_ADD, RE_AARCH64_GOT_PAGE,
-            RE_AARCH64_AUTH_GOT, RE_AARCH64_AUTH_GOT_PC,
-            RE_LOONGARCH_PLT_PAGE_PC, RE_LOONGARCH_GOT,
-            RE_LOONGARCH_GOT_PAGE_PC>(e))
+  if (oneof<
+          R_GOTPLT, R_GOT_OFF, R_RELAX_HINT, RE_MIPS_GOT_LOCAL_PAGE,
+          RE_MIPS_GOTREL, RE_MIPS_GOT_OFF, RE_MIPS_GOT_OFF32, RE_MIPS_GOT_GP_PC,
+          RE_AARCH64_GOT_PAGE_PC, RE_AARCH64_AUTH_GOT_PAGE_PC, R_GOT_PC,
+          R_GOTONLY_PC, R_GOTPLTONLY_PC, R_PLT_PC, R_PLT_GOTREL, R_PLT_GOTPLT,
+          R_GOTPLT_GOTREL, R_GOTPLT_PC, RE_PPC32_PLTREL, RE_PPC64_CALL_PLT,
+          RE_PPC64_RELAX_TOC, RE_RISCV_ADD, RE_AARCH64_GOT_PAGE,
+          RE_AARCH64_AUTH_GOT, RE_AARCH64_AUTH_GOT_PC, RE_LOONGARCH_PLT_PAGE_PC,
+          RE_LOONGARCH_GOT, RE_LOONGARCH_GOT_PAGE_PC>(e))
     return true;
 
   // These never do, except if the entire file is position dependent or if

>From 9b7132218d639b5abb3acf429fb621a0e65e457e Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Sun, 8 Dec 2024 16:50:07 +0300
Subject: [PATCH 08/10] Fix typo error

---
 lld/ELF/Relocations.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 7ed80b39a75a88..77b90172bc1c27 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1098,7 +1098,7 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
       // Many LoongArch TLS relocs reuse the RE_LOONGARCH_GOT type, in which
       // case the NEEDS_GOT flag shouldn't get set.
       if (expr == RE_AARCH64_AUTH_GOT || expr == RE_AARCH64_AUTH_GOT_PAGE_PC ||
-          expr == RE_AARCH64_AUTH_GOT_PAGE_PC)
+          expr == RE_AARCH64_AUTH_GOT_PC)
         sym.setFlags(NEEDS_GOT | NEEDS_GOT_AUTH);
       else
         sym.setFlags(NEEDS_GOT | NEEDS_GOT_NONAUTH);

>From ed93c04d88080d2c93d0646243842f5ab6f35320 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Sun, 15 Dec 2024 18:50:50 +0300
Subject: [PATCH 09/10] Do not use terms 'external' and 'local'

---
 lld/test/ELF/aarch64-got-relocations-pauth.s | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lld/test/ELF/aarch64-got-relocations-pauth.s b/lld/test/ELF/aarch64-got-relocations-pauth.s
index 149d6e71b70216..5c573d1edc9d51 100644
--- a/lld/test/ELF/aarch64-got-relocations-pauth.s
+++ b/lld/test/ELF/aarch64-got-relocations-pauth.s
@@ -80,11 +80,11 @@ _start:
 #--- ok-tiny.s
 # RUN: llvm-mc -filetype=obj -triple=aarch64 ok-tiny.s -o ok-tiny.o
 
-# RUN: ld.lld ok-tiny.o a.so -pie -o external-tiny
-# RUN: llvm-readelf -r -S -x .got external-tiny | FileCheck %s --check-prefix=EXTERNAL-TINY
+# RUN: ld.lld ok-tiny.o a.so -pie -o tiny1
+# RUN: llvm-readelf -r -S -x .got tiny1 | FileCheck %s --check-prefix=EXTERNAL-TINY
 
-# RUN: ld.lld ok-tiny.o a.o -pie -o local-tiny
-# RUN: llvm-readelf -r -S -x .got -s local-tiny | FileCheck %s --check-prefix=LOCAL-TINY
+# RUN: ld.lld ok-tiny.o a.o -pie -o tiny2
+# RUN: llvm-readelf -r -S -x .got -s tiny2 | FileCheck %s --check-prefix=LOCAL-TINY
 
 # EXTERNAL-TINY:      Offset            Info             Type                    Symbol's Value   Symbol's Name + Addend
 # EXTERNAL-TINY-NEXT: 0000000000020368  0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 bar + 0
@@ -114,13 +114,13 @@ _start:
 ##                                                                ^^
 ##                                                                0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
 
-# RUN: llvm-objdump -d external-tiny | FileCheck %s --check-prefix=EXTERNAL-TINY-ASM
+# RUN: llvm-objdump -d tiny1 | FileCheck %s --check-prefix=EXTERNAL-TINY-ASM
 
 # EXTERNAL-TINY-ASM:      <_start>:
 # EXTERNAL-TINY-ASM-NEXT: adr x0, 0x20368
 # EXTERNAL-TINY-ASM-NEXT: ldr x1, 0x20370
 
-# RUN: llvm-objdump -d local-tiny | FileCheck %s --check-prefix=LOCAL-TINY-ASM
+# RUN: llvm-objdump -d tiny2 | FileCheck %s --check-prefix=LOCAL-TINY-ASM
 
 # LOCAL-TINY-ASM:         <_start>:
 # LOCAL-TINY-ASM-NEXT:    adr x0, 0x20308

>From 45898edd823d1a4ef7330daab3d9ff98125ae523 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Mon, 16 Dec 2024 10:40:42 +0300
Subject: [PATCH 10/10] Fix check prefixes

---
 lld/test/ELF/aarch64-got-relocations-pauth.s | 48 ++++++++++----------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/lld/test/ELF/aarch64-got-relocations-pauth.s b/lld/test/ELF/aarch64-got-relocations-pauth.s
index 5c573d1edc9d51..1cac08f9dc9238 100644
--- a/lld/test/ELF/aarch64-got-relocations-pauth.s
+++ b/lld/test/ELF/aarch64-got-relocations-pauth.s
@@ -81,50 +81,50 @@ _start:
 # RUN: llvm-mc -filetype=obj -triple=aarch64 ok-tiny.s -o ok-tiny.o
 
 # RUN: ld.lld ok-tiny.o a.so -pie -o tiny1
-# RUN: llvm-readelf -r -S -x .got tiny1 | FileCheck %s --check-prefix=EXTERNAL-TINY
+# RUN: llvm-readelf -r -S -x .got tiny1 | FileCheck %s --check-prefix=TINY1
 
 # RUN: ld.lld ok-tiny.o a.o -pie -o tiny2
-# RUN: llvm-readelf -r -S -x .got -s tiny2 | FileCheck %s --check-prefix=LOCAL-TINY
+# RUN: llvm-readelf -r -S -x .got -s tiny2 | FileCheck %s --check-prefix=TINY2
 
-# EXTERNAL-TINY:      Offset            Info             Type                    Symbol's Value   Symbol's Name + Addend
-# EXTERNAL-TINY-NEXT: 0000000000020368  0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 bar + 0
-# EXTERNAL-TINY-NEXT: 0000000000020370  0000000200000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 zed + 0
+# TINY1:      Offset            Info             Type                    Symbol's Value   Symbol's Name + Addend
+# TINY1-NEXT: 0000000000020368  0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 bar + 0
+# TINY1-NEXT: 0000000000020370  0000000200000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 zed + 0
 
 ## Symbol's values for bar and zed are equal since they contain no content (see Inputs/shared.s)
-# LOCAL-TINY:         Offset            Info             Type                    Symbol's Value   Symbol's Name + Addend
-# LOCAL-TINY-NEXT:    0000000000020308  0000000000000411 R_AARCH64_AUTH_RELATIVE 10248
-# LOCAL-TINY-NEXT:    0000000000020310  0000000000000411 R_AARCH64_AUTH_RELATIVE 10248
+# TINY2:         Offset            Info             Type                    Symbol's Value   Symbol's Name + Addend
+# TINY2-NEXT:    0000000000020308  0000000000000411 R_AARCH64_AUTH_RELATIVE 10248
+# TINY2-NEXT:    0000000000020310  0000000000000411 R_AARCH64_AUTH_RELATIVE 10248
 
-# EXTERNAL-TINY:      Hex dump of section '.got':
-# EXTERNAL-TINY-NEXT: 0x00020368 00000000 00000080 00000000 000000a0
+# TINY1:      Hex dump of section '.got':
+# TINY1-NEXT: 0x00020368 00000000 00000080 00000000 000000a0
 ##                                              ^^
 ##                                              0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
 ##                                                                ^^
 ##                                                                0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
 
-# LOCAL-TINY: Symbol table '.symtab' contains {{.*}} entries:
-# LOCAL-TINY:    Num:    Value          Size Type    Bind   Vis       Ndx Name
-# LOCAL-TINY:         0000000000010248     0 FUNC    GLOBAL DEFAULT     6 bar
-# LOCAL-TINY:         0000000000010248     0 NOTYPE  GLOBAL DEFAULT     6 zed
+# TINY2: Symbol table '.symtab' contains {{.*}} entries:
+# TINY2:    Num:    Value          Size Type    Bind   Vis       Ndx Name
+# TINY2:         0000000000010248     0 FUNC    GLOBAL DEFAULT     6 bar
+# TINY2:         0000000000010248     0 NOTYPE  GLOBAL DEFAULT     6 zed
 
-# LOCAL-TINY:         Hex dump of section '.got':
-# LOCAL-TINY-NEXT:    0x00020308 00000000 00000080 00000000 000000a0
+# TINY2:         Hex dump of section '.got':
+# TINY2-NEXT:    0x00020308 00000000 00000080 00000000 000000a0
 ##                                              ^^
 ##                                              0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
 ##                                                                ^^
 ##                                                                0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
 
-# RUN: llvm-objdump -d tiny1 | FileCheck %s --check-prefix=EXTERNAL-TINY-ASM
+# RUN: llvm-objdump -d tiny1 | FileCheck %s --check-prefix=TINY1-ASM
 
-# EXTERNAL-TINY-ASM:      <_start>:
-# EXTERNAL-TINY-ASM-NEXT: adr x0, 0x20368
-# EXTERNAL-TINY-ASM-NEXT: ldr x1, 0x20370
+# TINY1-ASM:      <_start>:
+# TINY1-ASM-NEXT: adr x0, 0x20368
+# TINY1-ASM-NEXT: ldr x1, 0x20370
 
-# RUN: llvm-objdump -d tiny2 | FileCheck %s --check-prefix=LOCAL-TINY-ASM
+# RUN: llvm-objdump -d tiny2 | FileCheck %s --check-prefix=TINY2-ASM
 
-# LOCAL-TINY-ASM:         <_start>:
-# LOCAL-TINY-ASM-NEXT:    adr x0, 0x20308
-# LOCAL-TINY-ASM-NEXT:    ldr x1, 0x20310
+# TINY2-ASM:         <_start>:
+# TINY2-ASM-NEXT:    adr x0, 0x20308
+# TINY2-ASM-NEXT:    ldr x1, 0x20310
 
 .globl _start
 _start:



More information about the llvm-branch-commits mailing list