Skip to content

Commit caabec2

Browse files
committed
psm: fix .cfi directives for RISC-V
We used RISC-V code as a reference implementing psm for LoongArch. During the review of LoongArch code we found that the .cfi directives in RISC-V was incorrect [1]. The GNU assembler defines .cfi_def_cfa [2]: computing CFA as: take address from register and add offset to it. So ".cfi_def_cfa x2, 16" will compute the CFA correctly, but we used "-16". I tested the code on an StarFive VisionFive v1 board (access provided by The GCC Compile Farm project [3]) with a C caller and GDB. GDB indeed reported "corrupt stack" for backtrace. Fix the symbol of offset to make the backtrace working. And, clean up the .cfi directives as Simonas suggested [4]. [1]: #68 (comment) [2]: https://sourceware.org/binutils/docs/as/CFI-directives.html [3]: https://cfarm.tetaneutral.net/ [4]: #68 (comment)
1 parent 910957b commit caabec2

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

psm/src/arch/riscv.s

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ rust_psm_on_stack:
4848
.cfi_startproc
4949
sw x1, -12(x13)
5050
sw x2, -16(x13)
51-
.cfi_def_cfa x13, 0
51+
addi x2, x13, -16
52+
.cfi_def_cfa x2, 16
5253
.cfi_offset x1, -12
5354
.cfi_offset x2, -16
54-
addi x2, x13, -16
55-
.cfi_def_cfa x2, -16
5655
jalr x1, x12, 0
5756
lw x1, 4(x2)
5857
.cfi_restore x1

psm/src/arch/riscv64.s

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ rust_psm_on_stack:
4848
.cfi_startproc
4949
sd x1, -8(x13)
5050
sd x2, -16(x13)
51-
.cfi_def_cfa x13, 0
51+
addi x2, x13, -16
52+
.cfi_def_cfa x2, 16
5253
.cfi_offset x1, -8
5354
.cfi_offset x2, -16
54-
addi x2, x13, -16
55-
.cfi_def_cfa x2, -16
5655
jalr x1, x12, 0
5756
ld x1, 8(x2)
5857
.cfi_restore x1

0 commit comments

Comments
 (0)