Skip to content

[PAC][lld][AArch64][ELF] Support signed GOT with tiny code model #113816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 18, 2024

Conversation

kovdan01
Copy link
Contributor

@kovdan01 kovdan01 commented Oct 27, 2024

Depends on #114525

Support R_AARCH64_AUTH_GOT_ADR_PREL_LO21 and R_AARCH64_AUTH_GOT_LD_PREL19
GOT-generating relocations. A corresponding RE_AARCH64_AUTH_GOT_PC member
of RelExpr is added, which is an AUTH-specific variant of R_GOT_PC.

Copy link
Contributor Author

kovdan01 commented Oct 27, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

@kovdan01 kovdan01 self-assigned this Oct 27, 2024
@kovdan01 kovdan01 linked an issue Oct 27, 2024 that may be closed by this pull request
@kovdan01 kovdan01 marked this pull request as ready for review October 28, 2024 17:46
@llvmbot
Copy link
Member

llvmbot commented Oct 28, 2024

@llvm/pr-subscribers-lld-elf

Author: Daniil Kovalev (kovdan01)

Changes

Depends on #113812

Support R_AARCH64_AUTH_GOT_ADR_PREL_LO21 and R_AARCH64_AUTH_GOT_LD_PREL19
GOT-generating relocations.


Full diff: https://github.com/llvm/llvm-project/pull/113816.diff

5 Files Affected:

  • (modified) lld/ELF/Arch/AArch64.cpp (+5)
  • (modified) lld/ELF/InputSection.cpp (+1)
  • (modified) lld/ELF/Relocations.cpp (+9-8)
  • (modified) lld/ELF/Relocations.h (+1)
  • (modified) lld/test/ELF/aarch64-got-relocations-pauth.s (+73)
diff --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp
index 86f509f3fd78a7..2f2e0c2a52b0ef 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 R_AARCH64_AUTH_GOT;
+  case R_AARCH64_AUTH_GOT_LD_PREL19:
+  case R_AARCH64_AUTH_GOT_ADR_PREL_LO21:
+    return R_AARCH64_AUTH_GOT_PC;
   case R_AARCH64_LD64_GOTPAGE_LO15:
     return R_AARCH64_GOT_PAGE;
   case R_AARCH64_ADR_GOT_PAGE:
@@ -549,6 +552,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;
@@ -569,6 +573,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 ccc7cf8c6e2de9..ba135afd3580bf 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -788,6 +788,7 @@ uint64_t InputSectionBase::getRelocTargetVA(Ctx &ctx, const Relocation &r,
   case R_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 2d3815e58b5f67..324a97d7a55f41 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -210,11 +210,11 @@ static bool needsPlt(RelExpr expr) {
 }
 
 bool lld::elf::needsGot(RelExpr expr) {
-  return oneof<R_GOT, R_AARCH64_AUTH_GOT, R_GOT_OFF, R_MIPS_GOT_LOCAL_PAGE,
-               R_MIPS_GOT_OFF, R_MIPS_GOT_OFF32, R_AARCH64_GOT_PAGE_PC,
-               R_AARCH64_AUTH_GOT_PAGE_PC, R_GOT_PC, R_GOTPLT,
-               R_AARCH64_GOT_PAGE, R_LOONGARCH_GOT, R_LOONGARCH_GOT_PAGE_PC>(
-      expr);
+  return oneof<R_GOT, R_AARCH64_AUTH_GOT, R_AARCH64_AUTH_GOT_PC, R_GOT_OFF,
+               R_MIPS_GOT_LOCAL_PAGE, R_MIPS_GOT_OFF, R_MIPS_GOT_OFF32,
+               R_AARCH64_GOT_PAGE_PC, R_AARCH64_AUTH_GOT_PAGE_PC, R_GOT_PC,
+               R_GOTPLT, R_AARCH64_GOT_PAGE, R_LOONGARCH_GOT,
+               R_LOONGARCH_GOT_PAGE_PC>(expr);
 }
 
 // True if this expression is of the form Sym - X, where X is a position in the
@@ -1011,8 +1011,8 @@ bool RelocationScanner::isStaticLinkTimeConstant(RelExpr e, RelType type,
             R_GOTONLY_PC, R_GOTPLTONLY_PC, R_PLT_PC, R_PLT_GOTREL, R_PLT_GOTPLT,
             R_GOTPLT_GOTREL, R_GOTPLT_PC, R_PPC32_PLTREL, R_PPC64_CALL_PLT,
             R_PPC64_RELAX_TOC, R_RISCV_ADD, R_AARCH64_GOT_PAGE,
-            R_AARCH64_AUTH_GOT, R_LOONGARCH_PLT_PAGE_PC, R_LOONGARCH_GOT,
-            R_LOONGARCH_GOT_PAGE_PC>(e))
+            R_AARCH64_AUTH_GOT, R_AARCH64_AUTH_GOT_PC, R_LOONGARCH_PLT_PAGE_PC,
+            R_LOONGARCH_GOT, R_LOONGARCH_GOT_PAGE_PC>(e))
     return true;
 
   // These never do, except if the entire file is position dependent or if
@@ -1126,7 +1126,8 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
       // Many LoongArch TLS relocs reuse the R_LOONGARCH_GOT type, in which
       // case the NEEDS_GOT flag shouldn't get set.
       bool needsGotAuth =
-          (expr == R_AARCH64_AUTH_GOT || expr == R_AARCH64_AUTH_GOT_PAGE_PC);
+          (expr == R_AARCH64_AUTH_GOT || expr == R_AARCH64_AUTH_GOT_PC ||
+           expr == R_AARCH64_AUTH_GOT_PAGE_PC);
       uint16_t flags = sym.flags.load(std::memory_order_relaxed);
       if (!(flags & NEEDS_GOT)) {
         if (needsGotAuth)
diff --git a/lld/ELF/Relocations.h b/lld/ELF/Relocations.h
index 20d88de402ac18..38d55d46116569 100644
--- a/lld/ELF/Relocations.h
+++ b/lld/ELF/Relocations.h
@@ -89,6 +89,7 @@ enum RelExpr {
   R_AARCH64_AUTH_GOT_PAGE_PC,
   R_AARCH64_GOT_PAGE,
   R_AARCH64_AUTH_GOT,
+  R_AARCH64_AUTH_GOT_PC,
   R_AARCH64_PAGE_PC,
   R_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC,
   R_AARCH64_TLSDESC_PAGE,
diff --git a/lld/test/ELF/aarch64-got-relocations-pauth.s b/lld/test/ELF/aarch64-got-relocations-pauth.s
index f04e3d953388ce..c43f1ca251a9a8 100644
--- a/lld/test/ELF/aarch64-got-relocations-pauth.s
+++ b/lld/test/ELF/aarch64-got-relocations-pauth.s
@@ -78,6 +78,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-none-linux err.s -o err.o

@llvmbot
Copy link
Member

llvmbot commented Oct 28, 2024

@llvm/pr-subscribers-lld

Author: Daniil Kovalev (kovdan01)

Changes

Depends on #113812

Support R_AARCH64_AUTH_GOT_ADR_PREL_LO21 and R_AARCH64_AUTH_GOT_LD_PREL19
GOT-generating relocations.


Full diff: https://github.com/llvm/llvm-project/pull/113816.diff

5 Files Affected:

  • (modified) lld/ELF/Arch/AArch64.cpp (+5)
  • (modified) lld/ELF/InputSection.cpp (+1)
  • (modified) lld/ELF/Relocations.cpp (+9-8)
  • (modified) lld/ELF/Relocations.h (+1)
  • (modified) lld/test/ELF/aarch64-got-relocations-pauth.s (+73)
diff --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp
index 86f509f3fd78a7..2f2e0c2a52b0ef 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 R_AARCH64_AUTH_GOT;
+  case R_AARCH64_AUTH_GOT_LD_PREL19:
+  case R_AARCH64_AUTH_GOT_ADR_PREL_LO21:
+    return R_AARCH64_AUTH_GOT_PC;
   case R_AARCH64_LD64_GOTPAGE_LO15:
     return R_AARCH64_GOT_PAGE;
   case R_AARCH64_ADR_GOT_PAGE:
@@ -549,6 +552,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;
@@ -569,6 +573,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 ccc7cf8c6e2de9..ba135afd3580bf 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -788,6 +788,7 @@ uint64_t InputSectionBase::getRelocTargetVA(Ctx &ctx, const Relocation &r,
   case R_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 2d3815e58b5f67..324a97d7a55f41 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -210,11 +210,11 @@ static bool needsPlt(RelExpr expr) {
 }
 
 bool lld::elf::needsGot(RelExpr expr) {
-  return oneof<R_GOT, R_AARCH64_AUTH_GOT, R_GOT_OFF, R_MIPS_GOT_LOCAL_PAGE,
-               R_MIPS_GOT_OFF, R_MIPS_GOT_OFF32, R_AARCH64_GOT_PAGE_PC,
-               R_AARCH64_AUTH_GOT_PAGE_PC, R_GOT_PC, R_GOTPLT,
-               R_AARCH64_GOT_PAGE, R_LOONGARCH_GOT, R_LOONGARCH_GOT_PAGE_PC>(
-      expr);
+  return oneof<R_GOT, R_AARCH64_AUTH_GOT, R_AARCH64_AUTH_GOT_PC, R_GOT_OFF,
+               R_MIPS_GOT_LOCAL_PAGE, R_MIPS_GOT_OFF, R_MIPS_GOT_OFF32,
+               R_AARCH64_GOT_PAGE_PC, R_AARCH64_AUTH_GOT_PAGE_PC, R_GOT_PC,
+               R_GOTPLT, R_AARCH64_GOT_PAGE, R_LOONGARCH_GOT,
+               R_LOONGARCH_GOT_PAGE_PC>(expr);
 }
 
 // True if this expression is of the form Sym - X, where X is a position in the
@@ -1011,8 +1011,8 @@ bool RelocationScanner::isStaticLinkTimeConstant(RelExpr e, RelType type,
             R_GOTONLY_PC, R_GOTPLTONLY_PC, R_PLT_PC, R_PLT_GOTREL, R_PLT_GOTPLT,
             R_GOTPLT_GOTREL, R_GOTPLT_PC, R_PPC32_PLTREL, R_PPC64_CALL_PLT,
             R_PPC64_RELAX_TOC, R_RISCV_ADD, R_AARCH64_GOT_PAGE,
-            R_AARCH64_AUTH_GOT, R_LOONGARCH_PLT_PAGE_PC, R_LOONGARCH_GOT,
-            R_LOONGARCH_GOT_PAGE_PC>(e))
+            R_AARCH64_AUTH_GOT, R_AARCH64_AUTH_GOT_PC, R_LOONGARCH_PLT_PAGE_PC,
+            R_LOONGARCH_GOT, R_LOONGARCH_GOT_PAGE_PC>(e))
     return true;
 
   // These never do, except if the entire file is position dependent or if
@@ -1126,7 +1126,8 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
       // Many LoongArch TLS relocs reuse the R_LOONGARCH_GOT type, in which
       // case the NEEDS_GOT flag shouldn't get set.
       bool needsGotAuth =
-          (expr == R_AARCH64_AUTH_GOT || expr == R_AARCH64_AUTH_GOT_PAGE_PC);
+          (expr == R_AARCH64_AUTH_GOT || expr == R_AARCH64_AUTH_GOT_PC ||
+           expr == R_AARCH64_AUTH_GOT_PAGE_PC);
       uint16_t flags = sym.flags.load(std::memory_order_relaxed);
       if (!(flags & NEEDS_GOT)) {
         if (needsGotAuth)
diff --git a/lld/ELF/Relocations.h b/lld/ELF/Relocations.h
index 20d88de402ac18..38d55d46116569 100644
--- a/lld/ELF/Relocations.h
+++ b/lld/ELF/Relocations.h
@@ -89,6 +89,7 @@ enum RelExpr {
   R_AARCH64_AUTH_GOT_PAGE_PC,
   R_AARCH64_GOT_PAGE,
   R_AARCH64_AUTH_GOT,
+  R_AARCH64_AUTH_GOT_PC,
   R_AARCH64_PAGE_PC,
   R_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC,
   R_AARCH64_TLSDESC_PAGE,
diff --git a/lld/test/ELF/aarch64-got-relocations-pauth.s b/lld/test/ELF/aarch64-got-relocations-pauth.s
index f04e3d953388ce..c43f1ca251a9a8 100644
--- a/lld/test/ELF/aarch64-got-relocations-pauth.s
+++ b/lld/test/ELF/aarch64-got-relocations-pauth.s
@@ -78,6 +78,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-none-linux err.s -o err.o

Comment on lines 102 to 105
# ^^
# 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
# ^^
# 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume these are intentionally not matched. In that case, is there a good reason to keep them in the test?

Copy link
Contributor Author

@kovdan01 kovdan01 Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not output to be checked and matched but comments helping to understand the contents of hex dump. I've changed the prefix to ## so it's clear that it's a comment and not a special line like RUN/CHECK/etc. See e841e19. Applied the same to #113815

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A thanks for the explanation. I think I made a similar comment in one of the other PRs before I saw this. Feel free to ignore that/mark it resolved.

@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-lld branch from 0d23449 to 38d5936 Compare November 1, 2024 10:33
@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-tiny-lld branch from 71a9746 to e841e19 Compare November 1, 2024 10:37
Copy link
Contributor

@ilovepi ilovepi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, LGTM, but lets get another maintainer to take a look before landing.

@ilovepi
Copy link
Contributor

ilovepi commented Nov 1, 2024

Again, LGTM, but lets get another maintainer to take a look before landing.

well, assuming presubmit is working. I see a number of test failures, ATM.

@kovdan01
Copy link
Contributor Author

kovdan01 commented Nov 9, 2024

I see a number of test failures, ATM.

@ilovepi Yes, these are currently expected - as mentioned in the PR description, it depends on #114525 (codegen support for the feature). The dependency isn't included in the Graphite PR stack since this does not cause merge conflicts (different parts of llvm are altered) - I find it easier to keep PRs separate if it's possible and just mention unmerged dependencies in description (for me, it makes updating PRs more robust).

@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-lld branch from 38d5936 to 42ca2d9 Compare November 10, 2024 17:43
@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-tiny-lld branch from e841e19 to 69bc310 Compare November 10, 2024 19:04
@@ -78,6 +78,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none is also an OS component and is misleading when used together with linux.

Just use aarch64 (or aarch64-linux when it's important to mention Linux, usually it's not)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for suggestion, changed to aarch64 in 3c80d75. Also applied to #113815

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but the description should mention why R_AARCH64_AUTH_GOT_PC is added and the existing RelExpr member that is similar to it.


.globl _start
_start:
adr x0, :got_auth:bar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for so many instructions.

We want very few instructions that look like simplified real-world codegen. While it's important to test two symbols to add some nuance, we can simplify the code here. Perhaps we just need

adr x0, :got_auth:bar
ldr x1, :got_auth:zed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for suggestion, removed excessive instructions in 3c80d75

@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-lld branch from 1621897 to bf7d8a9 Compare November 18, 2024 05:33
@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-tiny-lld branch from 82a5205 to ecc8b14 Compare December 1, 2024 22:28
@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-lld branch from b277e3b to b8a4abd Compare December 4, 2024 11:57
@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-tiny-lld branch from ecc8b14 to 1de7b3e Compare December 4, 2024 11:57
Copy link

github-actions bot commented Dec 4, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-lld branch from b8a4abd to e1f8260 Compare December 4, 2024 20:04
@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-tiny-lld branch 2 times, most recently from 0c161da to 758fac9 Compare December 4, 2024 20:09
@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-lld branch from d7336f6 to 6f44978 Compare December 8, 2024 14:07
@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-tiny-lld branch from 758fac9 to e7443e9 Compare December 8, 2024 14:07
# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might just use tiny1 tiny2 instead of local-tiny external-tiny, since we may test both preemptible and non-preemptible symbols. local/external isn't accurate linker term anyway (local may mean the local binding)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for suggestion, fixed in 7d94945, and also applied the same to #113815

@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-lld branch from 6f44978 to 8dba1cd Compare December 15, 2024 15:53
@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-tiny-lld branch from e7443e9 to 7d94945 Compare December 15, 2024 15:54
@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-lld branch from 8dba1cd to 03f9115 Compare December 16, 2024 07:42
@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-tiny-lld branch 2 times, most recently from 45898ed to a0c30ce Compare December 16, 2024 18:07
Base automatically changed from users/kovdan01/pauth-signed-got-lld to main December 17, 2024 07:23
@kovdan01 kovdan01 force-pushed the users/kovdan01/pauth-signed-got-tiny-lld branch from a0c30ce to bc3a2e4 Compare December 17, 2024 08:00
Copy link
Contributor Author

kovdan01 commented Dec 18, 2024

Merge activity

  • Dec 18, 1:40 AM EST: A user started a stack merge that includes this pull request via Graphite.
  • Dec 18, 1:41 AM EST: A user merged this pull request with Graphite.

@kovdan01 kovdan01 merged commit 1ef5b98 into main Dec 18, 2024
7 of 8 checks passed
@kovdan01 kovdan01 deleted the users/kovdan01/pauth-signed-got-tiny-lld branch December 18, 2024 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[PAC][ELF][lld] Support signed GOT
4 participants