[PATCH] D61610: [PPC64] implement Thunk Section Spacing
Alfredo Dal'Ava JĂșnior via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 09:02:08 PDT 2019
adalava updated this revision to Diff 198679.
adalava added a comment.
increase to PPC64_REL24 range
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61610/new/
https://reviews.llvm.org/D61610
Files:
lld/ELF/Arch/PPC64.cpp
lld/test/ELF/Inputs/ppc64-far-branch-rangethunk.s
lld/test/ELF/ppc64-branch-thunkspacing.s
Index: lld/test/ELF/ppc64-branch-thunkspacing.s
===================================================================
--- /dev/null
+++ lld/test/ELF/ppc64-branch-thunkspacing.s
@@ -0,0 +1,38 @@
+# REQUIRES: ppc
+
+# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-freebsd13.0 %s -o %t.o
+# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-freebsd13.0 %S/Inputs/ppc64-far-branch-rangethunk.s -o %tfar.o
+# RUN: ld.lld %t.o %tfar.o -o %t2
+# RUN: llvm-objdump -d %t2 | FileCheck %s
+
+.section .init,"ax", at progbits
+.align 2
+.globl _start
+.type _start, at function
+
+_start:
+ stwu 1,-16(1)
+ mflr 0
+ stw 31,12(1)
+ stw 0,20(1)
+ mr 31,1
+ bl too_far1
+
+
+# When ThunkSpacing is applied, "__long_branch_too_far1" is shifted
+# to an offset after "_start"
+
+# CHECK: Disassembly of section .init:
+# CHECK: 0000000010010000 _start:
+# CHECK-NEXT: 10010000: 94 21 ff f0 stwu 1, -16(1)
+# CHECK-NEXT: 10010004: 7c 08 02 a6 mflr 0
+# CHECK-NEXT: 10010008: 93 e1 00 0c stw 31, 12(1)
+# CHECK-NEXT: 1001000c: 90 01 00 14 stw 0, 20(1)
+# CHECK-NEXT: 10010010: 7c 3f 0b 78 mr 31, 1
+# CHECK-NEXT: 10010014: 48 00 00 05 bl .+4
+
+# CHECK: 0000000010010018 __long_branch_too_far1:
+# CHECK-NEXT: 10010018: 3d 82 10 02 addis 12, 2, 4098
+# CHECK-NEXT: 1001001c: e9 8c 80 00 ld 12, -32768(12)
+# CHECK-NEXT: 10010020: 7d 89 03 a6 mtctr 12
+# CHECK-NEXT: 10010024: 4e 80 04 20 bctr
Index: lld/test/ELF/Inputs/ppc64-far-branch-rangethunk.s
===================================================================
--- /dev/null
+++ lld/test/ELF/Inputs/ppc64-far-branch-rangethunk.s
@@ -0,0 +1,9 @@
+
+.section .init,"ax", at progbits,unique,2
+.align 2
+.global too_far1
+.type too_far1,%function
+
+// place too_far1 to + 64MB (should be above 32MB)
+too_far1 = 0x10010000 + 0x4000000
+
Index: lld/ELF/Arch/PPC64.cpp
===================================================================
--- lld/ELF/Arch/PPC64.cpp
+++ lld/ELF/Arch/PPC64.cpp
@@ -211,6 +211,7 @@
bool adjustPrologueForCrossSplitStack(uint8_t *Loc, uint8_t *End,
uint8_t StOther) const override;
+ uint32_t getThunkSectionSpacing() const override;
};
} // namespace
@@ -1051,6 +1052,25 @@
return true;
}
+uint32_t PPC64::getThunkSectionSpacing() const {
+ // PowerPC64 has the following basic branch instructions:
+ //
+ // - b[l,a] PPC64_REL24 range [33,554,432...33,554,428]
+ // - bc[l,a] PPC64_REL14 range [-32,768...32764]
+ //
+ // We take the less strict range, and intentionally use a lower
+ // size than the maximum branch range so the end of the ThunkSection
+ // is more likely to be within range of the branch instruction that
+ // is furthest away.
+ //
+ // Reducing it in 0x80000 allow creating 32,768 16 byte Thunks at any
+ // offset in a ThunkSection without risk of a branch to one of the
+ // Thunks going out of range.
+ //
+ // See comment in Arch/ARM.cpp for more detais of getThunkSectionSpacing().
+ return 0x2000000 - 0x80000;
+}
+
TargetInfo *elf::getPPC64TargetInfo() {
static PPC64 Target;
return &Target;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61610.198679.patch
Type: text/x-patch
Size: 3093 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190508/02a44ab0/attachment.bin>
More information about the llvm-commits
mailing list