Skip to content

Commit 4ebe62d

Browse files
committed
Merging r359094:
------------------------------------------------------------------------ r359094 | maskray | 2019-04-24 07:03:30 -0700 (Wed, 24 Apr 2019) | 12 lines [PPC64] Consider localentry offset when computing branch distance Summary: We don't take localentry offset into account, and thus may fail to create a long branch when the gap is just a few bytes smaller than 2^25. relocation R_PPC64_REL24 out of range: 33554432 is not in [-33554432, 33554431] relocation R_PPC64_REL24 out of range: 33554436 is not in [-33554432, 33554431] Fix that by adding the offset to the symbol VA. Differential Revision: https://reviews.llvm.org/D61058 ------------------------------------------------------------------------ llvm-svn: 364209
1 parent c2be208 commit 4ebe62d

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lld/ELF/Arch/PPC64.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,10 @@ bool PPC64::needsThunk(RelExpr Expr, RelType Type, const InputFile *File,
757757

758758
// If the offset exceeds the range of the branch type then it will need
759759
// a range-extending thunk.
760-
return !inBranchRange(Type, BranchAddr, S.getVA());
760+
// See the comment in getRelocTargetVA() about R_PPC64_CALL.
761+
return !inBranchRange(Type, BranchAddr,
762+
S.getVA() +
763+
getPPC64GlobalEntryToLocalEntryOffset(S.StOther));
761764
}
762765

763766
uint32_t PPC64::getThunkSectionSpacing() const {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# REQUIRES: ppc
2+
3+
# RUN: llvm-mc -filetype=obj -triple=ppc64le %s -o %t.o
4+
# RUN: ld.lld %t.o -o %t
5+
# RUN: llvm-nm %t | FileCheck %s
6+
7+
# CHECK-DAG: 0000000010010000 t __long_branch_callee
8+
# CHECK-DAG: 0000000010010010 T _start
9+
# CHECK-DAG: 0000000012010008 T callee
10+
11+
# The bl instruction jumps to the local entry. The distance requires a long branch stub:
12+
# localentry(callee) - _start = 0x12010008+8 - 0x10010010 = 0x2000000
13+
14+
# We used to compute globalentry(callee) - _start and caused a "R_PPC64_REL24
15+
# out of range" error because we didn't create the stub.
16+
17+
.globl _start
18+
_start:
19+
bl callee
20+
21+
.space 0x1fffff4
22+
23+
.globl callee
24+
callee:
25+
.Lgep0:
26+
addis 2, 12, .TOC.-.Lgep0@ha
27+
addi 2, 2, .TOC.-.Lgep0@l
28+
.Llep0:
29+
.localentry callee, .Llep0-.Lgep0
30+
blr

0 commit comments

Comments
 (0)