[llvm] [WIP][BOLT] Do not delete jumptable if it starts with the entry address (PR #178578)
Haibo Jiang via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 1 02:32:02 PST 2026
https://github.com/Jianghibo updated https://github.com/llvm/llvm-project/pull/178578
>From fe39bd575e0952cefde723f6034cae13872f3b89 Mon Sep 17 00:00:00 2001
From: jianghaibo <jianghaibo9 at huawei.com>
Date: Sun, 1 Feb 2026 18:11:33 +0800
Subject: [PATCH] [BOLT] Fix fixed pic handling in indirect jumps
Jump tables for fixed PIC indirect jumps are only
created in strict relocation mode.
And the jump table is not spurous when the entry
address of the relocation and the start address
of the jump table are equal.
---
bolt/lib/Core/BinaryFunction.cpp | 5 +++--
bolt/test/X86/Inputs/jump-table-fixed-ref-pic.s | 7 ++++++-
bolt/test/X86/jump-table-fixed-ref-pic.test | 5 +++++
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 255f3d734bdb4..5e20983a62cce 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -917,7 +917,7 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, unsigned Size,
if (BaseRegNum == BC.MRI->getProgramCounter())
ArrayStart += getAddress() + Offset + Size;
- if (FixedEntryLoadInstr) {
+ if (FixedEntryLoadInstr && BC.HasRelocations) {
assert(BranchType == IndirectBranchType::POSSIBLE_PIC_FIXED_BRANCH &&
"Invalid IndirectBranch type");
MCInst::iterator FixedEntryDispOperand =
@@ -942,7 +942,8 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, unsigned Size,
// Remove spurious JumpTable at EntryAddress caused by PIC reference from
// the load instruction.
- BC.deleteJumpTable(EntryAddress);
+ if (EntryAddress != ArrayStart)
+ BC.deleteJumpTable(EntryAddress);
// Replace FixedEntryDispExpr used in target address calculation with outer
// jump table reference.
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 6407964593e2d..576fcb90113e7 100644
--- a/bolt/test/X86/Inputs/jump-table-fixed-ref-pic.s
+++ b/bolt/test/X86/Inputs/jump-table-fixed-ref-pic.s
@@ -3,13 +3,18 @@
main:
.cfi_startproc
cmpq $0x3, %rdi
- jae .L4
+ jae .Ltmp
cmpq $0x1, %rdi
jne .L4
movslq .Ljt_pic+8(%rip), %rax
lea .Ljt_pic(%rip), %rdx
add %rdx, %rax
jmpq *%rax
+.Ltmp:
+ movslq .Ljt_pic(%rip), %rax
+ lea .Ljt_pic(%rip), %rdx
+ add %rdx, %rax
+ jmpq *%rax
.L1:
movq $0x1, %rax
jmp .L5
diff --git a/bolt/test/X86/jump-table-fixed-ref-pic.test b/bolt/test/X86/jump-table-fixed-ref-pic.test
index d215c565b31e5..df570da1fbe69 100644
--- a/bolt/test/X86/jump-table-fixed-ref-pic.test
+++ b/bolt/test/X86/jump-table-fixed-ref-pic.test
@@ -11,3 +11,8 @@ 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
+
+CHECK: movslq ".rodata/1"(%rip), %rax
+CHECK-NEXT: leaq ".rodata/1"(%rip), %rdx
+CHECK-NEXT: addq %rdx, %rax
+CHECK-NEXT: jmpq *%rax # UNKNOWN CONTROL FLOW
More information about the llvm-commits
mailing list