Skip to content

Commit 73a0144

Browse files
authored
[BOLT] Add test case for PIC fixed indirect jump (#91547)
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.
1 parent 62b5b61 commit 73a0144

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.globl main
2+
.type main, %function
3+
main:
4+
.cfi_startproc
5+
cmpq $0x3, %rdi
6+
jae .L4
7+
cmpq $0x1, %rdi
8+
jne .L4
9+
mov .Ljt_pic+8(%rip), %rax
10+
lea .Ljt_pic(%rip), %rdx
11+
add %rdx, %rax
12+
jmpq *%rax
13+
.L1:
14+
movq $0x1, %rax
15+
jmp .L5
16+
.L2:
17+
movq $0x0, %rax
18+
jmp .L5
19+
.L3:
20+
movq $0x2, %rax
21+
jmp .L5
22+
.L4:
23+
mov $0x3, %rax
24+
.L5:
25+
retq
26+
.cfi_endproc
27+
28+
.section .rodata
29+
.align 16
30+
.Ljt_pic:
31+
.long .L1 - .Ljt_pic
32+
.long .L2 - .Ljt_pic
33+
.long .L3 - .Ljt_pic
34+
.long .L4 - .Ljt_pic
35+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Verify that BOLT detects fixed destination of indirect jump for PIC
2+
# case.
3+
4+
XFAIL: *
5+
6+
RUN: %clang %cflags -no-pie %S/Inputs/jump-table-fixed-ref-pic.s -Wl,-q -o %t
7+
RUN: llvm-bolt %t --relocs -o %t.null 2>&1 | FileCheck %s
8+
9+
CHECK: BOLT-INFO: fixed indirect branch detected in main

0 commit comments

Comments
 (0)