1## Check that jump table detection does not fail on a false 2## reference to a jump table. 3 4# REQUIRES: system-linux 5 6# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \ 7# RUN: %s -o %t.o 8# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q 9 10# RUN: llvm-bolt %t.exe --print-cfg \ 11# RUN: --print-only=inc_dup -o %t.out | FileCheck %s 12 13 .file "jump_table.c" 14 .section .rodata 15.LC0: 16 .string "0" 17.LC1: 18 .string "1" 19.LC2: 20 .string "2" 21.LC3: 22 .string "3" 23.LC4: 24 .string "4" 25.LC5: 26 .string "5" 27 .text 28 .globl inc_dup 29 .type inc_dup, @function 30inc_dup: 31.LFB0: 32 .cfi_startproc 33 pushq %rbp 34 .cfi_def_cfa_offset 16 35 .cfi_offset 6, -16 36 movq %rsp, %rbp 37 .cfi_def_cfa_register 6 38 subq $16, %rsp 39 movl %edi, -4(%rbp) 40 movl -4(%rbp), %eax 41 subl $10, %eax 42 cmpl $5, %eax 43 ja .L2 44# Control flow confusing for JT detection 45# CHECK: leaq "JUMP_TABLE{{.*}}"(%rip), %rdx 46 leaq .L4(%rip), %rdx 47 jmp .LJT 48# CHECK: leaq {{.*}}(%rip), %rdx 49 leaq .LC0(%rip), %rdx 50 jmp .L10 51.LJT: 52 movslq (%rdx,%rax,4), %rax 53 addq %rdx, %rax 54# CHECK: jmpq *%rax # UNKNOWN CONTROL FLOW 55 jmp *%rax 56 .section .rodata 57 .align 4 58 .align 4 59.L4: 60 .long .L3-.L4 61 .long .L5-.L4 62 .long .L6-.L4 63 .long .L7-.L4 64 .long .L8-.L4 65 .long .L9-.L4 66 .text 67.L3: 68 leaq .LC0(%rip), %rdi 69 call puts@PLT 70 movl $1, %eax 71 jmp .L10 72.L5: 73 leaq .LC1(%rip), %rdi 74 call puts@PLT 75 movl $2, %eax 76 jmp .L10 77.L6: 78 leaq .LC2(%rip), %rdi 79 call puts@PLT 80 movl $3, %eax 81 jmp .L10 82.L7: 83 leaq .LC3(%rip), %rdi 84 call puts@PLT 85 movl $4, %eax 86 jmp .L10 87.L8: 88 leaq .LC4(%rip), %rdi 89 call puts@PLT 90 movl $5, %eax 91 jmp .L10 92.L9: 93 leaq .LC5(%rip), %rdi 94 call puts@PLT 95 movl $6, %eax 96 jmp .L10 97.L2: 98 movl -4(%rbp), %eax 99 addl $1, %eax 100.L10: 101 leave 102 .cfi_def_cfa 7, 8 103 ret 104 .cfi_endproc 105.LFE0: 106 .size inc_dup, .-inc_dup 107 .text 108 .globl main 109 .type main, @function 110main: 111.LFB1: 112 .cfi_startproc 113 pushq %rbp 114 .cfi_def_cfa_offset 16 115 .cfi_offset 6, -16 116 movq %rsp, %rbp 117 .cfi_def_cfa_register 6 118 subq $16, %rsp 119 movl %edi, -4(%rbp) 120 movq %rsi, -16(%rbp) 121 movl -4(%rbp), %eax 122 addl $9, %eax 123 movl %eax, %edi 124 call inc_dup@PLT 125 leave 126 .cfi_def_cfa 7, 8 127 ret 128 .cfi_endproc 129.LFE1: 130 .size main, .-main 131 .ident "GCC: (GNU) 6.3.0" 132 .section .note.GNU-stack,"",@progbits 133