mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 01:26:04 +00:00

D127611 computed st_value is inaccurate: * For a backward branch, the destination address may be wrong if there is no relaxable relocation between it and the current location due to `if (remove)`. We may incorrectly relax a branch to c.j which ends up an overflow. * For a forward branch, the destination address may be overestimated and lose relaxation opportunities. To fix the issues, * Don't reset st_value to the original value. * Save the st_value delta from the previous iteration into valueDelta, and use `sa[0].d->value -= delta - valueDelta.find(sa[0].d)->second`.
45 lines
1.1 KiB
ArmAsm
45 lines
1.1 KiB
ArmAsm
# REQUIRES: riscv
|
|
## Test R_RISCV_CALL referencing the current input section with the displacement
|
|
## close to the boundary.
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+c,+relax %s -o %t.o
|
|
# RUN: ld.lld -Ttext=0x10000 %t.o -o %t
|
|
# RUN: llvm-objdump -d --no-show-raw-insn -M no-aliases %t | FileCheck %s
|
|
|
|
# CHECK-LABEL: <_start>:
|
|
# CHECK-NEXT: jal ra, {{.*}} <_start>
|
|
# CHECK-NEXT: jal ra, {{.*}} <_start>
|
|
# CHECK-EMPTY:
|
|
# CHECK-NEXT: <a>:
|
|
# CHECK-NEXT: c.jr ra
|
|
|
|
# CHECK-LABEL: <b>:
|
|
# CHECK: jal zero, {{.*}} <a>
|
|
# CHECK-NEXT: jal zero, {{.*}} <c>
|
|
# CHECK-NEXT: c.j {{.*}} <c>
|
|
|
|
# CHECK-LABEL: <c>:
|
|
# CHECK-NEXT: c.jr ra
|
|
|
|
#--- a.s
|
|
.global _start
|
|
_start:
|
|
call _start
|
|
call _start
|
|
|
|
a:
|
|
ret
|
|
b:
|
|
.space 2048
|
|
## Relaxed to jal. If we don't compute the precise value of a, we may consider
|
|
## a reachable by c.j.
|
|
tail a
|
|
## Relaxed to jal. c.j is unreachable.
|
|
tail c # c.j
|
|
## Relaxed to c.j. If we don't compute the precise value of c, we may consider
|
|
## c.j unreachable.
|
|
tail c # c.j
|
|
.space 2042
|
|
c:
|
|
ret
|