1# This reproduces a bug with BOLT non-reloc mode, during emission, if the user
2# does not use -update-debug-sections. In this bug, if a function gets too large
3# to occupy its original location, but it has a jump table, BOLT would skip
4# rewriting the function but it would still overwrite the jump table in a bogus
5# file offset (offset zero). This will typically corrupt the .interp section,
6# which is the first section in the binary, depending on the size of the jump
7# table that was written. If .interp is corrupted, the binary won't run.
8
9# REQUIRES: system-linux
10
11# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
12# RUN: llvm-strip --strip-unneeded %t.o
13# RUN: %clang %cflags -no-pie -nostartfiles -nostdlib -lc %t.o -o %t.exe
14
15# RUN: llvm-bolt %t.exe -o %t.exe.bolt -relocs=0 -lite=0 -reorder-blocks=reverse
16
17# RUN: %t.exe.bolt 1 2 3
18
19  .file "test.S"
20  .text
21  .globl _start
22  .type _start, @function
23_start:
24  .cfi_startproc
25  xor    %rax,%rax
26  movq   (%rsp), %rdi
27  and    $0x3,%rdi
28  jmpq   *.JT1(,%rdi,8)
29.LBB1:
30  movl   $0x1,%eax
31  jmp    .LBB5
32.LBB2:
33  movl   $0x2,%eax
34  jmp    .LBB5
35.LBB3:
36  movl   $0x3,%eax
37  jmp    .LBB5
38.LBB4:
39  movl   $0x4,%eax
40.LBB5:
41  callq exit@PLT
42  .cfi_endproc
43  .size _start, .-_start
44
45# Make the jump table large enough to force the bug to manifest as .interp
46# being corrupt. Typically .interp will be at offset 0x1c8, so the jump table
47# needs to be larger than that.
48  .section .rodata,"a",@progbits
49  .p2align 3
50.JT1:
51  .quad .LBB1
52  .quad .LBB2
53  .quad .LBB3
54  .quad .LBB4
55  .quad .LBB5
56  .quad .LBB5
57  .rept 100
58  .quad .LBB1
59  .endr
60