[lld] 1ef5b98 - [PAC][lld][AArch64][ELF] Support signed GOT with tiny code model (#113816)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 17 22:41:58 PST 2024
Author: Daniil Kovalev
Date: 2024-12-18T09:41:54+03:00
New Revision: 1ef5b987a464611a60e873650726b5e02fda0feb
URL: https://github.com/llvm/llvm-project/commit/1ef5b987a464611a60e873650726b5e02fda0feb
DIFF: https://github.com/llvm/llvm-project/commit/1ef5b987a464611a60e873650726b5e02fda0feb.diff
LOG: [PAC][lld][AArch64][ELF] Support signed GOT with tiny code model (#113816)
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`.
Added:
Modified:
lld/ELF/Arch/AArch64.cpp
lld/ELF/InputSection.cpp
lld/ELF/Relocations.cpp
lld/ELF/Relocations.h
lld/test/ELF/aarch64-got-relocations-pauth.s
Removed:
################################################################################
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..efa7ba3e7cb063 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 RE_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..77b90172bc1c27 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);
@@ -974,15 +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_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
@@ -1096,7 +1097,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_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 4456fe3ad7714b..2d37123f1cca79 100644
--- a/lld/test/ELF/aarch64-got-relocations-pauth.s
+++ b/lld/test/ELF/aarch64-got-relocations-pauth.s
@@ -77,6 +77,60 @@ _start:
adrp x1, :got_auth:zed
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 tiny1
+# 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=TINY2
+
+# 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)
+# 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
+
+# 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
+
+# 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
+
+# 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=TINY1-ASM
+
+# TINY1-ASM: <_start>:
+# TINY1-ASM-NEXT: adr x0, 0x20368
+# TINY1-ASM-NEXT: ldr x1, 0x20370
+
+# RUN: llvm-objdump -d tiny2 | FileCheck %s --check-prefix=TINY2-ASM
+
+# TINY2-ASM: <_start>:
+# TINY2-ASM-NEXT: adr x0, 0x20308
+# TINY2-ASM-NEXT: ldr x1, 0x20310
+
+.globl _start
+_start:
+ adr x0, :got_auth:bar
+ 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 2>&1 | FileCheck %s --check-prefix=ERR --implicit-check-not=error:
More information about the llvm-commits
mailing list