[llvm] [BOLT] Avoid reference updates for non-JT symbol operands (PR #88838)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 29 11:18:40 PDT 2024


linsinan1995 wrote:

@maksfb , One thing I am not very sure about is the `IsLegitAccess` check in this pass. I think it is possible to have a case like bolt/test/runtime/X86/jt-symbol-disambiguation.s, but when both `.end_of_table` and JT are in the same function, BOLT will generate the wrong code again.

like
```

  .text
  .globl _start
  .type _start, @function
_start:
  .cfi_startproc
  movq   (%rsp), %rdi
  xor    %rax,%rax
  and    $0x3,%rdi
  leaq   .JT1(%rip), %rax
  movslq  (%rax, %rdi, 4), %rdi
  addq   %rax, %rdi
  jmpq   *%rdi
.LBB1:
  movl   $0x1,%eax
  jmp    .LBB5
.LBB2:
  movl   $0x2,%eax
  jmp    .LBB5
.LBB3:
  movl   $0x3,%eax
  jmp    .LBB5
.LBB4:
  movl   $0x4,%eax
.LBB5:
  leaq   .start_of_table(%rip), %rsi  # iterator
  leaq   .end_of_table(%rip), %rdi    # iterator end
.LBB6:
  cmpq %rsi, %rdi
  je .LBB7
  movq (%rsi), %rbx
  leaq 8(%rsi), %rsi            # ++iterator
  jmp .LBB6
.LBB7:
  xor   %rdi, %rdi
  callq exit at PLT
  .cfi_endproc
  .size _start, .-_start

# ----
# Data section
# ----
  .section .rodata,"a", at progbits
  .p2align 3
.start_of_table:
  .quad 123
  .quad 456
  .quad 789
.end_of_table:
.JT1:
  .long .LBB1 - .JT1
  .long .LBB2 - .JT1
  .long .LBB3 - .JT1
  .long .LBB4 - .JT1
```

We may need more checks for such addresses overlapping cases in BOLT. at least more warnings in the future?

https://github.com/llvm/llvm-project/pull/88838


More information about the llvm-commits mailing list