[llvm] [BOLT] Add test case for PIC fixed indirect jump (PR #91547)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 17:49:55 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-bolt
Author: Maksim Panchenko (maksfb)
<details>
<summary>Changes</summary>
A compiler can generate a redundant indirection for a jump via a fixed jump table target. Add a test case that covers such pattern that covers PIC case. We already have non-PIC case detection.
Currently XFAIL.
---
Full diff: https://github.com/llvm/llvm-project/pull/91547.diff
2 Files Affected:
- (added) bolt/test/X86/Inputs/jump-table-fixed-ref-pic.s (+35)
- (added) bolt/test/X86/jump-table-fixed-ref-pic.test (+9)
``````````diff
diff --git a/bolt/test/X86/Inputs/jump-table-fixed-ref-pic.s b/bolt/test/X86/Inputs/jump-table-fixed-ref-pic.s
new file mode 100644
index 0000000000000..66629a4880e64
--- /dev/null
+++ b/bolt/test/X86/Inputs/jump-table-fixed-ref-pic.s
@@ -0,0 +1,35 @@
+ .globl main
+ .type main, %function
+main:
+ .cfi_startproc
+ cmpq $0x3, %rdi
+ jae .L4
+ cmpq $0x1, %rdi
+ jne .L4
+ mov .Ljt_pic+8(%rip), %rax
+ lea .Ljt_pic(%rip), %rdx
+ add %rdx, %rax
+ jmpq *%rax
+.L1:
+ movq $0x1, %rax
+ jmp .L5
+.L2:
+ movq $0x0, %rax
+ jmp .L5
+.L3:
+ movq $0x2, %rax
+ jmp .L5
+.L4:
+ mov $0x3, %rax
+.L5:
+ retq
+ .cfi_endproc
+
+ .section .rodata
+ .align 16
+.Ljt_pic:
+ .long .L1 - .Ljt_pic
+ .long .L2 - .Ljt_pic
+ .long .L3 - .Ljt_pic
+ .long .L4 - .Ljt_pic
+
diff --git a/bolt/test/X86/jump-table-fixed-ref-pic.test b/bolt/test/X86/jump-table-fixed-ref-pic.test
new file mode 100644
index 0000000000000..4195b97aac501
--- /dev/null
+++ b/bolt/test/X86/jump-table-fixed-ref-pic.test
@@ -0,0 +1,9 @@
+# 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
+
+CHECK: BOLT-INFO: fixed indirect branch detected in main
``````````
</details>
https://github.com/llvm/llvm-project/pull/91547
More information about the llvm-commits
mailing list