1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
# Check a common case for BOLT address translation tables. These tables are used
# to translate profile activity happening in a bolted binary back to the
# original binary, so you can run BOLT again, with updated profile collected
# in a production environment that only runs bolted binaries. As BOLT only
# takes no-bolt binaries as inputs, this translation is necessary to cover
# this scenario.
#
# RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe
# RUN: llvm-bolt %t.exe -o %t.out --data %p/Inputs/blarge.fdata \
# RUN: --reorder-blocks=normal --split-functions --enable-bat 2>&1 | FileCheck %s
# RUN: llvm-bat-dump %t.out --dump-all \
# RUN: --translate=0x401180 | FileCheck %s --check-prefix=CHECK-BAT-DUMP
#
# In this test we focus on function usqrt at address 0x401170. This is a
# non-reloc binary case, so we don't expect this address to change, that's
# why we hardcode its address here. This address also comes hardcoded in the
# blarge.yaml input file.
#
# This is the layout of the function before BOLT reorder blocks:
#
# BB Layout : .LBB02, .Ltmp39, .LFT1, .Ltmp38, .LFT2
#
# This is the layout of the function after BOLT reorder blocks:
#
# BB Layout : .LBB02, .Ltmp38, .Ltmp39, .LFT2, .LFT3
#
# .Ltmp38 is originally at offset 0x39 but gets moved to 0xc (see full dump
# below).
#
# We check that BAT is able to translate references happening in .Ltmp38 to
# its original offset.
#
# This binary has 3 functions with profile, all of them are split, so 6 maps.
# BAT creates one map per function fragment.
#
# CHECK: BOLT: 3 out of 7 functions were overwritten.
# CHECK: BOLT-INFO: Wrote 6 BAT maps
# CHECK: BOLT-INFO: Wrote 3 BAT cold-to-hot entries
#
# usqrt mappings (hot part). We match against any key (left side containing
# the bolted binary offsets) because BOLT may change where it puts instructions
# depending on whether it is relaxing a branch or not. But the original input
# binary offsets (right side) should be the same because these addresses are
# hardcoded in the blarge.yaml file.
#
# CHECK-BAT-DUMP: Function Address: 0x401170
# CHECK-BAT-DUMP-NEXT: BB mappings:
# CHECK-BAT-DUMP-NEXT: 0x0 -> 0x0
# CHECK-BAT-DUMP-NEXT: 0x8 -> 0x8 (branch)
# CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x39
# CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x3d (branch)
# CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x10
# CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x30 (branch)
#
# CHECK-BAT-DUMP: 3 cold mappings
#
# Now check that the translation 0x401180 maps back to its correct
# input offset (offset 3d in the usqrt input function).
#
# COM: CHECK-BAT-DUMP: Translating addresses according to parsed BAT tables:
# CHECK-BAT-DUMP: 0x401180 -> usqrt + 0x3d
# -------------------------
# Full dump for reference (this is not checked):
# -------------------------
Binary Function "usqrt" after finalize-functions
Number : 7
State : CFG finalized
Address : 0x401170
Size : 0x43
MaxSize : 0x43
Offset : 0xcb0
Section : .text
Orc Section : .local.text.usqrt
LSDA : 0x0
IsSimple : 1
IsMultiEntry: 0
IsSplit : 1
BB Count : 5
Hash : a6468f132ec176ca
BB Layout : .LBB02, .Ltmp38, .Ltmp39, .LFT2, .LFT3
Exec Count : 199
Profile Acc : 100.0%
.LBB02 (4 instructions, align : 1)
Entry Point
Exec Count : 199
CFI State : 0
Input offset: 0
00000000: movl $0x20, %r8d
00000006: xorl %eax, %eax
00000008: xorl %edx, %edx # Offset: 8
0000000a: jmp .Ltmp39
Successors: .Ltmp39 (mispreds: 0, count: 0)
.Ltmp38 (2 instructions, align : 1)
Exec Count : 4711
CFI State : 0
Input offset: 39
Predecessors: .Ltmp39, .LFT2
0000000c: subl $0x1, %r8d
00000010: je .LFT3 # Offset: 61
Successors: .LFT3 (mispreds: 0, count: 0), .Ltmp39 (mispreds: 33, count: 4711)
.Ltmp39 (10 instructions, align : 1)
Exec Count : 4711
CFI State : 0
Input offset: 10
Predecessors: .Ltmp38, .LBB02
00000012: movq %rdi, %rcx
00000015: addq %rax, %rax
00000018: shlq $0x2, %rdi
0000001c: andl $0xc0000000, %ecx
00000022: shrq $0x1e, %rcx
00000026: leaq (%rcx,%rdx,4), %rdx
0000002a: leaq 0x1(%rax,%rax), %rcx
0000002f: cmpq %rcx, %rdx
00000032: jb .Ltmp38 # Offset: 48
00000034: jmp .LFT2
Successors: .Ltmp38 (mispreds: 171, count: 2886), .LFT2 (mispreds: 0, count: 0)
------- HOT-COLD SPLIT POINT -------
.LFT2 (3 instructions, align : 1)
Exec Count : 0
CFI State : 0
Input offset: 32
Predecessors: .Ltmp39
00000036: subq %rcx, %rdx
00000039: addq $0x1, %rax # Offset: 53
0000003d: jmp .Ltmp38
Successors: .Ltmp38 (mispreds: 0, count: 0)
.LFT3 (2 instructions, align : 1)
Exec Count : 0
CFI State : 0
Input offset: 3f
Predecessors: .Ltmp38
0000003f: movq %rax, (%rsi)
00000042: retq # Offset: 66
DWARF CFI Instructions:
<empty>
End of Function "usqrt"
|