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 as a fragment of main 14 .text 15 .globl _start 16 .type _start, %function 17_start: 18 callq main.cold 19 call exit 20.size _start, .-_start 21 22 .globl main.cold 23 .type main.cold, %function 24 .p2align 2 25main.cold: 26LBB0: 27 andl $0xf, %ecx 28 cmpb $0x4, %cl 29 ## exit through ret 30 ja LBB3 31 32## jump table dispatch, jumping to label indexed by val in %ecx 33LBB1: 34 leaq JUMP_TABLE(%rip), %r8 35 movzbl %cl, %ecx 36 movslq (%r8,%rcx,4), %rax 37 addq %rax, %r8 38 jmpq *%r8 39 40LBB2: 41 xorq %rax, %rax 42LBB3: 43 addq $0x8, %rsp 44 ret 45.size main.cold, .-main.cold 46 47## main function, referenced from jump table in cold fragment 48 .globl main 49 .type main, %function 50 .p2align 2 51main: 52 ## load bearing nop: pad LBB4 so that it can't be treated 53 ## as __builtin_unreachable by analyzeJumpTable 54 nop 55LBB4: 56 callq abort 57.size main, .-main 58 59 .rodata 60## jmp table, entries must be R_X86_64_PC32 relocs 61 .globl JUMP_TABLE 62JUMP_TABLE: 63 .long LBB2-JUMP_TABLE 64 .long LBB3-JUMP_TABLE 65 .long LBB4-JUMP_TABLE 66 .long LBB3-JUMP_TABLE 67