61 lines · plain
1# This reproduces a bug with BOLT non-reloc mode, during emission, if the user2# does not use -update-debug-sections. In this bug, if a function gets too large3# to occupy its original location, but it has a jump table, BOLT would skip4# rewriting the function but it would still overwrite the jump table in a bogus5# 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 jump7# table that was written. If .interp is corrupted, the binary won't run.8 9# REQUIRES: system-linux10 11# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o12# RUN: llvm-strip --strip-unneeded %t.o13# RUN: %clang %cflags -no-pie -nostartfiles -nostdlib -lc %t.o -o %t.exe14 15# RUN: llvm-bolt %t.exe -o %t.exe.bolt --relocs=0 --lite=0 \16# RUN: --reorder-blocks=reverse17 18# RUN: %t.exe.bolt 1 2 319 20 .file "test.S"21 .text22 .globl _start23 .type _start, @function24_start:25 .cfi_startproc26 xor %rax,%rax27 movq (%rsp), %rdi28 and $0x3,%rdi29 jmpq *.JT1(,%rdi,8)30.LBB1:31 movl $0x1,%eax32 jmp .LBB533.LBB2:34 movl $0x2,%eax35 jmp .LBB536.LBB3:37 movl $0x3,%eax38 jmp .LBB539.LBB4:40 movl $0x4,%eax41.LBB5:42 callq exit@PLT43 .cfi_endproc44 .size _start, .-_start45 46# Make the jump table large enough to force the bug to manifest as .interp47# being corrupt. Typically .interp will be at offset 0x1c8, so the jump table48# needs to be larger than that.49 .section .rodata,"a",@progbits50 .p2align 351.JT1:52 .quad .LBB153 .quad .LBB254 .quad .LBB355 .quad .LBB456 .quad .LBB557 .quad .LBB558 .rept 10059 .quad .LBB160 .endr61