https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123403
Bug ID: 123403
Summary: the copy-paste bugs in libgcc for v850
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libgcc
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
Created attachment 63220
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63220&action=edit
a proposed fix for this issue
the system:
```
Linux wwhome7 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC
2022 x86_64 x86_64 x86_64 GNU/Linux
```
the version:
```
$ v850-unknown-elf-gcc --version
v850-unknown-elf-gcc (Built by ckormanyos/real-time-cpp) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
```
the command line:
```
$ v850-unknown-elf-gcc -O2 -x c -fno-stack-protector -mrh850-
abi -mv850e2v3 -msoft-float -c -osave_return_gcc.o save_return_gcc.c
$ v850-unknown-elf-ld -orh850_save_return_gcc.elf save_return_gcc.o
~/gcc-v850-unknown-elf/local/gcc-13.2.0-v850-unknown-elf/lib/gcc/v850-unknown-elf/13.2.0/libgcc.a
```
the result of:
```
v850-unknown-elf-objdump -d rh850_save_return_gcc.elf|less
/__return_r25_r29
/__return_r2_r31
```
is
```
001003a4 <__return_r25_r29>:
1003a4: 3e ef 01 00 ld.w 0[ep], r29
1003a8: 3e e7 05 00 ld.w 4[ep], r28
1003ac: 3e df 09 00 ld.w 8[ep], r27
1003b0: 3e d7 0d 00 ld.w 12[ep], r26
1003b4: 3e cf 11 00 ld.w 16[ep], r25
1003b8: 03 1e 14 00 addi 20, sp, sp
1003bc: 7f 00 jmp [lp]
```
and
```
0010046c <__return_r2_r31>:
10046c: 23 ef 2d 00 ld.w 44[sp], r29
100470: 23 e7 29 00 ld.w 40[sp], r28
100474: 23 df 25 00 ld.w 36[sp], r27
100478: 23 d7 21 00 ld.w 32[sp], r26
10047c: 23 cf 1d 00 ld.w 28[sp], r25
100480: 23 c7 19 00 ld.w 24[sp], r24
100484: 23 bf 15 00 ld.w 20[sp], r23
100488: 23 b7 11 00 ld.w 16[sp], r22
10048c: 23 af 0d 00 ld.w 12[sp], r21
100490: 23 a7 09 00 ld.w 8[sp], r20
100494: 23 17 05 00 ld.w 4[sp], r2
100498: 23 ff 01 00 ld.w 0[sp], lp
10049c: 03 1e 30 00 addi 48, sp, sp
1004a0: 7f 00 jmp [lp]
```
__return_r25_r29 uses undefined register `ep`
__return_r2_r31 restores registers in the reverse order
(e.g. `lp` should be the top (not the bottom) register in the frame)
these functions should match __save_r25_r29 and __save_r2_r31 functions.
see the patch in the attachment
I also can propose another improvement (reducing the size of save/return
functions by using 16-bit `add imm, sp` instead of 32-bit `addi imm, sp, sp`)
but I'd like to do this in another issue.