Skip to content

Commit e837461

Browse files
committedJan 16, 2019
[ELF][AArch64] Add R_AARCH64_PLT_PAGE_PC to isRelExpr
As a follow on to D56666 (r351186) there is a case when taking the address of an ifunc when linking -pie that can generate a spurious can't create dynamic relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol in readonly segment. Specifically the case is where the ifunc is in the same translation unit as the address taker, so given -fpie the compiler knows the ifunc is defined in the executable so it can use a non-got-generating relocation. The error message is due to R_AARCH64_PLT_PAGE_PC not being added to isRelExpr, its non PLT equivalent R_AARCH64_PAGE_PC is already in isRelExpr. Differential Revision: https://reviews.llvm.org/D56724 llvm-svn: 351335
1 parent e56d65a commit e837461

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed
 

‎lld/ELF/Relocations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static bool needsGot(RelExpr Expr) {
356356
static bool isRelExpr(RelExpr Expr) {
357357
return isRelExprOneOf<R_PC, R_GOTREL, R_GOTREL_FROM_END, R_MIPS_GOTREL,
358358
R_PPC_CALL, R_PPC_CALL_PLT, R_AARCH64_PAGE_PC,
359-
R_RELAX_GOT_PC>(Expr);
359+
R_AARCH64_PLT_PAGE_PC, R_RELAX_GOT_PC>(Expr);
360360
}
361361

362362
// Returns true if a given relocation can be computed at link-time.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# REQUIRES: aarch64
2+
# RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-gnu %s -o %t.o
3+
# RUN: ld.lld -pie %t.o -o %tout
4+
# RUN: llvm-objdump -D %tout | FileCheck %s
5+
# RUN: llvm-readobj -r %tout | FileCheck %s -check-prefix=CHECK-RELOCS
6+
7+
# Test that when we take the address of a preemptible ifunc using -fpie, we can
8+
# handle the case when the ifunc is in the same translation unit as the address
9+
# taker. In this case the compiler knows that ifunc is not defined in a shared
10+
# library so it can use a non got generating relative reference.
11+
.text
12+
.globl myfunc
13+
.type myfunc,@gnu_indirect_function
14+
myfunc:
15+
ret
16+
17+
.text
18+
.globl main
19+
.type main,@function
20+
main:
21+
adrp x8, myfunc
22+
add x8, x8, :lo12: myfunc
23+
ret
24+
25+
# CHECK: 0000000000010000 myfunc:
26+
# CHECK-NEXT: 10000: c0 03 5f d6 ret
27+
# CHECK: 0000000000010004 main:
28+
# CHECK-NEXT: 10004: 08 00 00 90 adrp x8, #0
29+
# x8 = 0x10000
30+
# CHECK-NEXT: 10008: 08 41 00 91 add x8, x8, #16
31+
# x8 = 0x10010 = .plt for myfunc
32+
# CHECK-NEXT: 1000c: c0 03 5f d6 ret
33+
# CHECK-NEXT: Disassembly of section .plt:
34+
# CHECK-NEXT: 0000000000010010 .plt:
35+
# CHECK-NEXT: 10010: 90 00 00 90 adrp x16, #65536
36+
# CHECK-NEXT: 10014: 11 02 40 f9 ldr x17, [x16]
37+
# CHECK-NEXT: 10018: 10 02 00 91 add x16, x16, #0
38+
# CHECK-NEXT: 1001c: 20 02 1f d6 br x17
39+
40+
# CHECK-RELOCS: Relocations [
41+
# CHECK-RELOCS-NEXT: Section {{.*}} .rela.plt {
42+
# CHECK-RELOCS-NEXT: 0x20000 R_AARCH64_IRELATIVE - 0x10000
43+
# CHECK-RELOCS-NEXT: }
44+
# CHECK-RELOCS-NEXT: ]

0 commit comments

Comments
 (0)
Please sign in to comment.