brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · d81c233 Raw
101 lines · plain
1# In this test case, we reproduce the behavior seen in gcc where the2# base address of a data object is decremented by some number and lands3# inside a jump table from another function.4 5# REQUIRES: system-linux6 7# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o8# RUN: llvm-strip --strip-unneeded %t.o9# RUN: %clang %cflags -no-pie -nostartfiles -nostdlib -lc %t.o -o %t.exe -Wl,-q10 11# RUN: llvm-bolt %t.exe -o %t.exe.bolt --relocs=1 --lite=0 \12# RUN:   --reorder-blocks=reverse -jump-tables=move13 14# RUN: %t.exe.bolt 1 2 315 16  .file "jt-symbol-disambiguation-2.s"17  .text18 19# ----20# Func foo contains a jump table whose start is colocated with a21# symbol marking the end of a data table22# ----23  .globl foo24  .type foo, @function25foo:26  .cfi_startproc27  xor    %rax,%rax28  and    $0x3,%rdi29  leaq   .JT1(%rip), %rax30  movslq  (%rax, %rdi, 4), %rdi31  addq   %rax, %rdi32  jmpq   *%rdi33.LBB1:34  movl   $0x1,%eax35  jmp    .LBB536.LBB2:37  movl   $0x2,%eax38  jmp    .LBB539.LBB3:40  movl   $0x3,%eax41  jmp    .LBB542.LBB4:43  movl   $0x4,%eax44.LBB5:45  retq46  .cfi_endproc47  .size foo, .-foo48 49# ----50# Func _start scans an object with indexed access using %rax * 8 as an51# index. However, %rax is known to be at least one, so the compiler52# loads the pointer for the base address as object - 8 instead of just53# object.54# ----55  .globl _start56  .type _start, @function57_start:58  .cfi_startproc59  movq   (%rsp), %rdi60  callq foo61  xorq   %rbx, %rbx62  leaq   .object-8(%rip), %rsi  # indexed access base address63  movq   $1, %rax               # start index64.LBB6:65  cmpq $4, %rax66  je .LBB767  addq (%rsi,%rax,8), %rbx68  incq %rax   # ++iterator69  jmp .LBB670.LBB7:71  cmpq  $1368, %rbx             # check .object contents integrity72  jne   .LBB_BAD73  xor   %rdi, %rdi74  callq exit@PLT75  retq76.LBB_BAD:77  leaq  .message, %rdi78  callq puts@PLT79  movq  $1, %rdi80  callq exit@PLT81  retq82  .cfi_endproc83  .size _start, .-_start84 85# ----86# Data section87# ----88  .section .rodata,"a",@progbits89  .p2align 390.JT1:91  .long .LBB1 - .JT192  .long .LBB2 - .JT193  .long .LBB3 - .JT194  .long .LBB4 - .JT195.object:96  .quad 12397  .quad 45698  .quad 78999.message:100  .asciz "RUNTIME ASSERTION FAILURE: references in test binary are corrupt after BOLT"101