aboutsummaryrefslogtreecommitdiff
path: root/bolt/test
diff options
context:
space:
mode:
authorAmir Ayupov <aaupov@fb.com>2024-05-09 12:35:45 -0700
committerAmir Ayupov <aaupov@fb.com>2024-07-18 20:57:05 -0700
commit3023b15fb1ec00dbe6a1cb630236125f500978ef (patch)
tree37f6160efc3730e7c8909e55b5d5d871b90db858 /bolt/test
parent401d7bcabc0affc38a6e52ffad782eedf0a5ec5a (diff)
downloadllvm-3023b15fb1ec00dbe6a1cb630236125f500978ef.zip
llvm-3023b15fb1ec00dbe6a1cb630236125f500978ef.tar.gz
llvm-3023b15fb1ec00dbe6a1cb630236125f500978ef.tar.bz2
[BOLT] Support POSSIBLE_PIC_FIXED_BRANCH
Detect and support fixed PIC indirect jumps of the following form: ``` movslq En(%rip), %r1 leaq PIC_JUMP_TABLE(%rip), %r2 addq %r2, %r1 jmpq *%r1 ``` with PIC_JUMP_TABLE that looks like following: ``` JT: ---------- E1:| L1 - JT | |----------| E2:| L2 - JT | |----------| | | ...... En:| Ln - JT | ---------- ``` The code could be produced by compilers, see https://github.com/llvm/llvm-project/issues/91648. Test Plan: updated jump-table-fixed-ref-pic.test Reviewers: maksfb, ayermolo, dcci, rafaelauler Reviewed By: rafaelauler Pull Request: https://github.com/llvm/llvm-project/pull/91667
Diffstat (limited to 'bolt/test')
-rw-r--r--bolt/test/X86/Inputs/jump-table-fixed-ref-pic.s2
-rw-r--r--bolt/test/X86/jump-table-fixed-ref-pic.test12
2 files changed, 9 insertions, 5 deletions
diff --git a/bolt/test/X86/Inputs/jump-table-fixed-ref-pic.s b/bolt/test/X86/Inputs/jump-table-fixed-ref-pic.s
index 66629a4..6407964 100644
--- a/bolt/test/X86/Inputs/jump-table-fixed-ref-pic.s
+++ b/bolt/test/X86/Inputs/jump-table-fixed-ref-pic.s
@@ -6,7 +6,7 @@ main:
jae .L4
cmpq $0x1, %rdi
jne .L4
- mov .Ljt_pic+8(%rip), %rax
+ movslq .Ljt_pic+8(%rip), %rax
lea .Ljt_pic(%rip), %rdx
add %rdx, %rax
jmpq *%rax
diff --git a/bolt/test/X86/jump-table-fixed-ref-pic.test b/bolt/test/X86/jump-table-fixed-ref-pic.test
index c8b6eda..d215c56 100644
--- a/bolt/test/X86/jump-table-fixed-ref-pic.test
+++ b/bolt/test/X86/jump-table-fixed-ref-pic.test
@@ -1,9 +1,13 @@
## Verify that BOLT detects fixed destination of indirect jump for PIC
## case.
-XFAIL: *
-
RUN: %clang %cflags -no-pie %S/Inputs/jump-table-fixed-ref-pic.s -Wl,-q -o %t
-RUN: llvm-bolt %t --relocs -o %t.null 2>&1 | FileCheck %s
+RUN: llvm-bolt %t --relocs -o %t.null -print-cfg 2>&1 | FileCheck %s
+
+CHECK: BOLT-INFO: fixed PIC indirect branch detected in main {{.*}} the destination value is 0x[[#TGT:]]
+CHECK: Binary Function "main" after building cfg
-CHECK: BOLT-INFO: fixed indirect branch detected in main
+CHECK: movslq ".rodata/1"+8(%rip), %rax
+CHECK-NEXT: leaq ".rodata/1"(%rip), %rdx
+CHECK-NEXT: addq %rdx, %rax
+CHECK-NEXT: jmpq *%rax # UNKNOWN CONTROL FLOW