Module Name:    src
Committed By:   simonb
Date:           Sat Feb  6 06:58:59 UTC 2021

Modified Files:
        src/lib/libc/arch/mips/sys: cerror.S

Log Message:
For mips n32/n64 explicitly save the GP reg on the stack, and
restore it _after_ the call to __errno().  Fixes sending the
__errno() call off to nowhereland when this code is included
in another library (eg __posix_cerror() in libposix).  Failure
picked up by the ATF lib/libposix/posix1/t_rename test.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/arch/mips/sys/cerror.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/arch/mips/sys/cerror.S
diff -u src/lib/libc/arch/mips/sys/cerror.S:1.19 src/lib/libc/arch/mips/sys/cerror.S:1.20
--- src/lib/libc/arch/mips/sys/cerror.S:1.19	Thu Sep 12 15:36:15 2013
+++ src/lib/libc/arch/mips/sys/cerror.S	Sat Feb  6 06:58:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cerror.S,v 1.19 2013/09/12 15:36:15 joerg Exp $	*/
+/*	$NetBSD: cerror.S,v 1.20 2021/02/06 06:58:59 simonb Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -38,7 +38,7 @@
 #if 0
 	RCSID("from: @(#)cerror.s	8.1 (Berkeley) 6/16/93")
 #else
-	RCSID("$NetBSD: cerror.S,v 1.19 2013/09/12 15:36:15 joerg Exp $")
+	RCSID("$NetBSD: cerror.S,v 1.20 2021/02/06 06:58:59 simonb Exp $")
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -50,24 +50,33 @@
 	.globl	_C_LABEL(__errno)
 NESTED_NOPROFILE(__cerror, CALLFRAME_SIZ, ra)
 	.mask	0x80000000, (CALLFRAME_RA - CALLFRAME_SIZ)
-	PIC_PROLOGUE(__cerror)
+	PIC_PROLOGUE(__cerror)		# saves caller gp in t3 (n32/n64)
 	PTR_SUBU	sp, CALLFRAME_SIZ
 	PTR_S		ra, CALLFRAME_RA(sp)
 	INT_S		v0, CALLFRAME_S0(sp)	# save errno value
+#if defined(__mips_n32) || defined(__mips_n64)
+	PTR_S		t3, CALLFRAME_GP(sp)	# save caller gp (in t3)
+#endif
 
 	SAVE_GP(CALLFRAME_GP)
 
 	PTR_LA		t9, _C_LABEL(__errno)	# locate address of errno
-	RESTORE_GP64				# restore GP (from t3)
+
 	jalr		t9			# __errno()
 
+#if defined(__mips_n32) || defined(__mips_n64)
+	PTR_L		gp, CALLFRAME_GP(sp)	# restore caller gp
+#endif
 	INT_L		t0, CALLFRAME_S0(sp)
 	PTR_L		ra, CALLFRAME_RA(sp)
 	INT_S		t0, 0(v0)		# update errno value
 	PTR_ADDU	sp, CALLFRAME_SIZ
 	li		v0, -1
 	li		v1, -1
-	j		ra			# GP has been restored.
+
+	# Note we don't use PIC_RETURN() here as the GP is stored
+	# on the stack and not in the t3 reg (for the n32/n64 case).
+	j		ra
 END(__cerror)
 #else		
 	.globl	_C_LABEL(errno)

Reply via email to