xref: /llvm-project/bolt/test/X86/split-func-jump-table-fragment-noparent.s (revision 11791ae7b0b05b8bd8d806331ff51da618912cf8)
1## This reproduces a bug with jump table identification where jump table has
2## entries pointing to code in function and its cold fragment.
3## The fragment is only reachable through jump table.
4
5# REQUIRES: system-linux
6
7# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
8# RUN: llvm-strip --strip-unneeded %t.o
9# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
10# RUN: llvm-bolt %t.exe -o %t.out --lite=0 -v=1 2>&1 | FileCheck %s
11
12# CHECK-NOT: unclaimed PC-relative relocations left in data
13# CHECK: BOLT-INFO: marking main.cold.1 as a fragment of main
14  .text
15  .globl main
16  .type main, %function
17  .p2align 2
18main:
19LBB0:
20  andl $0xf, %ecx
21  cmpb $0x4, %cl
22  ## exit through ret
23  ja LBB3
24
25## jump table dispatch, jumping to label indexed by val in %ecx
26LBB1:
27  leaq JUMP_TABLE(%rip), %r8
28  movzbl %cl, %ecx
29  movslq (%r8,%rcx,4), %rax
30  addq %rax, %r8
31  jmpq *%r8
32
33LBB2:
34  xorq %rax, %rax
35LBB3:
36  addq $0x8, %rsp
37  ret
38.size main, .-main
39
40## cold fragment is only reachable through jump table
41  .globl main.cold.1
42  .type main.cold.1, %function
43  .p2align 2
44main.cold.1:
45  ## load bearing nop: pad LBB4 so that it can't be treated
46  ## as __builtin_unreachable by analyzeJumpTable
47  nop
48LBB4:
49  callq abort
50.size main.cold.1, .-main.cold.1
51
52  .rodata
53## jmp table, entries must be R_X86_64_PC32 relocs
54  .globl JUMP_TABLE
55JUMP_TABLE:
56  .long LBB2-JUMP_TABLE
57  .long LBB3-JUMP_TABLE
58  .long LBB4-JUMP_TABLE
59  .long LBB3-JUMP_TABLE
60