[libc-commits] [PATCH] D145584: [libc] Add support for setjmp and longjmp in riscv
Mikhail Ramalho via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Mar 14 08:25:07 PDT 2023
mikhail.ramalho added a comment.
Hi Siva, let me try to explain all the comments at once (I'll add it to the commit message too):
I've added the `__attribute__((naked))` because both clang and GCC will add a function prologue and epilogue to these functions without it.
The consequence of using the naked attribute is that clang doesn't allow us to reference arguments in the function body:
/home/mgadelha/llvm-project/libc/src/setjmp/setjmp.cpp:75:52: error: parameter references not allowed in naked functions
LIBC_INLINE_ASM("sd %0, %1\n\t" : "=r"(ra) : "m"(buf->__pc) :);
This is not a problem for GCC, but clang refuses to compile the code.
So, we either use the naked attribute to reduce the size of setjmp/longjm (which forces us to use a0 and a1, only because of clang), or we don't use the attribute and generate a huge setjmp/longjmp. I've decided to go with the former...
setjmp with the naked attribute:
0000000000000000 <_ZN11__llvm_libc6setjmpEP9__jmp_buf>:
0: 00153023 sd ra,0(a0)
4: e500 sd s0,8(a0)
6: e904 sd s1,16(a0)
8: 01253c23 sd s2,24(a0)
c: 03353023 sd s3,32(a0)
10: 03453423 sd s4,40(a0)
14: 03553823 sd s5,48(a0)
18: 03653c23 sd s6,56(a0)
1c: 05753023 sd s7,64(a0)
20: 05853423 sd s8,72(a0)
24: 05953823 sd s9,80(a0)
28: 05a53c23 sd s10,88(a0)
2c: 07b53023 sd s11,96(a0)
30: 06253423 sd sp,104(a0)
34: b920 fsd fs0,112(a0)
36: bd24 fsd fs1,120(a0)
38: 09253027 fsd fs2,128(a0)
3c: 09353427 fsd fs3,136(a0)
40: 09453827 fsd fs4,144(a0)
44: 09553c27 fsd fs5,152(a0)
48: 0b653027 fsd fs6,160(a0)
4c: 0b753427 fsd fs7,168(a0)
50: 0b853827 fsd fs8,176(a0)
54: 0b953c27 fsd fs9,184(a0)
58: 0da53027 fsd fs10,192(a0)
5c: 0db53427 fsd fs11,200(a0)
60: 4501 li a0,0
0000000000000062 <.LVL1>:
62: 8082 ret
without the naked attribute:
0000000000000000 <_ZN11__llvm_libc6setjmpEP9__jmp_buf>:
0: 7155 add sp,sp,-208
2: e586 sd ra,200(sp)
4: e1a2 sd s0,192(sp)
6: fd26 sd s1,184(sp)
8: f94a sd s2,176(sp)
a: f54e sd s3,168(sp)
c: f152 sd s4,160(sp)
e: ed56 sd s5,152(sp)
10: e95a sd s6,144(sp)
12: e55e sd s7,136(sp)
14: e162 sd s8,128(sp)
16: fce6 sd s9,120(sp)
18: f8ea sd s10,112(sp)
1a: f4ee sd s11,104(sp)
1c: b0a2 fsd fs0,96(sp)
1e: aca6 fsd fs1,88(sp)
20: a8ca fsd fs2,80(sp)
22: a4ce fsd fs3,72(sp)
24: a0d2 fsd fs4,64(sp)
26: bc56 fsd fs5,56(sp)
28: b85a fsd fs6,48(sp)
2a: b45e fsd fs7,40(sp)
2c: b062 fsd fs8,32(sp)
2e: ac66 fsd fs9,24(sp)
30: a86a fsd fs10,16(sp)
32: a46e fsd fs11,8(sp)
34: 00153023 sd ra,0(a0)
38: 00850593 add a1,a0,8
3c: e180 sd s0,0(a1)
3e: 01050593 add a1,a0,16
42: e184 sd s1,0(a1)
44: 01850593 add a1,a0,24
48: 0125b023 sd s2,0(a1)
4c: 02050593 add a1,a0,32
50: 0135b023 sd s3,0(a1)
54: 02850593 add a1,a0,40
58: 0145b023 sd s4,0(a1)
5c: 03050593 add a1,a0,48
60: 0155b023 sd s5,0(a1)
64: 03850593 add a1,a0,56
68: 0165b023 sd s6,0(a1)
6c: 04050593 add a1,a0,64
70: 0175b023 sd s7,0(a1)
74: 04850593 add a1,a0,72
78: 0185b023 sd s8,0(a1)
7c: 05050593 add a1,a0,80
80: 0195b023 sd s9,0(a1)
84: 05850593 add a1,a0,88
88: 01a5b023 sd s10,0(a1)
8c: 06050593 add a1,a0,96
90: 01b5b023 sd s11,0(a1)
94: 06850593 add a1,a0,104
98: 0025b023 sd sp,0(a1)
9c: 07050593 add a1,a0,112
a0: a180 fsd fs0,0(a1)
a2: 07850593 add a1,a0,120
a6: a184 fsd fs1,0(a1)
a8: 08050593 add a1,a0,128
ac: 0125b027 fsd fs2,0(a1)
b0: 08850593 add a1,a0,136
b4: 0135b027 fsd fs3,0(a1)
b8: 09050593 add a1,a0,144
bc: 0145b027 fsd fs4,0(a1)
c0: 09850593 add a1,a0,152
c4: 0155b027 fsd fs5,0(a1)
c8: 0a050593 add a1,a0,160
cc: 0165b027 fsd fs6,0(a1)
d0: 0a850593 add a1,a0,168
d4: 0175b027 fsd fs7,0(a1)
d8: 0b050593 add a1,a0,176
dc: 0185b027 fsd fs8,0(a1)
e0: 0b850593 add a1,a0,184
e4: 0195b027 fsd fs9,0(a1)
e8: 0c050593 add a1,a0,192
ec: 01a5b027 fsd fs10,0(a1)
f0: 0c850513 add a0,a0,200
f4: 01b53027 fsd fs11,0(a0)
f8: 4501 li a0,0
fa: 60ae ld ra,200(sp)
fc: 640e ld s0,192(sp)
fe: 74ea ld s1,184(sp)
100: 794a ld s2,176(sp)
102: 79aa ld s3,168(sp)
104: 7a0a ld s4,160(sp)
106: 6aea ld s5,152(sp)
108: 6b4a ld s6,144(sp)
10a: 6baa ld s7,136(sp)
10c: 6c0a ld s8,128(sp)
10e: 7ce6 ld s9,120(sp)
110: 7d46 ld s10,112(sp)
112: 7da6 ld s11,104(sp)
114: 3406 fld fs0,96(sp)
116: 24e6 fld fs1,88(sp)
118: 2946 fld fs2,80(sp)
11a: 29a6 fld fs3,72(sp)
11c: 2a06 fld fs4,64(sp)
11e: 3ae2 fld fs5,56(sp)
120: 3b42 fld fs6,48(sp)
122: 3ba2 fld fs7,40(sp)
124: 3c02 fld fs8,32(sp)
126: 2ce2 fld fs9,24(sp)
128: 2d42 fld fs10,16(sp)
12a: 2da2 fld fs11,8(sp)
12c: 6169 add sp,sp,208
12e: 8082 ret
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145584/new/
https://reviews.llvm.org/D145584
More information about the libc-commits
mailing list