diff options
Diffstat (limited to 'bolt/test')
-rw-r--r-- | bolt/test/AArch64/constant_island_pie_update.s | 6 | ||||
-rw-r--r-- | bolt/test/AArch64/ifunc.test (renamed from bolt/test/AArch64/ifunc.c) | 23 | ||||
-rw-r--r-- | bolt/test/AArch64/internal-call.s | 65 | ||||
-rw-r--r-- | bolt/test/AArch64/update-weak-reference-symbol.s | 2 | ||||
-rw-r--r-- | bolt/test/Inputs/ifunc.c | 12 | ||||
-rw-r--r-- | bolt/test/Inputs/iplt.ld (renamed from bolt/test/AArch64/Inputs/iplt.ld) | 0 | ||||
-rw-r--r-- | bolt/test/X86/ifunc.test | 47 | ||||
-rw-r--r-- | bolt/test/X86/log.test | 4 | ||||
-rw-r--r-- | bolt/test/X86/print-only-section.s | 29 | ||||
-rw-r--r-- | bolt/test/X86/pseudoprobe-decoding-inline.test | 36 | ||||
-rw-r--r-- | bolt/test/X86/pseudoprobe-decoding-noinline.test | 41 | ||||
-rw-r--r-- | bolt/test/X86/yaml-unknown-keys.test | 50 | ||||
-rw-r--r-- | bolt/test/lit.local.cfg | 4 | ||||
-rw-r--r-- | bolt/test/merge-fdata-uninitialized-header.test | 45 | ||||
-rw-r--r-- | bolt/test/perf2bolt/lit.local.cfg | 5 | ||||
-rw-r--r-- | bolt/test/perf2bolt/perf_test.test | 9 |
16 files changed, 326 insertions, 52 deletions
diff --git a/bolt/test/AArch64/constant_island_pie_update.s b/bolt/test/AArch64/constant_island_pie_update.s index 313e103..889f6b6 100644 --- a/bolt/test/AArch64/constant_island_pie_update.s +++ b/bolt/test/AArch64/constant_island_pie_update.s @@ -8,15 +8,15 @@ # RUN: %clang %cflags -fPIC -pie %t.o -o %t.rela.exe -nostdlib \ # RUN: -Wl,-q -Wl,-z,notext # RUN: llvm-bolt %t.rela.exe -o %t.rela.bolt --use-old-text=0 --lite=0 -# RUN: llvm-objdump -j .text -d --show-all-symbols %t.rela.bolt | FileCheck %s +# RUN: llvm-objdump -j .text -d -z --show-all-symbols %t.rela.bolt | FileCheck %s # RUN: llvm-readelf -rsW %t.rela.bolt | FileCheck --check-prefix=ELFCHECK %s // .relr.dyn # RUN: %clang %cflags -fPIC -pie %t.o -o %t.relr.exe -nostdlib \ # RUN: -Wl,-q -Wl,-z,notext -Wl,--pack-dyn-relocs=relr # RUN: llvm-objcopy --remove-section .rela.mytext %t.relr.exe # RUN: llvm-bolt %t.relr.exe -o %t.relr.bolt --use-old-text=0 --lite=0 -# RUN: llvm-objdump -j .text -d --show-all-symbols %t.relr.bolt | FileCheck %s -# RUN: llvm-objdump -j .text -d %t.relr.bolt | \ +# RUN: llvm-objdump -j .text -d -z --show-all-symbols %t.relr.bolt | FileCheck %s +# RUN: llvm-objdump -j .text -d -z %t.relr.bolt | \ # RUN: FileCheck %s --check-prefix=ADDENDCHECK # RUN: llvm-readelf -rsW %t.relr.bolt | FileCheck --check-prefix=RELRELFCHECK %s # RUN: llvm-readelf -SW %t.relr.bolt | FileCheck --check-prefix=RELRSZCHECK %s diff --git a/bolt/test/AArch64/ifunc.c b/bolt/test/AArch64/ifunc.test index 1744976..3da42c6 100644 --- a/bolt/test/AArch64/ifunc.c +++ b/bolt/test/AArch64/ifunc.test @@ -1,8 +1,6 @@ -// This test checks that IFUNC trampoline is properly recognised by BOLT - // With -O0 indirect call is performed on IPLT trampoline. IPLT trampoline // has IFUNC symbol. -// RUN: %clang %cflags -nostdlib -O0 -no-pie %s -fuse-ld=lld \ +// RUN: %clang %cflags -nostdlib -O0 -no-pie %p/../Inputs/ifunc.c -fuse-ld=lld \ // RUN: -o %t.O0.exe -Wl,-q // RUN: llvm-bolt %t.O0.exe -o %t.O0.bolt.exe \ // RUN: --print-disasm --print-only=_start | \ @@ -12,7 +10,7 @@ // Non-pie static executable doesn't generate PT_DYNAMIC, check relocation // is readed successfully and IPLT trampoline has been identified by bolt. -// RUN: %clang %cflags -nostdlib -O3 %s -fuse-ld=lld -no-pie \ +// RUN: %clang %cflags -nostdlib -O3 %p/../Inputs/ifunc.c -fuse-ld=lld -no-pie \ // RUN: -o %t.O3_nopie.exe -Wl,-q // RUN: llvm-readelf -l %t.O3_nopie.exe | \ // RUN: FileCheck --check-prefix=NON_DYN_CHECK %s @@ -25,7 +23,7 @@ // With -O3 direct call is performed on IPLT trampoline. IPLT trampoline // doesn't have associated symbol. The ifunc symbol has the same address as // IFUNC resolver function. -// RUN: %clang %cflags -nostdlib -O3 %s -fuse-ld=lld -fPIC -pie \ +// RUN: %clang %cflags -nostdlib -O3 %p/../Inputs/ifunc.c -fuse-ld=lld -fPIC -pie \ // RUN: -o %t.O3_pie.exe -Wl,-q // RUN: llvm-bolt %t.O3_pie.exe -o %t.O3_pie.bolt.exe \ // RUN: --print-disasm --print-only=_start | \ @@ -35,8 +33,8 @@ // Check that IPLT trampoline located in .plt section are normally handled by // BOLT. The gnu-ld linker doesn't use separate .iplt section. -// RUN: %clang %cflags -nostdlib -O3 %s -fuse-ld=lld -fPIC -pie \ -// RUN: -T %p/Inputs/iplt.ld -o %t.iplt_O3_pie.exe -Wl,-q +// RUN: %clang %cflags -nostdlib -O3 %p/../Inputs/ifunc.c -fuse-ld=lld -fPIC -pie \ +// RUN: -T %p/../Inputs/iplt.ld -o %t.iplt_O3_pie.exe -Wl,-q // RUN: llvm-bolt %t.iplt_O3_pie.exe -o %t.iplt_O3_pie.bolt.exe \ // RUN: --print-disasm --print-only=_start | \ // RUN: FileCheck --check-prefix=CHECK %s @@ -49,14 +47,3 @@ // REL_CHECK: R_AARCH64_IRELATIVE [[#%x,REL_SYMB_ADDR:]] // REL_CHECK: [[#REL_SYMB_ADDR]] {{.*}} FUNC {{.*}} resolver_foo - -static void foo() {} -static void bar() {} - -extern int use_foo; - -static void *resolver_foo(void) { return use_foo ? foo : bar; } - -__attribute__((ifunc("resolver_foo"))) void ifoo(); - -void _start() { ifoo(); } diff --git a/bolt/test/AArch64/internal-call.s b/bolt/test/AArch64/internal-call.s new file mode 100644 index 0000000..43b3a64 --- /dev/null +++ b/bolt/test/AArch64/internal-call.s @@ -0,0 +1,65 @@ +## Test that llvm-bolt detects internal calls and marks the containing function +## as non-simple. + +# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o +# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -static +# RUN: llvm-bolt %t.exe -o %t.null --print-all 2>&1 | FileCheck %s + +# CHECK: Binary Function "_start" after building cfg +# CHECK: internal call detected in function _start +# CHECK-NOT: Binary Function "_start" after validate-internal-calls + + .text + .globl _start + .type _start, %function +_start: + .cfi_startproc +.LBB00: + mov x11, #0x1fff + cmp x1, x11 + b.hi .Ltmp1 + +.entry1: + movi v4.16b, #0x0 + movi v5.16b, #0x0 + subs x1, x1, #0x8 + b.lo .Ltmp2 + +.entry2: + ld1 { v2.2d, v3.2d }, [x0], #32 + ld1 { v0.2d, v1.2d }, [x0], #32 + +.Ltmp2: + uaddlp v4.4s, v4.8h + uaddlp v4.2d, v4.4s + mov x0, v4.d[0] + mov x1, v4.d[1] + add x0, x0, x1 + ret x30 + +.Ltmp1: + mov x8, x30 + +.Lloop: + add x5, x0, x9 + mov x1, #0xface + movi v4.16b, #0x0 + movi v5.16b, #0x0 + bl .entry2 + add x4, x4, x0 + mov x0, x5 + sub x7, x7, x10 + cmp x7, x11 + b.hi .Lloop + + mov x1, x7 + bl .entry1 + add x0, x4, x0 + mov x30, x8 + ret x30 + + .cfi_endproc +.size _start, .-_start + +## Force relocation mode. + .reloc 0, R_AARCH64_NONE diff --git a/bolt/test/AArch64/update-weak-reference-symbol.s b/bolt/test/AArch64/update-weak-reference-symbol.s index 600a06b8..46819e8 100644 --- a/bolt/test/AArch64/update-weak-reference-symbol.s +++ b/bolt/test/AArch64/update-weak-reference-symbol.s @@ -3,7 +3,7 @@ // RUN: %clang %cflags -Wl,-z,notext -shared -Wl,-q %s -o %t.so // RUN: llvm-bolt %t.so -o %t.so.bolt // RUN: llvm-nm -n %t.so.bolt > %t.out.txt -// RUN: llvm-objdump -dj .rodata %t.so.bolt >> %t.out.txt +// RUN: llvm-objdump -z -dj .rodata %t.so.bolt >> %t.out.txt // RUN: FileCheck %s --input-file=%t.out.txt # CHECK: w func_1 diff --git a/bolt/test/Inputs/ifunc.c b/bolt/test/Inputs/ifunc.c new file mode 100644 index 0000000..3fa62be --- /dev/null +++ b/bolt/test/Inputs/ifunc.c @@ -0,0 +1,12 @@ +// This test checks that IFUNC trampoline is properly recognised by BOLT + +static void foo() {} +static void bar() {} + +extern int use_foo; + +static void *resolver_foo(void) { return use_foo ? foo : bar; } + +__attribute__((ifunc("resolver_foo"))) void ifoo(); + +void _start() { ifoo(); } diff --git a/bolt/test/AArch64/Inputs/iplt.ld b/bolt/test/Inputs/iplt.ld index 1e54a24..1e54a24 100644 --- a/bolt/test/AArch64/Inputs/iplt.ld +++ b/bolt/test/Inputs/iplt.ld diff --git a/bolt/test/X86/ifunc.test b/bolt/test/X86/ifunc.test new file mode 100644 index 0000000..befefbe --- /dev/null +++ b/bolt/test/X86/ifunc.test @@ -0,0 +1,47 @@ +// Check if BOLT can process ifunc symbols from .plt section +// RUN: %clang %cflags -nostdlib -no-pie %p/../Inputs/ifunc.c -fuse-ld=lld \ +// RUN: -o %t.exe -Wl,-q +// RUN: llvm-bolt %t.exe -o %t.bolt.exe \ +// RUN: --print-disasm --print-only=_start | \ +// RUN: FileCheck --check-prefix=CHECK %s +// RUN: llvm-readelf -aW %t.bolt.exe | \ +// RUN: FileCheck --check-prefix=REL_CHECK %s + +// Check if BOLT can process ifunc symbols from .plt section in non-pie static +// executable case. +// RUN: %clang %cflags -nostdlib %p/../Inputs/ifunc.c -fuse-ld=lld -no-pie \ +// RUN: -o %t.nopie.exe -Wl,-q +// RUN: llvm-readelf -l %t.nopie.exe | \ +// RUN: FileCheck --check-prefix=NON_DYN_CHECK %s +// RUN: llvm-bolt %t.nopie.exe -o %t.nopie.bolt.exe \ +// RUN: --print-disasm --print-only=_start | \ +// RUN: FileCheck --check-prefix=CHECK %s +// RUN: llvm-readelf -aW %t.nopie.bolt.exe | \ +// RUN: FileCheck --check-prefix=REL_CHECK %s + +// Check if BOLT can process ifunc symbols from .plt section in pie executable +// case. +// RUN: %clang %cflags -nostdlib %p/../Inputs/ifunc.c -fuse-ld=lld -fPIC -pie \ +// RUN: -o %t.pie.exe -Wl,-q +// RUN: llvm-bolt %t.pie.exe -o %t.pie.bolt.exe \ +// RUN: --print-disasm --print-only=_start | \ +// RUN: FileCheck --check-prefix=CHECK %s +// RUN: llvm-readelf -aW %t.pie.bolt.exe | \ +// RUN: FileCheck --check-prefix=REL_CHECK %s + +// Check that IPLT trampoline located in .plt section are normally handled by +// BOLT. The gnu-ld linker doesn't use separate .iplt section. +// RUN: %clang %cflags -nostdlib %p/../Inputs/ifunc.c -fuse-ld=lld -fPIC -pie \ +// RUN: -T %p/../Inputs/iplt.ld -o %t.iplt_pie.exe -Wl,-q +// RUN: llvm-bolt %t.iplt_pie.exe -o %t.iplt_pie.bolt.exe \ +// RUN: --print-disasm --print-only=_start | \ +// RUN: FileCheck --check-prefix=CHECK %s +// RUN: llvm-readelf -aW %t.iplt_pie.bolt.exe | \ +// RUN: FileCheck --check-prefix=REL_CHECK %s + +// NON_DYN_CHECK-NOT: DYNAMIC + +// CHECK: callq "resolver_foo/1@PLT" + +// REL_CHECK: R_X86_64_IRELATIVE [[#%x,REL_SYMB_ADDR:]] +// REL_CHECK: [[#REL_SYMB_ADDR]] {{.*}} FUNC {{.*}} resolver_foo diff --git a/bolt/test/X86/log.test b/bolt/test/X86/log.test index 42109db..2c006e9 100644 --- a/bolt/test/X86/log.test +++ b/bolt/test/X86/log.test @@ -6,7 +6,7 @@ RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe RUN: llvm-bolt %t.exe -o %t.null --data %p/Inputs/blarge.fdata -v=2 \ RUN: --reorder-blocks=normal --print-finalized --log-file=%t.log 2>&1 \ RUN: | FileCheck --check-prefix=CHECK --allow-empty %s -RUN: cat %t.log | FileCheck %s --check-prefix=CHECK-LOG +RUN: FileCheck %s --check-prefix=CHECK-LOG --input-file %t.log CHECK-NOT: BOLT-INFO CHECK-NOT: BOLT-WARNING @@ -16,4 +16,4 @@ CHECK-NOT: BOLT-ERROR CHECK-LOG: BOLT-INFO: Target architecture CHECK-LOG: BOLT-INFO: BOLT version CHECK-LOG: BOLT-INFO: basic block reordering modified layout -CHECK-LOG: Binary Function "usqrt" +CHECK-LOG: Binary Function "main" diff --git a/bolt/test/X86/print-only-section.s b/bolt/test/X86/print-only-section.s new file mode 100644 index 0000000..d580818 --- /dev/null +++ b/bolt/test/X86/print-only-section.s @@ -0,0 +1,29 @@ +## Check that --print-only flag works with sections. + +# REQUIRES: system-linux + +# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t.exe +# RUN: llvm-bolt %t.exe -o %t.out --print-cfg --print-only=unused_code 2>&1 \ +# RUN: | FileCheck %s + +# CHECK: Binary Function "foo" +# CHECK-NOT: Binary Function "_start" + + .text + .globl _start + .type _start, %function +_start: + .cfi_startproc + ret + .cfi_endproc + .size _start, .-_start + + .section unused_code,"ax",@progbits + .globl foo + .type foo, %function +foo: + .cfi_startproc + ret + .cfi_endproc + .size foo, .-foo diff --git a/bolt/test/X86/pseudoprobe-decoding-inline.test b/bolt/test/X86/pseudoprobe-decoding-inline.test index b361551..e5e8aad 100644 --- a/bolt/test/X86/pseudoprobe-decoding-inline.test +++ b/bolt/test/X86/pseudoprobe-decoding-inline.test @@ -6,37 +6,39 @@ # PREAGG: B X:0 #main# 1 0 ## Check pseudo-probes in regular YAML profile (non-BOLTed binary) # RUN: link_fdata %s %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin %t.preagg PREAGG -# RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml -o %t.fdata --profile-use-pseudo-probes +# RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml -o %t.fdata --profile-write-pseudo-probes # RUN: FileCheck --input-file %t.yaml %s --check-prefix CHECK-YAML ## Check pseudo-probes in BAT YAML profile (BOLTed binary) # RUN: link_fdata %s %t.bolt %t.preagg2 PREAGG -# RUN: perf2bolt %t.bolt -p %t.preagg2 --pa -w %t.yaml2 -o %t.fdata2 --profile-use-pseudo-probes +# RUN: perf2bolt %t.bolt -p %t.preagg2 --pa -w %t.yaml2 -o %t.fdata2 --profile-write-pseudo-probes # RUN: FileCheck --input-file %t.yaml2 %s --check-prefix CHECK-YAML # CHECK-YAML: name: bar # CHECK-YAML: - bid: 0 -# CHECK-YAML: pseudo_probes: [ { guid: 0xE413754A191DB537, id: 1, type: 0 }, { guid: 0xE413754A191DB537, id: 4, type: 0 } ] -# CHECK-YAML: guid: 0xE413754A191DB537 -# CHECK-YAML: pseudo_probe_desc_hash: 0x10E852DA94 +# CHECK-YAML: probes: [ { blx: 9 } ] +# CHECK-YAML: inline_tree: [ { } ] # # CHECK-YAML: name: foo # CHECK-YAML: - bid: 0 -# CHECK-YAML: pseudo_probes: [ { guid: 0x5CF8C24CDB18BDAC, id: 1, type: 0 }, { guid: 0x5CF8C24CDB18BDAC, id: 2, type: 0 } ] -# CHECK-YAML: guid: 0x5CF8C24CDB18BDAC -# CHECK-YAML: pseudo_probe_desc_hash: 0x200205A19C5B4 +# CHECK-YAML: probes: [ { blx: 3 } ] +# CHECK-YAML: inline_tree: [ { g: 1 }, { g: 0, cs: 8 } ] # # CHECK-YAML: name: main # CHECK-YAML: - bid: 0 -# CHECK-YAML: pseudo_probes: [ { guid: 0xDB956436E78DD5FA, id: 1, type: 0 }, { guid: 0x5CF8C24CDB18BDAC, id: 1, type: 0 }, { guid: 0x5CF8C24CDB18BDAC, id: 2, type: 0 } ] -# CHECK-YAML: guid: 0xDB956436E78DD5FA -# CHECK-YAML: pseudo_probe_desc_hash: 0x10000FFFFFFFF +# CHECK-YAML: probes: [ { blx: 3, id: 1 }, { blx: 1 } ] +# CHECK-YAML: inline_tree: [ { g: 2 }, { g: 1, cs: 2 }, { g: 0, p: 1, cs: 8 } ] # -## Check that without --profile-use-pseudo-probes option, no pseudo probes are +# CHECK-YAML: pseudo_probe_desc: +# CHECK-YAML-NEXT: gs: [ 0xE413754A191DB537, 0x5CF8C24CDB18BDAC, 0xDB956436E78DD5FA ] +# CHECK-YAML-NEXT: gh: [ 2, 0, 1 ] +# CHECK-YAML-NEXT: hs: [ 0x200205A19C5B4, 0x10000FFFFFFFF, 0x10E852DA94 ] +# +## Check that without --profile-write-pseudo-probes option, no pseudo probes are ## generated -# RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml -o %t.fdata -# RUN: FileCheck --input-file %t.yaml %s --check-prefix CHECK-NO-OPT -# CHECK-NO-OPT-NOT: pseudo_probes -# CHECK-NO-OPT-NOT: guid -# CHECK-NO-OPT-NOT: pseudo_probe_desc_hash +# RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml3 -o %t.fdata +# RUN: FileCheck --input-file %t.yaml3 %s --check-prefix CHECK-NO-OPT +# CHECK-NO-OPT-NOT: probes: +# CHECK-NO-OPT-NOT: inline_tree: +# CHECK-NO-OPT-NOT: pseudo_probe_desc: CHECK: Report of decoding input pseudo probe binaries diff --git a/bolt/test/X86/pseudoprobe-decoding-noinline.test b/bolt/test/X86/pseudoprobe-decoding-noinline.test index 5dd6c2e..36a2fab 100644 --- a/bolt/test/X86/pseudoprobe-decoding-noinline.test +++ b/bolt/test/X86/pseudoprobe-decoding-noinline.test @@ -1,6 +1,45 @@ # REQUIRES: system-linux -# RUN: llvm-bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/noinline-cs-pseudoprobe.perfbin --print-pseudo-probes=all -o %t.bolt 2>&1 | FileCheck %s +# RUN: llvm-bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/noinline-cs-pseudoprobe.perfbin --print-pseudo-probes=all -o %t.bolt --lite=0 --enable-bat 2>&1 | FileCheck %s +# PREAGG: B X:0 #foo# 1 0 +# PREAGG: B X:0 #bar# 1 0 +# PREAGG: B X:0 #main# 1 0 + +## Check pseudo-probes in regular YAML profile (non-BOLTed binary) +# RUN: link_fdata %s %S/../../../llvm/test/tools/llvm-profgen/Inputs/noinline-cs-pseudoprobe.perfbin %t.preagg PREAGG +# RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/noinline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml -o %t.fdata --profile-write-pseudo-probes +# RUN: FileCheck --input-file %t.yaml %s --check-prefix CHECK-YAML +## Check pseudo-probes in BAT YAML profile (BOLTed binary) +# RUN: link_fdata %s %t.bolt %t.preagg2 PREAGG +# RUN: perf2bolt %t.bolt -p %t.preagg2 --pa -w %t.yaml2 -o %t.fdata2 --profile-write-pseudo-probes +# RUN: FileCheck --input-file %t.yaml2 %s --check-prefix CHECK-YAML +# CHECK-YAML: name: bar +# CHECK-YAML: - bid: 0 +# CHECK-YAML: probes: [ { blx: 9 } ] +# CHECK-YAML: inline_tree: [ { } ] +# +# CHECK-YAML: name: foo +# CHECK-YAML: - bid: 0 +# CHECK-YAML: probes: [ { blx: 3 } ] +# CHECK-YAML: inline_tree: [ { g: 2 } ] +# +# CHECK-YAML: name: main +# CHECK-YAML: - bid: 0 +# CHECK-YAML: probes: [ { blx: 1, call: [ 2 ] } ] +# CHECK-YAML: inline_tree: [ { g: 1 } ] +# +# CHECK-YAML: pseudo_probe_desc: +# CHECK-YAML-NEXT: gs: [ 0xE413754A191DB537, 0xDB956436E78DD5FA, 0x5CF8C24CDB18BDAC ] +# CHECK-YAML-NEXT: gh: [ 2, 1, 0 ] +# CHECK-YAML-NEXT: hs: [ 0x200205A19C5B4, 0x10000FFFFFFFF, 0x10E852DA94 ] +# +## Check that without --profile-write-pseudo-probes option, no pseudo probes are +## generated +# RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/noinline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml3 -o %t.fdata +# RUN: FileCheck --input-file %t.yaml3 %s --check-prefix CHECK-NO-OPT +# CHECK-NO-OPT-NOT: probes: +# CHECK-NO-OPT-NOT: inline_tree: +# CHECK-NO-OPT-NOT: pseudo_probe_desc: ;; Report of decoding input pseudo probe binaries ; CHECK: GUID: 6699318081062747564 Name: foo diff --git a/bolt/test/X86/yaml-unknown-keys.test b/bolt/test/X86/yaml-unknown-keys.test new file mode 100644 index 0000000..cbcf9a4 --- /dev/null +++ b/bolt/test/X86/yaml-unknown-keys.test @@ -0,0 +1,50 @@ +## Test that BOLT gracefully handles a YAML profile with unknown keys. + +# REQUIRES: system-linux +# RUN: split-file %s %t +# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %t/main.s -o %t.o +# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -nostdlib +# RUN: llvm-bolt %t.exe -o %t.null --data %t/profile.yaml \ +# RUN: --profile-ignore-hash -v=1 2>&1 | FileCheck %s +# CHECK: warning: unknown key 'unknown-header-key' +# CHECK: warning: unknown key 'unknown_succ_key' +# CHECK: warning: unknown key 'unknown_block_key' +# CHECK: warning: unknown key 'unknown_function_key' +# CHECK: warning: unknown key 'unknown_toplev_key' +#--- main.s + .globl main + .type main, %function +main: + .cfi_startproc + cmpl $0x0, %eax + jne .LBB0 +.LBB0: + retq + .cfi_endproc +.size main, .-main +#--- profile.yaml +--- +header: + profile-version: 1 + binary-name: 'yaml-multiple-profiles.test.tmp.exe' + binary-build-id: '<unknown>' + profile-flags: [ lbr ] + profile-origin: branch profile reader + profile-events: '' + dfs-order: false + unknown-header-key: true +functions: + - name: 'main' + fid: 1 + hash: 0x50BBA3441D436491 + exec: 1 + nblocks: 1 + blocks: + - bid: 0 + insns: 2 + hash: 0x4D4D8FAF7D4C0000 + succ: [ { bid: 1, cnt: 0, unknown_succ_key: 0x10 } ] + unknown_block_key: [ ] + unknown_function_key: 1 +unknown_toplev_key: '' +... diff --git a/bolt/test/lit.local.cfg b/bolt/test/lit.local.cfg index 8aa5f15..e2fa0a4 100644 --- a/bolt/test/lit.local.cfg +++ b/bolt/test/lit.local.cfg @@ -1,6 +1,6 @@ host_linux_triple = config.target_triple.split("-")[0] + "-unknown-linux-gnu" -common_linker_flags = "-fuse-ld=lld -Wl,--unresolved-symbols=ignore-all" -flags = f"--target={host_linux_triple} {common_linker_flags}" +common_linker_flags = "-fuse-ld=lld -Wl,--unresolved-symbols=ignore-all -pie" +flags = f"--target={host_linux_triple} -fPIE {common_linker_flags}" config.substitutions.insert(0, ("%cflags", f"%cflags {flags}")) config.substitutions.insert(0, ("%cxxflags", f"%cxxflags {flags}")) diff --git a/bolt/test/merge-fdata-uninitialized-header.test b/bolt/test/merge-fdata-uninitialized-header.test new file mode 100644 index 0000000..5336961 --- /dev/null +++ b/bolt/test/merge-fdata-uninitialized-header.test @@ -0,0 +1,45 @@ +## Test that merge-fdata correctly handles YAML header with an uninitialized +## fields. a.yaml does not have hash-func set and it used to crash merge-fdata. + +# REQUIRES: system-linux + +# RUN: split-file %s %t +# RUN: not merge-fdata %t/a.yaml %t/b.yaml 2>&1 | FileCheck %s + +# CHECK: cannot merge profiles with different hash functions + +#--- a.yaml +--- +header: + profile-version: 1 + binary-name: 'a.out' + binary-build-id: '<unknown>' + profile-flags: [ lbr ] + profile-origin: branch profile reader + profile-events: '' + dfs-order: false +functions: + - name: 'main' + fid: 1 + hash: 0x50BBA3441D436491 + exec: 1 + nblocks: 0 +... +#--- b.yaml +--- +header: + profile-version: 1 + binary-name: 'a.out' + binary-build-id: '<unknown>' + profile-flags: [ lbr ] + profile-origin: branch profile reader + profile-events: '' + dfs-order: false + hash-func: xxh3 +functions: + - name: 'main' + fid: 1 + hash: 0x50BBA3441D436491 + exec: 1 + nblocks: 0 +... diff --git a/bolt/test/perf2bolt/lit.local.cfg b/bolt/test/perf2bolt/lit.local.cfg index 4ee9ad0..0fecf91 100644 --- a/bolt/test/perf2bolt/lit.local.cfg +++ b/bolt/test/perf2bolt/lit.local.cfg @@ -1,4 +1,5 @@ import shutil +import subprocess -if shutil.which("perf") is not None: - config.available_features.add("perf")
\ No newline at end of file +if shutil.which("perf") is not None and subprocess.run(["perf", "record", "-e", "cycles:u", "-o", "/dev/null", "--", "perf", "--version"], capture_output=True).returncode == 0: + config.available_features.add("perf") diff --git a/bolt/test/perf2bolt/perf_test.test b/bolt/test/perf2bolt/perf_test.test index 44db899..7bec442 100644 --- a/bolt/test/perf2bolt/perf_test.test +++ b/bolt/test/perf2bolt/perf_test.test @@ -3,15 +3,12 @@ REQUIRES: system-linux, perf RUN: %clang %S/Inputs/perf_test.c -fuse-ld=lld -Wl,--script=%S/Inputs/perf_test.lds -o %t -RUN: perf record -e cycles:u -o %t2 -- %t +RUN: perf record -Fmax -e cycles:u -o %t2 -- %t RUN: perf2bolt %t -p=%t2 -o %t3 -nl -ignore-build-id 2>&1 | FileCheck %s CHECK-NOT: PERF2BOLT-ERROR CHECK-NOT: !! WARNING !! This high mismatch ratio indicates the input binary is probably not the same binary used during profiling collection. RUN: %clang %S/Inputs/perf_test.c -no-pie -fuse-ld=lld -o %t4 -RUN: perf record -e cycles:u -o %t5 -- %t4 -RUN: perf2bolt %t4 -p=%t5 -o %t6 -nl -ignore-build-id 2>&1 | FileCheck %s --check-prefix=CHECK-NO-PIE - -CHECK-NO-PIE-NOT: PERF2BOLT-ERROR -CHECK-NO-PIE-NOT: !! WARNING !! This high mismatch ratio indicates the input binary is probably not the same binary used during profiling collection.
\ No newline at end of file +RUN: perf record -Fmax -e cycles:u -o %t5 -- %t4 +RUN: perf2bolt %t4 -p=%t5 -o %t6 -nl -ignore-build-id 2>&1 | FileCheck %s |