1# In this test case, we reproduce the behavior seen in gcc where the 2# base address of a data object is decremented by some number and lands 3# inside a jump table from another function. 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 -no-pie -nostartfiles -nostdlib -lc %t.o -o %t.exe -Wl,-q 10 11# RUN: llvm-bolt %t.exe -o %t.exe.bolt --relocs=1 --lite=0 \ 12# RUN: --reorder-blocks=reverse -jump-tables=move 13 14# RUN: %t.exe.bolt 1 2 3 15 16 .file "jt-symbol-disambiguation-2.s" 17 .text 18 19# ---- 20# Func foo contains a jump table whose start is colocated with a 21# symbol marking the end of a data table 22# ---- 23 .globl foo 24 .type foo, @function 25foo: 26 .cfi_startproc 27 xor %rax,%rax 28 and $0x3,%rdi 29 leaq .JT1(%rip), %rax 30 movslq (%rax, %rdi, 4), %rdi 31 addq %rax, %rdi 32 jmpq *%rdi 33.LBB1: 34 movl $0x1,%eax 35 jmp .LBB5 36.LBB2: 37 movl $0x2,%eax 38 jmp .LBB5 39.LBB3: 40 movl $0x3,%eax 41 jmp .LBB5 42.LBB4: 43 movl $0x4,%eax 44.LBB5: 45 retq 46 .cfi_endproc 47 .size foo, .-foo 48 49# ---- 50# Func _start scans an object with indexed access using %rax * 8 as an 51# index. However, %rax is known to be at least one, so the compiler 52# loads the pointer for the base address as object - 8 instead of just 53# object. 54# ---- 55 .globl _start 56 .type _start, @function 57_start: 58 .cfi_startproc 59 movq (%rsp), %rdi 60 callq foo 61 xorq %rbx, %rbx 62 leaq .object-8(%rip), %rsi # indexed access base address 63 movq $1, %rax # start index 64.LBB6: 65 cmpq $4, %rax 66 je .LBB7 67 addq (%rsi,%rax,8), %rbx 68 incq %rax # ++iterator 69 jmp .LBB6 70.LBB7: 71 cmpq $1368, %rbx # check .object contents integrity 72 jne .LBB_BAD 73 xor %rdi, %rdi 74 callq exit@PLT 75 retq 76.LBB_BAD: 77 leaq .message, %rdi 78 callq puts@PLT 79 movq $1, %rdi 80 callq exit@PLT 81 retq 82 .cfi_endproc 83 .size _start, .-_start 84 85# ---- 86# Data section 87# ---- 88 .section .rodata,"a",@progbits 89 .p2align 3 90.JT1: 91 .long .LBB1 - .JT1 92 .long .LBB2 - .JT1 93 .long .LBB3 - .JT1 94 .long .LBB4 - .JT1 95.object: 96 .quad 123 97 .quad 456 98 .quad 789 99.message: 100 .asciz "RUNTIME ASSERTION FAILURE: references in test binary are corrupt after BOLT" 101