Skip to content

Commit 247b2ce

Browse files
committed
[LLD][ELF][AArch64][ARM] Add missing classof to patch sections.
The code to insert patch section merges them with a comparison function that uses logic of the form: return (isa<PatchSection>(a) && !isa<PatchSection>(b)); If the PatchSections don't implement classof this check fails if b is also a SyntheticSection. This can result in the patches being out of range if the SyntheticSection is big, for example a ThunkSection with lots of thunks. Differential Revision: https://reviews.llvm.org/D71242 fixes (part of) pr44071
1 parent c7738cc commit 247b2ce

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

lld/ELF/AArch64ErrataFix.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ class Patch843419Section : public SyntheticSection {
381381

382382
uint64_t getLDSTAddr() const;
383383

384+
static bool classof(const SectionBase *d) {
385+
return d->kind() == InputSectionBase::Synthetic && d->name == ".text.patch";
386+
}
387+
384388
// The Section we are patching.
385389
const InputSection *patchee;
386390
// The offset of the instruction in the patchee section we are patching.

lld/ELF/ARMErrataFix.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ class Patch657417Section : public SyntheticSection {
8282
// Get the virtual address of the branch instruction at patcheeOffset.
8383
uint64_t getBranchAddr() const;
8484

85+
static bool classof(const SectionBase *d) {
86+
return d->kind() == InputSectionBase::Synthetic && d->name ==".text.patch";
87+
}
88+
8589
// The Section we are patching.
8690
const InputSection *patchee;
8791
// The offset of the instruction in the Patchee section we are patching.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// REQUIRES: aarch64
2+
// RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux --asm-macro-max-nesting-depth=40000 %s -o %t.o
3+
// RUN: echo "SECTIONS { \
4+
// RUN: .text1 0x10000 : { *(.text.*) } \
5+
// RUN: .text2 0xf010000 : { *(.target) } } " > %t.script
6+
// RUN: ld.lld --script %t.script -fix-cortex-a53-843419 %t.o -o %t2 --print-map 2>&1 | FileCheck %s
7+
8+
/// We use %(\parameter) to evaluate expression, which requires .altmacro.
9+
.altmacro
10+
11+
/// Test to reproduce the conditions that trigger R_AARCH64_JUMP26 out of range
12+
/// errors in pr44071. We create a large number of patches and thunks, with an
13+
/// LLD with the fault, the patches will be inserted after the thunks and due
14+
/// to the size of the thunk section some of the patches go out of range.
15+
/// With a fixed LLD the patches are inserted before the thunks.
16+
17+
// CHECK: <internal>:(.text.patch)
18+
// CHECK: <internal>:(.text.thunk)
19+
20+
/// Macro to generate the cortex-a53-843419 patch sequence
21+
.macro ERRATA from, to
22+
.balign 4096
23+
.space 4096 - 8
24+
adrp x0, dat1
25+
ldr x1, [x1, #0]
26+
ldr x0, [x0, :got_lo12:dat1]
27+
ret
28+
.if (\to-\from)
29+
ERRATA %(\from+1),\to
30+
.endif
31+
.endm
32+
33+
.section .text.01, "ax", %progbits
34+
.balign 4096
35+
.globl _start
36+
.type _start, %function
37+
.space 4096 - 8
38+
_start:
39+
/// Generate lots of patches.
40+
ERRATA 0, 4000
41+
42+
.macro CALLS from, to
43+
bl far\from
44+
.if (\to-\from)
45+
CALLS %(\from+1),\to
46+
.endif
47+
.endm
48+
49+
/// Generate long range thunks. These are inserted before the patches. Generate
50+
/// a sufficient number such that the patches must be placed before the
51+
/// .text.thunk section, and if they aren't some of the patches go out of
52+
/// range.
53+
.section .text.02, "ax", %progbits
54+
.global func
55+
.type func, %function
56+
func:
57+
CALLS 0, 20000
58+
59+
.section .text.03, "ax", %progbits
60+
.global space1
61+
space1:
62+
.space (1024 * 1024 * 96) + (120 * 4 * 1024)
63+
.balign 4096
64+
65+
.section .text.04, "ax", %progbits
66+
.global space2
67+
space2:
68+
.space 1024 * 1024
69+
70+
.macro DEFS from, to
71+
.global far\from
72+
.type far\from, %function
73+
far\from:
74+
ret
75+
.if (\to-\from)
76+
DEFS %(\from+1),\to
77+
.endif
78+
.endm
79+
80+
/// Define the thunk targets
81+
.section .target, "ax", %progbits
82+
DEFS 0, 20000
83+
84+
.data
85+
.global dat1
86+
dat1:
87+
.xword 0

0 commit comments

Comments
 (0)