Skip to content

Commit 4ca86d2

Browse files
committedDec 17, 2018
ELF: AArch64: Fix errata patch address calculation.
The code here wants the output section offset of the instruction requiring the errata patch, not the virtual address. Without this change we can end up placing a patch out of range if the virtual address of the code section is large enough. Differential Revision: https://reviews.llvm.org/D55732 llvm-svn: 349386
1 parent 728cbc0 commit 4ca86d2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
 

‎lld/ELF/AArch64ErrataFix.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ void AArch64Err843419Patcher::insertPatches(
488488
uint64_t ISLimit;
489489
uint64_t PrevISLimit = ISD.Sections.front()->OutSecOff;
490490
uint64_t PatchUpperBound = PrevISLimit + Target->getThunkSectionSpacing();
491+
uint64_t OutSecAddr = ISD.Sections.front()->getParent()->Addr;
491492

492493
// Set the OutSecOff of patches to the place where we want to insert them.
493494
// We use a similar strategy to Thunk placement. Place patches roughly
@@ -498,7 +499,7 @@ void AArch64Err843419Patcher::insertPatches(
498499
ISLimit = IS->OutSecOff + IS->getSize();
499500
if (ISLimit > PatchUpperBound) {
500501
while (PatchIt != PatchEnd) {
501-
if ((*PatchIt)->getLDSTAddr() >= PrevISLimit)
502+
if ((*PatchIt)->getLDSTAddr() - OutSecAddr >= PrevISLimit)
502503
break;
503504
(*PatchIt)->OutSecOff = PrevISLimit;
504505
++PatchIt;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// REQUIRES: aarch64
2+
// RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux %s -o %t.o
3+
// RUN: ld.lld --fix-cortex-a53-843419 -Ttext=0x8000000 %t.o -o %t2
4+
// RUN: llvm-objdump -d --start-address=0x8001000 --stop-address=0x8001004 %t2 | FileCheck %s
5+
6+
.section .text.01, "ax", %progbits
7+
.balign 4096
8+
.space 4096 - 8
9+
adrp x0, thunk
10+
ldr x1, [x1, #0]
11+
// CHECK: thunk:
12+
// CHECK-NEXT: b #67108872 <__CortexA53843419_8001000>
13+
thunk:
14+
ldr x0, [x0, :got_lo12:thunk]
15+
ret
16+
.space 64 * 1024 * 1024
17+
18+
.section .text.02, "ax", %progbits
19+
.space 64 * 1024 * 1024

0 commit comments

Comments
 (0)
Please sign in to comment.