[llvm] [BOLT] Avoid reference updates for non-JT symbol operands (PR #88838)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 15 20:58:15 PDT 2024
linsinan1995 wrote:
pass validate-memrefs wrongly update the correct reference to the jump table reference, which leads to a different execution result.
(a.out is compiled from jt-symbol-disambiguation-4.s attached in this PR)
```
+ ./a.out
FF
+ ./llvm-bolt -v=2 -jump-tables=move a.out -o a.out-opt
+ ./a.out-opt
5FFC00E
+ ./llvm-bolt -v=2 a.out -o a.out-opt-nomove
+ ./a.out-opt-nomove
FF
```
a.out
```
0000000000401160 <foo>:
401160: 48 c7 c0 00 00 00 00 mov $0x0,%rax
401167: ff 24 c5 18 20 40 00 jmpq *0x402018(,%rax,8) // JT label address 0x402018
40116a: R_X86_64_32S .rodata+0x18
...
0000000000401130 <main>:
401130: 48 c7 c0 f0 ff ff ff mov $0xfffffffffffffff0,%rax
401137: 8b 90 19 20 40 00 mov 0x402019(%rax),%edx // var `c` address 0x402008
401139: R_X86_64_32S c+0x11
40113d: 89 d6 mov %edx,%esi
0000000000402008 <c>:
402008: 01 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
402018: 71 11 40 00 00 00 00 00 71 11 40 00 00 00 00 00 q. at .....q.@.....
...
```
a.out-opt
```
0000000000800122 <foo>:
800122: 48 c7 c0 00 00 00 00 mov $0x0,%rax
800129: ff 24 c5 20 03 80 00 jmpq *0x800320(,%rax,8) # JT label address 0x800320
...
0000000000800100 <main>:
800100: 48 c7 c0 f0 ff ff ff mov $0xfffffffffffffff0,%rax
800107: 8b 90 21 03 80 00 mov 0x800321(%rax),%edx
80010d: 89 d6 mov %edx,%esi
0000000000800320 <.rodata.cold>:
800320: 30 01 xor %al,(%rcx)
800322: 80 00 00 addb $0x0,(%rax)
800325: 00 00 add %al,(%rax)
800327: 00 30 add %dh,(%rax)
```
`main` before validate-memref from BOLT log
```
.LBB07 (8 instructions, align : 1)
Entry Point
CFI State : 0
00000000: movq $-0x10, %rax
00000007: movl c+17(%rax), %edx
0000000d: movl %edx, %esi
0000000f: movl $SYMBOLat0x402038, %edi
00000014: movl $0x0, %eax
00000019: callq printf at PLT
0000001e: xorl %eax, %eax
00000020: retq
CFI State: 0
```
`main` after validate-memref from BOLT log
```
.LBB07 (8 instructions, align : 1)
Entry Point
CFI State : 0
00000000: movq $-0x10, %rax
00000007: movl "JUMP_TABLE/foo/1.0"+1(%rax), %edx
0000000d: movl %edx, %esi
0000000f: movl $SYMBOLat0x402038, %edi
00000014: movl $0x0, %eax
00000019: callq printf at PLT
0000001e: xorl %eax, %eax
00000020: retq
CFI State: 0
```
https://github.com/llvm/llvm-project/pull/88838
More information about the llvm-commits
mailing list