[llvm][lld] Support R_AARCH64_GOTPCREL32 (#72584)
This is the follopw implementation to
https://github.com/ARM-software/abi-aa/pull/223 that supports this
relocation in llvm and lld.
GitOrigin-RevId: 04a906ec980e7bf49ffda0808766f51d08e8ae76
diff --git a/ELF/Arch/AArch64.cpp b/ELF/Arch/AArch64.cpp
index 54b0a84..71a1b11 100644
--- a/ELF/Arch/AArch64.cpp
+++ b/ELF/Arch/AArch64.cpp
@@ -165,6 +165,8 @@
case R_AARCH64_ADR_GOT_PAGE:
case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
return R_AARCH64_GOT_PAGE_PC;
+ case R_AARCH64_GOTPCREL32:
+ return R_GOT_PC;
case R_AARCH64_NONE:
return R_NONE;
default:
@@ -374,6 +376,7 @@
write32(loc, val);
break;
case R_AARCH64_PLT32:
+ case R_AARCH64_GOTPCREL32:
checkInt(loc, val, 32, rel);
write32(loc, val);
break;
diff --git a/test/ELF/aarch64-reloc-gotpcrel32.s b/test/ELF/aarch64-reloc-gotpcrel32.s
new file mode 100644
index 0000000..4d00777
--- /dev/null
+++ b/test/ELF/aarch64-reloc-gotpcrel32.s
@@ -0,0 +1,27 @@
+// REQUIRES: aarch64
+// RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
+// RUN: ld.lld %t.o -o %t.so -shared --noinhibit-exec 2>&1 | FileCheck %s --check-prefix=WARN
+// RUN: llvm-readelf -S %t.so | FileCheck --check-prefix=SEC %s
+// RUN: llvm-objdump --no-print-imm-hex -s -d %t.so | FileCheck %s
+
+// SEC: .got PROGBITS 0000000000020390
+
+ .section .data
+ .globl bar
+bar:
+
+ .globl _start
+_start: // PC = 0x303a0
+// bar@GOTPCREL = 0x20390 (got entry for `bar`) - 0x303a0 (.) = 0xf0fffeff
+// bar@GOTPCREL+4 = 0x20390 (got entry for `bar`) - 0x303a4 (.) + 4 = 0xf0fffeff
+// bar@GOTPCREL-4 = 0x20390 (got entry for `bar`) - 0x303a8 (.) - 4 = 0xe4fffeff
+// CHECK: Contents of section .data:
+// CHECK-NEXT: {{.*}} f0fffeff f0fffeff e4fffeff
+ .word bar@GOTPCREL
+ .word bar@GOTPCREL+4
+ .word bar@GOTPCREL-4
+
+// WARN: relocation R_AARCH64_GOTPCREL32 out of range: {{.*}} is not in [-2147483648, 2147483647]; references 'baz'
+// WARN: relocation R_AARCH64_GOTPCREL32 out of range: {{.*}} is not in [-2147483648, 2147483647]; references 'baz'
+ .word baz@GOTPCREL+0xffffffff
+ .word baz@GOTPCREL-0xffffffff