Skip to content

Commit 00755b3

Browse files
committed
Merge branch 'users/huangjinjie/bolt_validata_branch_target' of https://github.com/Jinjie-Huang/llvm-project into users/huangjinjie/bolt_validata_branch_target
2 parents 5bfce8b + 5265b33 commit 00755b3

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

bolt/test/AArch64/constant-island-alignment.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ _start:
5353
blr x0
5454
mov x0, #1
5555
ret
56+
.size _start,.-_start
5657
nop
5758
# CHECK: {{0|8}} <$d>:
5859
.Lci:
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Test that BOLT errs when detecting the target
2+
## of a direct call/branch is a invalid instruction
3+
4+
# REQUIRES: system-linux
5+
# RUN: rm -rf %t && mkdir -p %t && cd %t
6+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-linux %s -o main.o
7+
# RUN: %clang %cflags %t/main.o -o main.exe -Wl,-q
8+
# RUN: llvm-bolt %t/main.exe -o %t/main.exe.bolt -lite=0 2>&1 | FileCheck %s --check-prefix=CHECK-TARGETS
9+
10+
# CHECK-TARGETS: BOLT-WARNING: corrupted control flow detected in function external_corrupt, an external branch/call targets an invalid instruction at address 0x{{[0-9a-f]+}}
11+
# CHECK-TARGETS: BOLT-WARNING: corrupted control flow detected in function internal_corrupt, an internal branch/call targets an invalid instruction at address 0x{{[0-9a-f]+}}
12+
13+
14+
.globl internal_corrupt
15+
.type internal_corrupt,@function
16+
internal_corrupt:
17+
ret
18+
nop
19+
.Lfake_branch_1:
20+
.inst 0x14000001 // Opcode 0x14=b, check for internal branch: b + 0x4
21+
.Lgarbage_1:
22+
.word 0xffffffff
23+
.size internal_corrupt,.-internal_corrupt
24+
25+
26+
.globl external_corrupt
27+
.type external_corrupt,@function
28+
external_corrupt:
29+
ret
30+
nop
31+
.Lfake_branch_2:
32+
.inst 0x14000004 // Opcode 0x14=b, check for external branch: b + 0xf
33+
.size external_corrupt,.-external_corrupt

bolt/test/X86/validate-branch-target.s

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
# RUN: %clang %cflags -pie -Wl,-q %t/main.o -o main.exe
88
# RUN: llvm-bolt %t/main.exe -o %t/main.exe.bolt -lite=0 2>&1 | FileCheck %s --check-prefix=CHECK-TARGETS
99

10-
# CHECK-TARGETS: BOLT-WARNING: corrupted control flow detected in function external_corrcupt, an external branch/call targets an invalid instruction at address 0x{{[0-9a-f]+}}
11-
# CHECK-TARGETS: BOLT-WARNING: corrupted control flow detected in function internal_corrcupt, an internal branch/call targets an invalid instruction at address 0x{{[0-9a-f]+}}
10+
# CHECK-TARGETS: BOLT-WARNING: corrupted control flow detected in function external_corrupt, an external branch/call targets an invalid instruction at address 0x{{[0-9a-f]+}}
11+
# CHECK-TARGETS: BOLT-WARNING: corrupted control flow detected in function internal_corrupt, an internal branch/call targets an invalid instruction at address 0x{{[0-9a-f]+}}
1212

1313

14-
.globl internal_corrcupt
15-
.type internal_corrcupt,@function
14+
.globl internal_corrupt
15+
.type internal_corrupt,@function
1616
.align 16
17-
internal_corrcupt:
17+
internal_corrupt:
1818
leaq .Lopts_1(%rip),%rax
1919
addq $25,%rax
2020
.byte 0xf3,0xc3
@@ -26,13 +26,13 @@ internal_corrcupt:
2626
.Lopts_1:
2727
.byte 114,1,52,40,56,120,44,105,110,116,41,0 # data '114' will be disassembled as 'jb', check for internal branch: jb + 0x1
2828
.align 64
29-
.size internal_corrcupt,.-internal_corrcupt
29+
.size internal_corrupt,.-internal_corrupt
3030

3131

32-
.globl external_corrcupt
33-
.type external_corrcupt,@function
32+
.globl external_corrupt
33+
.type external_corrupt,@function
3434
.align 16
35-
external_corrcupt:
35+
external_corrupt:
3636
leaq .Lopts_2(%rip),%rax
3737
addq $25,%rax
3838
.byte 0xf3,0xc3
@@ -44,4 +44,4 @@ external_corrcupt:
4444
.Lopts_2:
4545
.byte 114,99,52,40,56,120,44,99,104,97,114,41,0 # data '114' will be disassembled as 'jb', check for external branch: jb + 0x63
4646
.align 64
47-
.size external_corrcupt,.-external_corrcupt
47+
.size external_corrupt,.-external_corrupt

0 commit comments

Comments
 (0)