xref: /llvm-project/bolt/test/runtime/X86/reg-reassign-swap-cold.s (revision a37e8a4bdc4feab14d44eb043a2dfda0c64335ba)
1# This test case reproduces a bug where, during register swapping,
2# the code fragments associated with the function need to be swapped
3# together (which may be generated during PGO optimization). If not
4# handled properly, optimized binary execution can result in a segmentation fault.
5
6# REQUIRES: system-linux
7
8# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
9# RUN: link_fdata %s %t.o %t.fdata
10# RUN: llvm-strip --strip-unneeded %t.o
11# RUN: %clang -no-pie %t.o -o %t.exe -Wl,-q
12# RUN: llvm-bolt %t.exe -o %t.out -data=%t.fdata --reg-reassign | FileCheck %s
13# RUN: %t.out
14
15# CHECK: BOLT-INFO: Reg Reassignment Pass Stats
16# CHECK-NEXT: 2 functions affected.
17  .text
18  .globl  main
19  .globl  main.cold
20  .p2align  4, 0x90
21  .type   main,@function
22  .type   main.cold,@function
23main.cold:
24bb1:
25  cmp     $0x3, %r12
26  jne     bb8
27bb2:
28  jmp     bb4
29main:                                   # @main
30  .cfi_startproc
31# %bb.0:                                # %entry
32  pushq   %rax
33  pushq   %r12
34  pushq   %rbx
35  .cfi_def_cfa_offset 16
36  mov     $0x1,  %r12
37  mov     $0x2,  %rbx
38  add     $0x1,  %r12
39  shr     $0x14, %r12
40  mov     $0x3,  %r12
41bb3:
42  jmp     bb1
43bb4:
44  cmp     $0x3,  %r12
45bb5:
46  jne     bb8
47bb6:
48  xorl    %eax, %eax
49bb7:
50  popq    %rcx
51  popq    %rbx
52  popq    %r12
53  .cfi_def_cfa_offset 8
54  retq
55bb8:
56  mov  $0x1, %rax
57  jmp  bb7
58# FDATA: 1 main.cold #bb2# 1 main #bb4# 0 100
59# FDATA: 1 main #bb5# 1 main #bb6# 0 100
60# FDATA: 1 main #bb3# 1 main.cold 0 0 100
61
62.Lfunc_end0:
63  .size  main, .Lfunc_end0-main
64  .cfi_endproc
65