[BOLT][TEST] Import small tests

Summary:
Imported small internal tests:
- asm_func_debug.test
- basic_instrumentation.test
- bolt_icf.test
- ctc_and_unreachable.test
- double_jump.test
- exceptions_args.test
- exceptions_instrumentation.test
- fptr.test

(cherry picked from FBD32032684)
This commit is contained in:
Amir Ayupov 2021-10-29 13:31:22 -07:00 committed by Maksim Panchenko
parent 9ab0662211
commit f808ea00bd
20 changed files with 792 additions and 1 deletions

View File

@ -22,6 +22,7 @@ list(APPEND BOLT_TEST_DEPS
merge-fdata
llvm-nm
llvm-objdump
llvm-readelf
llvm-readobj
yaml2obj
llvm-strip

View File

@ -0,0 +1,27 @@
int fiz() {
return fiz();
}
int faz() {
return faz();
}
int zip () {
return 0;
}
int zap () {
return 0;
}
int foo () {
return zip();
}
int bar () {
return zap();
}
int main() {
return foo();
}

View File

@ -0,0 +1,15 @@
.text
.globl foo
.type foo, @function
foo:
nop
nop
nop
nop
nop
nop
nop
nop
ret
.size foo, .-foo

View File

@ -0,0 +1,4 @@
int main() {
foo();
return 0;
}

View File

@ -0,0 +1,44 @@
.text
.globl foo
.type foo, @function
foo:
cmp $1, %rdi
je bar
jmp .L2
.L1:
ret
.L2:
cmpq $1, %rdi
jne .L1
.size foo, .-foo
.globl bar
.type bar, @function
bar:
ret
.size bar, .-bar
.globl main
.type main, @function
main:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
movq %rsi, -16(%rbp)
movl -4(%rbp), %eax
movl %eax, %edi
call foo
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size main, .-main

View File

@ -0,0 +1,37 @@
/*
* A contrived example to test the double jump removal peephole.
*/
extern "C" unsigned long bar(unsigned long count) {
return count + 1;
}
unsigned long foo(unsigned long count) {
asm(
" cmpq $1,%0\n"
" je .L7\n"
" incq %0\n"
" jmp .L1\n"
".L1: jmp .L2\n"
".L2: incq %0\n"
" cmpq $2,%0\n"
" jne .L3\n"
" jmp .L4\n"
".L3: jmp .L5\n"
".L5: incq %0\n"
".L4: movq %0,%%rdi\n"
" pop %%rbp\n"
" jmp .L6\n"
".L7: pop %%rbp\n"
" incq %0\n"
" jmp .L6\n"
".L6: jmp bar\n"
:
: "m"(count)
);
return count;
}
int main(int argc, const char* argv[]) {
return foo(38);
}

456
bolt/test/X86/Inputs/exc_args.s Executable file
View File

@ -0,0 +1,456 @@
.file "exc_args.cpp"
.text
.globl _Z3fooiiiiiiii
.type _Z3fooiiiiiiii, @function
_Z3fooiiiiiiii:
.LFB15:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $32, %rsp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
movl %edx, -12(%rbp)
movl %ecx, -16(%rbp)
movl %r8d, -20(%rbp)
movl %r9d, -24(%rbp)
cmpl $1, -4(%rbp)
jle .L2
movl $1, %edi
call __cxa_allocate_exception
movl $0, %edx
movl $_ZTI4ExcG, %esi
movq %rax, %rdi
call __cxa_throw
.L2:
movl $1, %edi
call __cxa_allocate_exception
movl $0, %edx
movl $_ZTI4ExcC, %esi
movq %rax, %rdi
call __cxa_throw
.cfi_endproc
.LFE15:
.size _Z3fooiiiiiiii, .-_Z3fooiiiiiiii
.globl _Z11filter_onlyi
.type _Z11filter_onlyi, @function
_Z11filter_onlyi:
.LFB16:
.cfi_startproc
.cfi_personality 0x3,__gxx_personality_v0
.cfi_lsda 0x3,.LLSDA16
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
movl -4(%rbp), %eax
pushq $7
pushq $6
movl $5, %r9d
movl $4, %r8d
movl $3, %ecx
movl $2, %edx
movl $1, %esi
movl %eax, %edi
.LEHB0:
.cfi_escape 0x2e,0x10
call _Z3fooiiiiiiii
.LEHE0:
addq $16, %rsp
jmp .L7
.L6:
cmpq $-1, %rdx
je .L5
movq %rax, %rdi
.LEHB1:
call _Unwind_Resume
.L5:
movq %rax, %rdi
call __cxa_call_unexpected
.LEHE1:
.L7:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE16:
.globl __gxx_personality_v0
.section .gcc_except_table,"a",@progbits
.align 4
.LLSDA16:
.byte 0xff
.byte 0x3
.uleb128 .LLSDATT16-.LLSDATTD16
.LLSDATTD16:
.byte 0x1
.uleb128 .LLSDACSE16-.LLSDACSB16
.LLSDACSB16:
.uleb128 .LEHB0-.LFB16
.uleb128 .LEHE0-.LEHB0
.uleb128 .L6-.LFB16
.uleb128 0x1
.uleb128 .LEHB1-.LFB16
.uleb128 .LEHE1-.LEHB1
.uleb128 0
.uleb128 0
.LLSDACSE16:
.byte 0x7f
.byte 0
.align 4
.long _ZTI4ExcA
.long _ZTI4ExcB
.long _ZTI4ExcC
.long _ZTI4ExcD
.long _ZTI4ExcE
.long _ZTI4ExcF
.LLSDATT16:
.byte 0x1
.byte 0x2
.byte 0x3
.byte 0x4
.byte 0x5
.byte 0x6
.byte 0
.text
.size _Z11filter_onlyi, .-_Z11filter_onlyi
.section .rodata
.align 8
.LC0:
.string "this statement is cold and should be outlined"
.text
.globl _Z12never_throwsv
.type _Z12never_throwsv, @function
_Z12never_throwsv:
.LFB17:
.cfi_startproc
.cfi_personality 0x3,__gxx_personality_v0
.cfi_lsda 0x3,.LLSDA17
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $.LC0, %edi
.LEHB2:
call puts
.LEHE2:
jmp .L12
.L11:
cmpq $-1, %rdx
je .L10
movq %rax, %rdi
.LEHB3:
call _Unwind_Resume
.L10:
movq %rax, %rdi
call __cxa_call_unexpected
.LEHE3:
.L12:
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE17:
.section .gcc_except_table
.align 4
.LLSDA17:
.byte 0xff
.byte 0x3
.uleb128 .LLSDATT17-.LLSDATTD17
.LLSDATTD17:
.byte 0x1
.uleb128 .LLSDACSE17-.LLSDACSB17
.LLSDACSB17:
.uleb128 .LEHB2-.LFB17
.uleb128 .LEHE2-.LEHB2
.uleb128 .L11-.LFB17
.uleb128 0x1
.uleb128 .LEHB3-.LFB17
.uleb128 .LEHE3-.LEHB3
.uleb128 0
.uleb128 0
.LLSDACSE17:
.byte 0x7f
.byte 0
.align 4
.LLSDATT17:
.byte 0
.text
.size _Z12never_throwsv, .-_Z12never_throwsv
.section .rodata
.LC1:
.string "caught exception"
.LC2:
.string "caught ExcC"
.text
.globl main
.type main, @function
main:
.LFB18:
.cfi_startproc
.cfi_personality 0x3,__gxx_personality_v0
.cfi_lsda 0x3,.LLSDA18
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
pushq %rbx
subq $40, %rsp
.cfi_offset 3, -24
movl %edi, -36(%rbp)
movq %rsi, -48(%rbp)
movl $1768710518, -26(%rbp)
movw $100, -22(%rbp)
movl $0, -20(%rbp)
.L17:
cmpl $999999, -20(%rbp)
ja .L14
cmpl $2, -36(%rbp)
jne .L15
call _Z12never_throwsv
.L15:
cmpl $2, -36(%rbp)
jne .L16
movl -36(%rbp), %eax
movl %eax, %edi
.LEHB4:
call _Z11filter_onlyi
.LEHE4:
.L16:
movl -36(%rbp), %eax
pushq $7
pushq $6
movl $5, %r9d
movl $4, %r8d
movl $3, %ecx
movl $2, %edx
movl $1, %esi
movl %eax, %edi
.LEHB5:
.cfi_escape 0x2e,0x10
call _Z3fooiiiiiiii
.LEHE5:
addq $16, %rsp
.L25:
addl $1, -20(%rbp)
jmp .L17
.L14:
movl $0, %eax
jmp .L31
.L27:
movq %rax, %rdi
call __cxa_begin_catch
movl $.LC1, %edi
movl $0, %eax
.LEHB6:
.cfi_escape 0x2e,0
call printf
.LEHE6:
.LEHB7:
call __cxa_end_catch
.LEHE7:
jmp .L16
.L28:
movq %rax, %rbx
call __cxa_end_catch
movq %rbx, %rax
movq %rax, %rdi
.LEHB8:
call _Unwind_Resume
.L29:
cmpq $2, %rdx
je .L22
movq %rax, %rdi
call _Unwind_Resume
.LEHE8:
.L22:
movq %rax, %rdi
call __cxa_begin_catch
movzbl -26(%rbp), %eax
cmpb $118, %al
je .L23
call abort
.L23:
movzbl -25(%rbp), %eax
cmpb $97, %al
je .L24
call abort
.L24:
movl $.LC2, %edi
.LEHB9:
call puts
.LEHE9:
call __cxa_end_catch
jmp .L25
.L30:
movq %rax, %rbx
call __cxa_end_catch
movq %rbx, %rax
movq %rax, %rdi
.LEHB10:
call _Unwind_Resume
.LEHE10:
.L31:
movq -8(%rbp), %rbx
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE18:
.section .gcc_except_table
.align 4
.LLSDA18:
.byte 0xff
.byte 0x3
.uleb128 .LLSDATT18-.LLSDATTD18
.LLSDATTD18:
.byte 0x1
.uleb128 .LLSDACSE18-.LLSDACSB18
.LLSDACSB18:
.uleb128 .LEHB4-.LFB18
.uleb128 .LEHE4-.LEHB4
.uleb128 .L27-.LFB18
.uleb128 0x1
.uleb128 .LEHB5-.LFB18
.uleb128 .LEHE5-.LEHB5
.uleb128 .L29-.LFB18
.uleb128 0x3
.uleb128 .LEHB6-.LFB18
.uleb128 .LEHE6-.LEHB6
.uleb128 .L28-.LFB18
.uleb128 0
.uleb128 .LEHB7-.LFB18
.uleb128 .LEHE7-.LEHB7
.uleb128 0
.uleb128 0
.uleb128 .LEHB8-.LFB18
.uleb128 .LEHE8-.LEHB8
.uleb128 0
.uleb128 0
.uleb128 .LEHB9-.LFB18
.uleb128 .LEHE9-.LEHB9
.uleb128 .L30-.LFB18
.uleb128 0
.uleb128 .LEHB10-.LFB18
.uleb128 .LEHE10-.LEHB10
.uleb128 0
.uleb128 0
.LLSDACSE18:
.byte 0x1
.byte 0
.byte 0x2
.byte 0
.align 4
.long _ZTI4ExcC
.long 0
.LLSDATT18:
.text
.size main, .-main
.weak _ZTI4ExcF
.section .rodata._ZTI4ExcF,"aG",@progbits,_ZTI4ExcF,comdat
.align 8
.type _ZTI4ExcF, @object
.size _ZTI4ExcF, 16
_ZTI4ExcF:
.quad _ZTVN10__cxxabiv117__class_type_infoE+16
.quad _ZTS4ExcF
.weak _ZTS4ExcF
.section .rodata._ZTS4ExcF,"aG",@progbits,_ZTS4ExcF,comdat
.type _ZTS4ExcF, @object
.size _ZTS4ExcF, 6
_ZTS4ExcF:
.string "4ExcF"
.weak _ZTI4ExcE
.section .rodata._ZTI4ExcE,"aG",@progbits,_ZTI4ExcE,comdat
.align 8
.type _ZTI4ExcE, @object
.size _ZTI4ExcE, 16
_ZTI4ExcE:
.quad _ZTVN10__cxxabiv117__class_type_infoE+16
.quad _ZTS4ExcE
.weak _ZTS4ExcE
.section .rodata._ZTS4ExcE,"aG",@progbits,_ZTS4ExcE,comdat
.type _ZTS4ExcE, @object
.size _ZTS4ExcE, 6
_ZTS4ExcE:
.string "4ExcE"
.weak _ZTI4ExcD
.section .rodata._ZTI4ExcD,"aG",@progbits,_ZTI4ExcD,comdat
.align 8
.type _ZTI4ExcD, @object
.size _ZTI4ExcD, 16
_ZTI4ExcD:
.quad _ZTVN10__cxxabiv117__class_type_infoE+16
.quad _ZTS4ExcD
.weak _ZTS4ExcD
.section .rodata._ZTS4ExcD,"aG",@progbits,_ZTS4ExcD,comdat
.type _ZTS4ExcD, @object
.size _ZTS4ExcD, 6
_ZTS4ExcD:
.string "4ExcD"
.weak _ZTI4ExcB
.section .rodata._ZTI4ExcB,"aG",@progbits,_ZTI4ExcB,comdat
.align 8
.type _ZTI4ExcB, @object
.size _ZTI4ExcB, 16
_ZTI4ExcB:
.quad _ZTVN10__cxxabiv117__class_type_infoE+16
.quad _ZTS4ExcB
.weak _ZTS4ExcB
.section .rodata._ZTS4ExcB,"aG",@progbits,_ZTS4ExcB,comdat
.type _ZTS4ExcB, @object
.size _ZTS4ExcB, 6
_ZTS4ExcB:
.string "4ExcB"
.weak _ZTI4ExcA
.section .rodata._ZTI4ExcA,"aG",@progbits,_ZTI4ExcA,comdat
.align 8
.type _ZTI4ExcA, @object
.size _ZTI4ExcA, 16
_ZTI4ExcA:
.quad _ZTVN10__cxxabiv117__class_type_infoE+16
.quad _ZTS4ExcA
.weak _ZTS4ExcA
.section .rodata._ZTS4ExcA,"aG",@progbits,_ZTS4ExcA,comdat
.type _ZTS4ExcA, @object
.size _ZTS4ExcA, 6
_ZTS4ExcA:
.string "4ExcA"
.weak _ZTI4ExcC
.section .rodata._ZTI4ExcC,"aG",@progbits,_ZTI4ExcC,comdat
.align 8
.type _ZTI4ExcC, @object
.size _ZTI4ExcC, 16
_ZTI4ExcC:
.quad _ZTVN10__cxxabiv117__class_type_infoE+16
.quad _ZTS4ExcC
.weak _ZTS4ExcC
.section .rodata._ZTS4ExcC,"aG",@progbits,_ZTS4ExcC,comdat
.type _ZTS4ExcC, @object
.size _ZTS4ExcC, 6
_ZTS4ExcC:
.string "4ExcC"
.weak _ZTI4ExcG
.section .rodata._ZTI4ExcG,"aG",@progbits,_ZTI4ExcG,comdat
.align 8
.type _ZTI4ExcG, @object
.size _ZTI4ExcG, 16
_ZTI4ExcG:
.quad _ZTVN10__cxxabiv117__class_type_infoE+16
.quad _ZTS4ExcG
.weak _ZTS4ExcG
.section .rodata._ZTS4ExcG,"aG",@progbits,_ZTS4ExcG,comdat
.type _ZTS4ExcG, @object
.size _ZTS4ExcG, 6
_ZTS4ExcG:
.string "4ExcG"
.ident "GCC: (GNU) 8.5.0 20210514 (Red Hat 8.5.0-3)"
.section .note.GNU-stack,"",@progbits

View File

@ -0,0 +1,26 @@
# Verify that we update DW_TAG_compile_unit' ranges and .debug_aranges
# for assembly function that doesn't have corresponding DIE.
#
# The input test case foo() contains nops that we remove.
RUN: %clang -g %p/Inputs/asm_foo.s %p/Inputs/asm_main.c -o %t.exe
RUN: llvm-bolt %t.exe -o %t -update-debug-sections
RUN: llvm-dwarfdump -all %t | FileCheck %s
# Check ranges were created/updated for asm compile unit
CHECK: 0x0000000b: DW_TAG_compile_unit
CHECK-NEXT: DW_AT_stmt_list (0x00000000)
CHECK-NEXT: DW_AT_low_pc (0x0000000000000000)
CHECK-NEXT: DW_AT_ranges
CHECK-NEXT: [0x0000000000[[#%x,ADDR:]],
CHECK-SAME: 0x0000000000[[#ADDR+1]]))
CHECK-NEXT: DW_AT_name ("{{.*}}/asm_foo.s")
# Check .debug_aranges was updated for asm module
CHECK: .debug_aranges contents:
CHECK-NEXT: Address Range Header: length = 0x0000002c, format = DWARF32, version = 0x0002, cu_offset = 0x00000000, addr_size = 0x08, seg_size = 0x00
CHECK-NEXT: [0x0000000000[[#ADDR]], 0x0000000000[[#ADDR+1]])
# Check line number info was updated
CHECK: 0x0000000000[[#ADDR]] 13 0 1 0 0 is_stmt
CHECK-NEXT: 0x0000000000[[#ADDR+1]] 13 0 1 0 0 is_stmt end_sequence

View File

@ -0,0 +1,13 @@
# Check that we don't fail processing a function with conditional tail call and
# a fall-through to a next function (result of builtin_unreachable()).
RUN: %clang %cflags %p/Inputs/ctc_and_unreachable.s -o %t.exe -Wl,-q
RUN: llvm-bolt %t.exe -o %t -print-after-lowering -print-only=foo 2>&1 | FileCheck %s
CHECK: Binary Function "foo"
CHECK: cmpq $0x1, %rdi
CHECK: je bar # TAILCALL
CHECK: retq
CHECK: cmpq $0x1, %rdi
CHECK: jmp .Ltmp[[#]]
CHECK: End of Function "foo"

View File

@ -0,0 +1,26 @@
# Test the double jump removqal peephole.
RUN: %clang %cflags %p/Inputs/double_jump.cpp -o %t.exe
RUN: (llvm-bolt %t.exe -peepholes=double-jumps \
RUN: -eliminate-unreachable -o %t 2>&1 \
RUN: && llvm-objdump -d %t --print-imm-hex --no-show-raw-insn) | FileCheck %s
CHECK: BOLT-INFO: Peephole: 1 double jumps patched.
CHECK: <_Z3foom>:
CHECK-NEXT: pushq %rbp
CHECK-NEXT: movq %rsp, %rbp
CHECK-NEXT: movq %rdi, -0x8(%rbp)
CHECK-NEXT: cmpq $0x1, -0x8(%rbp)
CHECK-NEXT: je {{.*}} <_Z3foom+0x2c>
CHECK-NEXT: incq -0x8(%rbp)
CHECK-NEXT: incq -0x8(%rbp)
CHECK-NEXT: cmpq $0x2, -0x8(%rbp)
CHECK-NEXT: je {{.*}} <_Z3foom+0x22>
CHECK-NEXT: incq -0x8(%rbp)
CHECK-NEXT: movq -0x8(%rbp), %rdi
CHECK-NEXT: popq %rbp
CHECK-NEXT: jmp {{.*}} <bar>
CHECK-NEXT: popq %rbp
CHECK-NEXT: incq -0x8(%rbp)
CHECK-NEXT: jmp {{.*}} <bar>

View File

@ -0,0 +1,10 @@
# Check that we handle GNU_args_size correctly.
# It is generated for throwing functions with LP that have parameters on stack.
RUN: %clangxx %p/Inputs/exc_args.s -o %t
RUN: llvm-bolt %t -o /dev/null -print-finalized -print-only=main | FileCheck %s
CHECK: Binary Function "main" after finalize-functions
CHECK: callq _Z3fooiiiiiiii {{.*}} GNU_args_size = 16
CHECK: callq printf@PLT {{.*}} GNU_args_size = 0
CHECK: End of Function "main"

View File

@ -4,7 +4,7 @@
REQUIRES: x86_64-linux
RUN: %clangxx %p/Inputs/vararg.s -o %t -Wl,-q
RUN: %clangxx %p/../Inputs/vararg.s -o %t -Wl,-q
RUN: llvm-bolt %t -o /dev/null -print-cfg -print-only=.*printf.* |& FileCheck %s
RUN: %clangxx %p/Inputs/vararg_pic.s -o %t.pic -Wl,-q
RUN: llvm-bolt %t.pic -o /dev/null -print-cfg -print-only=.*printf.* \

15
bolt/test/bolt_icf.test Normal file
View File

@ -0,0 +1,15 @@
# Check for the replacement of calls to identical functions.
RUN: %clangxx %p/Inputs/bolt_icf.cpp -g -Wl,-q -o %t.exe
RUN: llvm-bolt %t.exe -relocs -o %t -icf 2>&1 | FileCheck %s
RUN: llvm-nm -n %t | FileCheck %s -check-prefix=CHECK-SYM
CHECK: BOLT-INFO: ICF folded [[#]] out of [[#]] functions in [[#]] passes.
# Check that symbols are updated correctly in the symbol table
CHECK-SYM-DAG: [[#%x,FIZ:]] T _Z3fizv
CHECK-SYM-DAG: [[#FIZ]] T _Z3fazv
CHECK-SYM-DAG: [[#%x,ZIP:]] T _Z3zipv
CHECK-SYM-DAG: [[#ZIP]] T _Z3zapv
CHECK-SYM-DAG: [[#%x,FOO:]] T _Z3foov
CHECK-SYM-DAG: [[#FOO]] T _Z3barv

View File

@ -76,6 +76,7 @@ tools = [
ToolSubst('llvm-objdump', unresolved='fatal'),
ToolSubst('llvm-objcopy', unresolved='fatal'),
ToolSubst('llvm-strip', unresolved='fatal'),
ToolSubst('llvm-readelf', unresolved='fatal'),
ToolSubst('link_fdata', command=FindTool('link_fdata.sh'), unresolved='fatal'),
]
llvm_config.add_tool_substitutions(tools, tool_dirs)

View File

@ -0,0 +1,45 @@
// Test that we can have a statement that throws in hot cold
// and a landing pad in cold code.
//
// Record performance data with no args. Run test with 2 args.
#include <stdio.h>
#include <stdint.h>
int foo()
{
return 0;
}
void bar(int a) {
if (a > 2 && a % 2)
throw new int();
}
void filter_only(){
foo();
}
int main(int argc, char **argv)
{
unsigned r = 0;
uint64_t limit = (argc >= 2 ? 10 : 500000000);
for (uint64_t i = 0; i < limit; ++i) {
i += foo();
try {
bar(argc);
try {
if (argc >= 2)
throw new int();
} catch (...) {
printf("catch 2\n");
throw new int();
}
} catch (...) {
printf("catch 1\n");
}
}
return 0;
}

View File

@ -0,0 +1,19 @@
// Make sure all printed values are the same and are updated after BOLT.
#include <stdio.h>
int main(int argc, char *argv[]);
unsigned long Global = (unsigned long)main + 0x7fffffff;
int main(int argc, char *argv[]) {
unsigned long Local = (unsigned long)&main + 0x7fffffff;
unsigned long Local2 = &main + 0x7fffffff;
printf("Global = 0x%lx\n", Global);
printf("Local = 0x%lx\n", Local);
printf("Local2 = 0x%lx\n", Local2);
return 0;
}

View File

@ -0,0 +1,22 @@
# Try to instrument a very fast test. varargs will not execute any code during
# runtime besides returning zero in main, so it is a good trivial case.
REQUIRES: system-linux
RUN: %clang %p/../../Inputs/vararg.s -Wl,-q -o %t.exe
RUN: llvm-bolt %t.exe -o %t -instrument \
RUN: -instrumentation-file=%t \
RUN: -instrumentation-file-append-pid
# Execute program to collect profile
RUN: rm %t.*.fdata || echo Nothing to remove
RUN: %t
# Profile should be written to %t.PID.fdata, check it
RUN: mv %t.*.fdata %t.fdata
RUN: cat %t.fdata | FileCheck -check-prefix=CHECK %s
# Check BOLT works with this profile
RUN: llvm-bolt %t.exe -data %t.fdata -o %t.2 -reorder-blocks=cache
# The instrumented profile should at least say main was called once
CHECK: main 0 0 1{{$}}

View File

@ -0,0 +1,21 @@
# Check instrumentation of C++ code with exceptions
REQUIRES: system-linux
RUN: %clangxx %p/Inputs/exceptions_split.cpp -Wl,-q -g -o %t_exc_split
RUN: llvm-bolt %t_exc_split -o %t.exc -instrument -instrumentation-file=%t.fdata
RUN: %t.exc arg1 arg2 arg3
RUN: llvm-bolt %t_exc_split -o %t.exc.bolted -data %t.fdata \
RUN: -reorder-blocks=cache+ -reorder-functions=hfsort+ -split-functions=3 \
RUN: -split-eh=1 | FileCheck --check-prefix=EXCEPTIONS %s
EXCEPTIONS-NOT: invalid (possibly stale) profile
# Check that cold symbols are emitted with local binding.
RUN: llvm-readelf -Ws %t.exc.bolted | FileCheck %s --check-prefix=CHECK-READELF
CHECK-READELF: FUNC LOCAL DEFAULT {{.*}} main.cold.{{.*}}
RUN: cat %t.fdata | FileCheck --check-prefix=EXCEPTIONS-FDATA %s
# Check that the printf "catch" ran exactly 10 times
EXCEPTIONS-FDATA: 1 main 90 1 _Znwm@PLT 0 0 10

View File

@ -0,0 +1,9 @@
# Make sure BOLT correctly updates values based on function pointer.
RUN: %clang %p/Inputs/fptr.c -Wl,-q -o %t.exe
RUN: llvm-bolt %t.exe -o %t -lite=0
RUN: %t | FileCheck %s
CHECK: Global = 0x[[#%x,ADDR:]]
CHECK-NEXT: Local = 0x[[#ADDR]]
CHECK-NEXT: Local2 = 0x[[#ADDR]]