Skip to content

Commit ad29822

Browse files
committed
[BOLT][AArch64] Add R_*_LD64_GOT*_LO15 rel support
Add R_AARCH64_LD64_GOT*_LO15 to the list of supported relocations. But due to the fact that JITlink doesn't create GOT section when used with BOLT and there is no common VK_LO15 relocation for aarch64 don't record this relocation to further process. Since BOLT doesn't move GOT table it's OK that instruction would have preserved imm value and not expression. But this level of support is needed during relocations processing e.g. to abort on out-of-section GOT symbols (llvm#100801).
1 parent 445023f commit ad29822

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

bolt/lib/Core/Relocation.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ static bool isSupportedAArch64(uint64_t Type) {
7575
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
7676
case ELF::R_AARCH64_TLSLE_ADD_TPREL_HI12:
7777
case ELF::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
78+
case ELF::R_AARCH64_LD64_GOTPAGE_LO15:
79+
case ELF::R_AARCH64_LD64_GOTOFF_LO15:
7880
case ELF::R_AARCH64_LD64_GOT_LO12_NC:
7981
case ELF::R_AARCH64_TLSDESC_LD64_LO12:
8082
case ELF::R_AARCH64_TLSDESC_ADD_LO12:
@@ -183,6 +185,8 @@ static size_t getSizeForTypeAArch64(uint64_t Type) {
183185
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
184186
case ELF::R_AARCH64_TLSLE_ADD_TPREL_HI12:
185187
case ELF::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
188+
case ELF::R_AARCH64_LD64_GOTPAGE_LO15:
189+
case ELF::R_AARCH64_LD64_GOTOFF_LO15:
186190
case ELF::R_AARCH64_LD64_GOT_LO12_NC:
187191
case ELF::R_AARCH64_TLSDESC_LD64_LO12:
188192
case ELF::R_AARCH64_TLSDESC_ADD_LO12:
@@ -464,6 +468,8 @@ static uint64_t extractValueAArch64(uint64_t Type, uint64_t Contents,
464468
return Contents;
465469
}
466470
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
471+
case ELF::R_AARCH64_LD64_GOTPAGE_LO15:
472+
case ELF::R_AARCH64_LD64_GOTOFF_LO15:
467473
case ELF::R_AARCH64_TLSDESC_LD64_LO12:
468474
case ELF::R_AARCH64_LD64_GOT_LO12_NC:
469475
case ELF::R_AARCH64_LDST64_ABS_LO12_NC: {
@@ -609,6 +615,8 @@ static bool isGOTAArch64(uint64_t Type) {
609615
default:
610616
return false;
611617
case ELF::R_AARCH64_ADR_GOT_PAGE:
618+
case ELF::R_AARCH64_LD64_GOTPAGE_LO15:
619+
case ELF::R_AARCH64_LD64_GOTOFF_LO15:
612620
case ELF::R_AARCH64_LD64_GOT_LO12_NC:
613621
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
614622
case ELF::R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
@@ -716,6 +724,8 @@ static bool isPCRelativeAArch64(uint64_t Type) {
716724
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
717725
case ELF::R_AARCH64_TLSLE_ADD_TPREL_HI12:
718726
case ELF::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
727+
case ELF::R_AARCH64_LD64_GOTPAGE_LO15:
728+
case ELF::R_AARCH64_LD64_GOTOFF_LO15:
719729
case ELF::R_AARCH64_LD64_GOT_LO12_NC:
720730
case ELF::R_AARCH64_TLSDESC_LD64_LO12:
721731
case ELF::R_AARCH64_TLSDESC_ADD_LO12:

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,8 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
14031403
case ELF::R_AARCH64_TLSDESC_CALL:
14041404
case ELF::R_AARCH64_TLSLE_ADD_TPREL_HI12:
14051405
case ELF::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
1406+
case ELF::R_AARCH64_LD64_GOTPAGE_LO15:
1407+
case ELF::R_AARCH64_LD64_GOTOFF_LO15:
14061408
return false;
14071409
default:
14081410
llvm_unreachable("Unexpected AArch64 relocation type in code");

bolt/test/AArch64/got_rels.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// This test checks that got-related relocations are properly handled by BOLT.
2+
3+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown \
4+
# RUN: %s -o %t.o
5+
# RUN: %clang %cflags -fPIC -pie %t.o -o %t.exe -Wl,-q
6+
# RUN: llvm-bolt %t.exe -o %t.bolt --print-disasm --print-only=_start | \
7+
# RUN: FileCheck %s
8+
9+
# CHECK: adrp x1, __BOLT_got_zero{{.*}}
10+
# CHECK-NEXT: ldr x1, [x1, :lo12:__BOLT_got_zero+{{.*}}]
11+
# CHECK-NEXT: adrp x1, "_GLOBAL_OFFSET_TABLE_/1"
12+
# CHECK-NEXT: ldr x1, [x1, #0x{{[[:xdigit:]]+}}]
13+
14+
.text
15+
.balign 4
16+
.global _start
17+
.type _start, %function
18+
_start:
19+
adrp x1, #:got:symbol
20+
ldr x1, [x1, #:got_lo12:symbol]
21+
adrp x1, _GLOBAL_OFFSET_TABLE_
22+
ldr x1, [x1, #:gotpage_lo15:symbol]
23+
.size _start, .-_start

0 commit comments

Comments
 (0)