116 lines · plain
1## In this test case, we reproduce the behavior seen in gcc where the2## base address of a jump table is decremented by some number and ends up3## at the exact address of a jump table from another function. After4## linking, the instruction references another jump table and that5## confuses BOLT.6## We repro here the following issue:7## Before assembler: Instruction operand is: jumptable - 328## After linking: Instruction operand is: another_jumptable9 10# REQUIRES: system-linux, asserts11 12# XFAIL: *13 14# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o15# RUN: llvm-strip --strip-unneeded %t.o16# RUN: %clang %cflags -no-pie -nostartfiles -nostdlib -lc %t.o -o %t.exe -Wl,-q17 18# RUN: llvm-bolt %t.exe -o %t.exe.bolt --relocs=1 --lite=0 \19# RUN: --reorder-blocks=reverse20 21## Useful when manually testing this. Currently we just check that22## the test does not cause BOLT to assert.23# COM: %t.exe.bolt 1 224 25 .file "jt-symbol-disambiguation-3.s"26 .text27 28# ----29# Func foo contains a jump table whose start is colocated with a30# jump table reference in another function. However, the other function31# does not use the first entries of it and is merely doing arithmetic32# to save the creation of unused first entries.33# ----34 .globl foo35 .type foo, @function36foo:37 .cfi_startproc38 xor %rax,%rax39 cmpq $3, %rdi40 ja .LBBAD41 jmpq *.JT1(,%rdi,8)42.LBB1:43 movl $0x4,%eax44 jmp .LBB545.LBB2:46 movl $0x5,%eax47 jmp .LBB548.LBB3:49 movl $0x6,%eax50 jmp .LBB551.LBB4:52 movl $0x7,%eax53.LBB5:54 retq55.LBBAD:56 mov $1, %rdi57 callq exit@PLT58 retq59 .cfi_endproc60 .size foo, .-foo61 62# ----63# Func _start scans an object with indexed access using %rax * 8 as an64# index. However, %rax is known to be at least one, so the compiler65# loads the pointer for the base address as object - 8 instead of just66# object.67# ----68 .globl _start69 .type _start, @function70_start:71 .cfi_startproc72 movq (%rsp), %rdi73 callq foo74 movq $1, %rdi75 cmpq $7, %rax76 ja .LBB1077 # Here the compiler uses the knowledge that the first four entries78 # of the jump table are not accessed and subtracts 32 from the base79 # address of it, so it doesn't have to allocate four unused entries in80 # memory. Unfortunately this can confuse BOLT since it ends up being a81 # direct reference to JT1, after linker is done.82 jmpq *.JT2-32(,%rax,8)83.LBB6:84 xorq %rdi, %rdi85 jmp .LBB1086.LBB7:87 xorq %rdi, %rdi88 jmp .LBB1089.LBB8:90 xorq %rdi, %rdi91 jmp .LBB1092.LBB9:93 xorq %rdi, %rdi94 jmp .LBB1095.LBB10:96 callq exit@PLT97 retq98 .cfi_endproc99 .size _start, .-_start100 101# ----102# Data section103# ----104 .section .rodata,"a",@progbits105 .p2align 3106.JT1:107 .quad .LBB1108 .quad .LBB2109 .quad .LBB3110 .quad .LBB4111.JT2:112 .quad .LBB6113 .quad .LBB7114 .quad .LBB8115 .quad .LBB9116