shithub: riscv

Download patch

ref: 0002fd0cf786d16c9b3e1ab62f0cb92b2461f185
parent: b599dc0e5486923085f238e146d5a1750bc168a9
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun May 17 19:46:09 EDT 2020

libc/arm64: work arround linker bug for cas()

at the _cas0 label, the linker would generate spurious stack
adjustment before the return:

atexitdont+0x84 0x000000000003614c	CLREX	$0xf
atexitdont+0x88 0x0000000000036150	MOVW	R31,R0
atexitdont+0x8c 0x0000000000036154	MOV	(SP)16!,R30 <- ????????????
atexitdont+0x90 0x0000000000036158	RETURN

the work arround is to move the code into its own cas0
text symbol.

this fixes impossible cwfs crashes in srvi().

--- a/sys/src/libc/arm64/atom.s
+++ b/sys/src/libc/arm64/atom.s
@@ -3,6 +3,12 @@
  * int cas(uint *p, int ov, int nv);
  * int casl(ulong *p, ulong ov, ulong nv);
  */
+TEXT cas0(SB), 1, $-4
+_cas0:
+	CLREX
+	MOVW	$0, R0
+	RETURN
+
 TEXT cas32(SB), 1, $-4
 TEXT cas(SB), 1, $-4
 TEXT casl(SB), 1, $-4
@@ -16,10 +22,6 @@
 	CBNZ	R4, _cas1
 	MOVW	$1, R0
 	B	_barrier(SB)
-_cas0:
-	CLREX
-	MOVW	$0, R0
-	RETURN
 
 TEXT casp(SB), 1, $-4
 	MOV	ov+8(FP), R1
--- a/sys/src/libc/arm64/tas.s
+++ b/sys/src/libc/arm64/tas.s
@@ -5,6 +5,7 @@
 	STXRW	R2, (R0), R3
 	CBNZ	R3, _tas1
 	MOVW	R1, R0
+	B _barrier(SB)
 
 TEXT	_barrier(SB), 1, $-4
 	DMB	$0xB	// ISH