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 4# REQUIRES: system-linux 5 6# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o 7# RUN: llvm-strip --strip-unneeded %t.o 8# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q 9# RUN: llvm-bolt %t.exe -o %t.out --lite=0 -v=1 --print-cfg --print-only=main \ 10# RUN: 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 abort in main.cold.1, registers cold fragment the regular way 23 ja main.cold.1 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## Insert padding between functions, so that the next instruction cannot be 41## treated as __builtin_unreachable destination for the jump table. 42 .quad 0 43 44 .globl main.cold.1 45 .type main.cold.1, %function 46 .p2align 2 47main.cold.1: 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 61## Verify that the entry corresponding to the cold fragment was added to 62## the jump table. 63 64# CHECK: PIC Jump table 65# CHECK-NEXT: 0x{{.*}} : 66# CHECK-NEXT: 0x{{.*}} : 67# CHECK-NEXT: 0x{{.*}} : main.cold.1 68# CHECK-NEXT: 0x{{.*}} : 69