148 lines · plain
1## Check a common case for BOLT address translation tables. These tables are used2## to translate profile activity happening in a bolted binary back to the3## original binary, so you can run BOLT again, with updated profile collected4## in a production environment that only runs bolted binaries. As BOLT only5## takes no-bolt binaries as inputs, this translation is necessary to cover6## this scenario.7#8# RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe9# RUN: llvm-bolt %t.exe -o %t.out --data %p/Inputs/blarge.fdata \10# RUN: --reorder-blocks=normal --split-functions --enable-bat 2>&1 | FileCheck %s11# RUN: llvm-bat-dump %t.out --dump-all \12# RUN: --translate=0x401180 | FileCheck %s --check-prefix=CHECK-BAT-DUMP13#14## In this test we focus on function usqrt at address 0x401170. This is a15## non-reloc binary case, so we don't expect this address to change, that's16## why we hardcode its address here. This address also comes hardcoded in the17## blarge.yaml input file.18##19## This is the layout of the function before BOLT reorder blocks:20##21## BB Layout : .LBB02, .Ltmp39, .LFT1, .Ltmp38, .LFT222##23## This is the layout of the function after BOLT reorder blocks:24##25## BB Layout : .LBB02, .Ltmp38, .Ltmp39, .LFT2, .LFT326##27## .Ltmp38 is originally at offset 0x39 but gets moved to 0xc (see full dump28## below).29##30## We check that BAT is able to translate references happening in .Ltmp38 to31## its original offset.32##33 34## This binary has 3 functions with profile, all of them are split, so 6 maps.35## BAT creates one map per function fragment.36#37# CHECK: BOLT: 3 out of 7 functions were overwritten.38# CHECK: BOLT-INFO: Wrote 6 BAT maps39# CHECK: BOLT-INFO: Wrote 3 function and 58 basic block hashes40# CHECK: BOLT-INFO: BAT section size (bytes): 94041#42# usqrt mappings (hot part). We match against any key (left side containing43# the bolted binary offsets) because BOLT may change where it puts instructions44# depending on whether it is relaxing a branch or not. But the original input45# binary offsets (right side) should be the same because these addresses are46# hardcoded in the blarge.yaml file.47#48# CHECK-BAT-DUMP: Function Address: 0x401170, hash: 0xace6cbc638b3198349# CHECK-BAT-DUMP-NEXT: BB mappings:50# CHECK-BAT-DUMP-NEXT: 0x0 -> 0x0 hash: 0x36007ba1d80c000051# CHECK-BAT-DUMP-NEXT: 0x8 -> 0x8 (branch)52# CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x39 hash: 0x5c0670552480003953# CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x3d (branch)54# CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x10 hash: 0xd70d7a64320e001055# CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x30 (branch)56#57# CHECK-BAT-DUMP: 3 cold mappings58#59# Now check that the translation 0x401180 maps back to its correct60# input offset (offset 3d in the usqrt input function).61#62# COM: CHECK-BAT-DUMP: Translating addresses according to parsed BAT tables:63# CHECK-BAT-DUMP: 0x401180 -> usqrt + 0x3d64 65# -------------------------66# Full dump for reference (this is not checked):67# -------------------------68 69Binary Function "usqrt" after finalize-functions70 Number : 771 State : CFG finalized72 Address : 0x40117073 Size : 0x4374 MaxSize : 0x4375 Offset : 0xcb076 Section : .text77 Orc Section : .local.text.usqrt78 LSDA : 0x079 IsSimple : 180 IsMultiEntry: 081 IsSplit : 182 BB Count : 583 Hash : a6468f132ec176ca84 BB Layout : .LBB02, .Ltmp38, .Ltmp39, .LFT2, .LFT385 Exec Count : 19986 Profile Acc : 100.0%87 88.LBB02 (4 instructions, align : 1)89 Entry Point90 Exec Count : 19991 CFI State : 092 Input offset: 093 00000000: movl $0x20, %r8d94 00000006: xorl %eax, %eax95 00000008: xorl %edx, %edx # Offset: 896 0000000a: jmp .Ltmp3997 Successors: .Ltmp39 (mispreds: 0, count: 0)98 99.Ltmp38 (2 instructions, align : 1)100 Exec Count : 4711101 CFI State : 0102 Input offset: 39103 Predecessors: .Ltmp39, .LFT2104 0000000c: subl $0x1, %r8d105 00000010: je .LFT3 # Offset: 61106 Successors: .LFT3 (mispreds: 0, count: 0), .Ltmp39 (mispreds: 33, count: 4711)107 108.Ltmp39 (10 instructions, align : 1)109 Exec Count : 4711110 CFI State : 0111 Input offset: 10112 Predecessors: .Ltmp38, .LBB02113 00000012: movq %rdi, %rcx114 00000015: addq %rax, %rax115 00000018: shlq $0x2, %rdi116 0000001c: andl $0xc0000000, %ecx117 00000022: shrq $0x1e, %rcx118 00000026: leaq (%rcx,%rdx,4), %rdx119 0000002a: leaq 0x1(%rax,%rax), %rcx120 0000002f: cmpq %rcx, %rdx121 00000032: jb .Ltmp38 # Offset: 48122 00000034: jmp .LFT2123 Successors: .Ltmp38 (mispreds: 171, count: 2886), .LFT2 (mispreds: 0, count: 0)124 125------- HOT-COLD SPLIT POINT -------126 127.LFT2 (3 instructions, align : 1)128 Exec Count : 0129 CFI State : 0130 Input offset: 32131 Predecessors: .Ltmp39132 00000036: subq %rcx, %rdx133 00000039: addq $0x1, %rax # Offset: 53134 0000003d: jmp .Ltmp38135 Successors: .Ltmp38 (mispreds: 0, count: 0)136 137.LFT3 (2 instructions, align : 1)138 Exec Count : 0139 CFI State : 0140 Input offset: 3f141 Predecessors: .Ltmp38142 0000003f: movq %rax, (%rsi)143 00000042: retq # Offset: 66144 145DWARF CFI Instructions:146 <empty>147End of Function "usqrt"148