public inbox for libc-ports@sourceware.org
 help / color / mirror / Atom feed
* Add CFI information for MIPS assembly sources
@ 2013-02-07 22:52 Joseph S. Myers
  2013-02-08  0:08 ` Roland McGrath
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Joseph S. Myers @ 2013-02-07 22:52 UTC (permalink / raw)
  To: libc-ports; +Cc: macro

This patch adds CFI information to many of the assembly sources in
MIPS glibc, similar to that for various other architectures, to
support better backtracing through such code by various tools.

This is a start on adding such CFI information rather than a patch
intended to add complete CFI information everywhere in the library.
Specifically, the following are not covered but could be covered by a
separate patch:

* Assembly sources used through inline asm in .c files (including some
complete functions generated that way through inline asm).

* The SETUP_GPX* macros.

* The bit of setcontext.S after sp is set from the saved context and
before the jump to that saved context.

* sysdeps/mips/start.S.

* sysdeps/unix/mips/sysdep.S.

For SETUP_GP64 and RESTORE_GP64, the cfi_* directives are in the
individual .S files rather than the macro definitions because the
macros can be used to save the old gp value in either a register or a
stack slot, and those need different CFI directives, so a single macro
SETUP_GP64 can't handle both cases and generate CFI at the same time.
This does mean that various callers need to condition the use of CFI
with these macro so no such CFI is generated in the o32 case when the
GP64 macros expand to empty (this is of course only needed for those
callers in .S files actually shared by o32 and non-o32 ABIs).
Although the RESTORE_GP64 doesn't actually depend on where the value
was saved, it seems better to be consistent and have the directives in
the .S files in both cases, rather than just for SETUP_GP64.

Quite a few of the changes are simply making functions consistently
use macros such as ENTRY and END at the start and end of the functions
to generate the cfi_startproc / cfi_endproc directives.  Some changes
to use ENTRY may have the effect of changing the .align directives
(which were .align 4 in some cases, now more consistently .align 2),
but I see no particular reason for the variation in those directives
in the cases where macros were previously not used at
start-of-function.

I plan to commit this patch subject to the results of testing that is
currently running, but comments or corrections are welcome.

2013-02-07  Joseph Myers  <joseph@codesourcery.com>

	* sysdeps/mips/add_n.S (__mpn_add_n): Use END.
	* sysdeps/mips/bsd-_setjmp.S (_setjmp): Likewise.
	* sysdeps/mips/bsd-setjmp.S (setjmp): Likewise.
	* sysdeps/mips/mips64/add_n.S (__mpn_add_n): Use ENTRY and END.
	* sysdeps/mips/mips64/addmul_1.S (__mpn_addmul_1): Likewise.
	* sysdeps/mips/mips64/bsd-_setjmp.S (_setjmp): Add CFI
	information.  Use END.
	* sysdeps/mips/mips64/bsd-setjmp.S (setjmp): Likewise.
	* sysdeps/mips/mips64/lshift.S (__mpn_lshift): Use ENTRY and END.
	* sysdeps/mips/mips64/mul_1.S (__mpn_mul_1): Likewise.
	* sysdeps/mips/mips64/rshift.S (__mpn_rshift): Likewise.
	* sysdeps/mips/mips64/setjmp.S (__sigsetjmp): Add CFI
	information.  Use END.
	* sysdeps/mips/mips64/sub_n.S (__mpn_sub_n): Use ENTRY and END.
	* sysdeps/mips/mips64/submul_1.S (__mpn_submul_1): Likewise.
	* sysdeps/mips/setjmp.S (__sigsetjmp): Use END.
	* sysdeps/mips/sys/asm.h (__mips_cfi_startproc): Define depending
	on [_LIBC].
	(__mips_cfi_endproc): Likewise.
	(LEAF): Use __mips_cfi_startproc.
	(NESTED): Likewise.
	(END): Use __mips_cfi_endproc.
	(EXPORT): Use __mips_cfi_startproc.
	* sysdeps/unix/mips/mips32/sysdep.h (PSEUDO): Add CFI information
	for error-handling code in both definitions.
	* sysdeps/unix/mips/mips64/n32/sysdep.h (PSEUDO): Likewise.
	* sysdeps/unix/mips/mips64/n64/sysdep.h (PSEUDO): Likewise.
	* sysdeps/unix/mips/sysdep.h (ENTRY): Use cfi_startproc.
	(END): Use cfi_endproc.
	(PSEUDO_END): Likewise.
	(PSEUDO_END_NOERRNO): Likewise.
	(PSEUDO_END_ERRVAL): Likewise.
	* sysdeps/unix/sysv/linux/mips/clone.S (__clone): Add CFI
	information.
	* sysdeps/unix/sysv/linux/mips/getcontext.S (__getcontext):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/makecontext.S (__makecontext):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S (__ioctl):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/nptl/sysdep-cancel.h
	[(!NOT_IN_libc || IS_IN_libpthread || IS_IN_librt) && __PIC__]
	(PSEUDO): Use cfi_endproc before ENTRY.
	* sysdeps/unix/sysv/linux/mips/mips64/syscall.S (syscall): Add CFI
	information.
	* sysdeps/unix/sysv/linux/mips/nptl/sysdep-cancel.h [(!NOT_IN_libc
	|| IS_IN_libpthread || IS_IN_librt) && __PIC__] (PSEUDO): Use
	cfi_endproc before ENTRY.
	* sysdeps/unix/sysv/linux/mips/setcontext.S (__setcontext): Add
	CFI information.
	* sysdeps/unix/sysv/linux/mips/swapcontext.S (__swapcontext):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/vfork.S (__vfork): Likewise.

diff --git a/ports/sysdeps/mips/add_n.S b/ports/sysdeps/mips/add_n.S
index 7a3848f..e83fc81 100644
--- a/ports/sysdeps/mips/add_n.S
+++ b/ports/sysdeps/mips/add_n.S
@@ -118,4 +118,4 @@ L(end):	addu	$11,$11,$2
 	sw	$11,0($4)
 	j	$31
 	or	$2,$2,$8
-	.end __mpn_add_n
+END (__mpn_add_n)
diff --git a/ports/sysdeps/mips/bsd-_setjmp.S b/ports/sysdeps/mips/bsd-_setjmp.S
index a932096..1974e4b 100644
--- a/ports/sysdeps/mips/bsd-_setjmp.S
+++ b/ports/sysdeps/mips/bsd-_setjmp.S
@@ -38,5 +38,5 @@ ENTRY (_setjmp)
 #else
 	j	C_SYMBOL_NAME (__sigsetjmp)
 #endif
-	.end	_setjmp
+END (_setjmp)
 libc_hidden_def (_setjmp)
diff --git a/ports/sysdeps/mips/bsd-setjmp.S b/ports/sysdeps/mips/bsd-setjmp.S
index 406c849..5eedcdd 100644
--- a/ports/sysdeps/mips/bsd-setjmp.S
+++ b/ports/sysdeps/mips/bsd-setjmp.S
@@ -38,4 +38,4 @@ ENTRY (setjmp)
 #else
 	j	C_SYMBOL_NAME (__sigsetjmp)
 #endif
-	.end	setjmp
+END (setjmp)
diff --git a/ports/sysdeps/mips/mips64/add_n.S b/ports/sysdeps/mips/mips64/add_n.S
index efb6cf4..020d4af 100644
--- a/ports/sysdeps/mips/mips64/add_n.S
+++ b/ports/sysdeps/mips/mips64/add_n.S
@@ -33,11 +33,7 @@
 #ifdef __PIC__
 	.option pic2
 #endif
-	.text
-	.align	2
-	.globl	__mpn_add_n
-	.ent	__mpn_add_n
-__mpn_add_n:
+ENTRY (__mpn_add_n)
 #ifdef __PIC__
 	SETUP_GP /* ??? unused */
 #endif
@@ -126,4 +122,4 @@ L(Lend):	daddu	$11,$11,$2
 	j	$31
 	or	$2,$2,$8
 
-	.end	__mpn_add_n
+END (__mpn_add_n)
diff --git a/ports/sysdeps/mips/mips64/addmul_1.S b/ports/sysdeps/mips/mips64/addmul_1.S
index 43838fd..46729a6 100644
--- a/ports/sysdeps/mips/mips64/addmul_1.S
+++ b/ports/sysdeps/mips/mips64/addmul_1.S
@@ -32,11 +32,7 @@
 #ifdef PIC
 	.option pic2
 #endif
-	.text
-	.align	4
-	.globl	__mpn_addmul_1
-	.ent	__mpn_addmul_1
-__mpn_addmul_1:
+ENTRY (__mpn_addmul_1)
 #ifdef PIC
 	SETUP_GP /* ??? unused */
 #endif
@@ -102,4 +98,4 @@ L(LC0):	ld	$10,0($4)
 	j	$31
 	daddu	$2,$9,$2	# add high product limb and carry from addition
 
-	.end	__mpn_addmul_1
+END (__mpn_addmul_1)
diff --git a/ports/sysdeps/mips/mips64/bsd-_setjmp.S b/ports/sysdeps/mips/mips64/bsd-_setjmp.S
index de36cf0..f5ef852 100644
--- a/ports/sysdeps/mips/mips64/bsd-_setjmp.S
+++ b/ports/sysdeps/mips/mips64/bsd-_setjmp.S
@@ -32,16 +32,18 @@ ENTRY (_setjmp)
 	SETUP_GP
 #endif
 	SETUP_GP64 (v0, C_SYMBOL_NAME (_setjmp))
+	cfi_register (gp, v0)
 	PTR_LA t9, C_SYMBOL_NAME (__sigsetjmp)
 #if _MIPS_SIM == _ABIO32
 	nop
 #endif	
 	RESTORE_GP64
+	cfi_restore (gp)
 	move	a1, zero		/* Pass a second argument of zero.  */
 #ifdef __PIC__
 	jr	t9
 #else
 	j	C_SYMBOL_NAME (__sigsetjmp)
 #endif
-	.end	_setjmp
+END (_setjmp)
 libc_hidden_def (_setjmp)
diff --git a/ports/sysdeps/mips/mips64/bsd-setjmp.S b/ports/sysdeps/mips/mips64/bsd-setjmp.S
index c3e26bf..fdd405e 100644
--- a/ports/sysdeps/mips/mips64/bsd-setjmp.S
+++ b/ports/sysdeps/mips/mips64/bsd-setjmp.S
@@ -32,15 +32,17 @@ ENTRY (setjmp)
 	SETUP_GP
 #endif
 	SETUP_GP64 (v0, C_SYMBOL_NAME (setjmp))
+	cfi_register (gp, v0)
 	PTR_LA t9, C_SYMBOL_NAME (__sigsetjmp)
 #if _MIPS_SIM == _ABIO32
 	nop
 #endif	
 	RESTORE_GP64
+	cfi_restore (gp)
 	dli a1, 1		/* Pass a second argument of one.  */
 #ifdef __PIC__
 	jr	t9
 #else
 	j	C_SYMBOL_NAME (__sigsetjmp)
 #endif
-	.end	setjmp
+END (setjmp)
diff --git a/ports/sysdeps/mips/mips64/lshift.S b/ports/sysdeps/mips/mips64/lshift.S
index e0b02bc..740408d 100644
--- a/ports/sysdeps/mips/mips64/lshift.S
+++ b/ports/sysdeps/mips/mips64/lshift.S
@@ -32,11 +32,7 @@
 #ifdef __PIC__
 	.option pic2
 #endif
-	.text
-	.align	2
-	.globl	__mpn_lshift
-	.ent	__mpn_lshift
-__mpn_lshift:
+ENTRY (__mpn_lshift)
 #ifdef __PIC__
 	SETUP_GP /* ??? unused */
 #endif
@@ -101,4 +97,4 @@ L(Loop):	ld	$3,-16($5)
 L(Lend):	dsll	$8,$10,$7
 	j	$31
 	sd	$8,-8($4)
-	.end	__mpn_lshift
+END (__mpn_lshift)
diff --git a/ports/sysdeps/mips/mips64/mul_1.S b/ports/sysdeps/mips/mips64/mul_1.S
index 2fe28d3..e136065 100644
--- a/ports/sysdeps/mips/mips64/mul_1.S
+++ b/ports/sysdeps/mips/mips64/mul_1.S
@@ -33,11 +33,7 @@
 #ifdef __PIC__
 	.option pic2
 #endif
-	.text
-	.align	4
-	.globl	__mpn_mul_1
-	.ent	__mpn_mul_1
-__mpn_mul_1:
+ENTRY (__mpn_mul_1)
 #ifdef __PIC__
 	SETUP_GP /* ??? unused */
 #endif
@@ -91,4 +87,4 @@ L(LC0):	mflo	$10
 	j	$31
 	daddu	$2,$9,$2	# add high product limb and carry from addition
 
-	.end	__mpn_mul_1
+END (__mpn_mul_1)
diff --git a/ports/sysdeps/mips/mips64/rshift.S b/ports/sysdeps/mips/mips64/rshift.S
index 75ac68b..0d821f2 100644
--- a/ports/sysdeps/mips/mips64/rshift.S
+++ b/ports/sysdeps/mips/mips64/rshift.S
@@ -32,11 +32,7 @@
 #ifdef __PIC__
 	.option pic2
 #endif
-	.text
-	.align	2
-	.globl	__mpn_rshift
-	.ent	__mpn_rshift
-__mpn_rshift:
+ENTRY (__mpn_rshift)
 #ifdef __PIC__
 	SETUP_GP /* ??? unused */
 #endif
@@ -98,4 +94,4 @@ L(Loop):	ld	$3,8($5)
 L(Lend):	dsrl	$8,$10,$7
 	j	$31
 	sd	$8,0($4)
-	.end	__mpn_rshift
+END (__mpn_rshift)
diff --git a/ports/sysdeps/mips/mips64/setjmp.S b/ports/sysdeps/mips/mips64/setjmp.S
index 53ed92c..e355957 100644
--- a/ports/sysdeps/mips/mips64/setjmp.S
+++ b/ports/sysdeps/mips/mips64/setjmp.S
@@ -30,6 +30,7 @@ ENTRY (__sigsetjmp)
 	SETUP_GP
 #endif
 	SETUP_GP64 (v0, C_SYMBOL_NAME (__sigsetjmp))
+	cfi_register (gp, v0)
 	move a2, sp
 	move a3, fp
 	PTR_LA t9, __sigsetjmp_aux
@@ -37,8 +38,9 @@ ENTRY (__sigsetjmp)
 	nop
 #endif	
 	RESTORE_GP64
+	cfi_restore (gp)
 #if _MIPS_SIM != _ABIO32
 	move a4, gp
 #endif
 	jr t9
-	.end __sigsetjmp
+END (__sigsetjmp)
diff --git a/ports/sysdeps/mips/mips64/sub_n.S b/ports/sysdeps/mips/mips64/sub_n.S
index ea8f4bd..dd6f691 100644
--- a/ports/sysdeps/mips/mips64/sub_n.S
+++ b/ports/sysdeps/mips/mips64/sub_n.S
@@ -33,11 +33,7 @@
 #ifdef __PIC__
 	.option pic2
 #endif
-	.text
-	.align	2
-	.globl	__mpn_sub_n
-	.ent	__mpn_sub_n
-__mpn_sub_n:
+ENTRY (__mpn_sub_n)
 #ifdef __PIC__
 	SETUP_GP /* ??? unused */
 #endif
@@ -126,4 +122,4 @@ L(Lend):	daddu	$11,$11,$2
 	j	$31
 	or	$2,$2,$8
 
-	.end	__mpn_sub_n
+END (__mpn_sub_n)
diff --git a/ports/sysdeps/mips/mips64/submul_1.S b/ports/sysdeps/mips/mips64/submul_1.S
index 22239d5..bf5d6ff 100644
--- a/ports/sysdeps/mips/mips64/submul_1.S
+++ b/ports/sysdeps/mips/mips64/submul_1.S
@@ -33,11 +33,7 @@
 #ifdef __PIC__
 	.option pic2
 #endif
-	.text
-	.align	4
-	.globl	__mpn_submul_1
-	.ent	__mpn_submul_1
-__mpn_submul_1:
+ENTRY (__mpn_submul_1)
 #ifdef __PIC__
 	SETUP_GP /* ??? unused */
 #endif
@@ -103,4 +99,4 @@ L(LC0):	ld	$10,0($4)
 	j	$31
 	daddu	$2,$9,$2	# add high product limb and carry from addition
 
-	.end	__mpn_submul_1
+END (__mpn_submul_1)
diff --git a/ports/sysdeps/mips/setjmp.S b/ports/sysdeps/mips/setjmp.S
index 7c53b97..3f923fb 100644
--- a/ports/sysdeps/mips/setjmp.S
+++ b/ports/sysdeps/mips/setjmp.S
@@ -41,4 +41,4 @@ ENTRY (__sigsetjmp)
 #else
 	j	__sigsetjmp_aux
 #endif
-	.end __sigsetjmp
+END (__sigsetjmp)
diff --git a/ports/sysdeps/mips/sys/asm.h b/ports/sysdeps/mips/sys/asm.h
index 605451a..62ff378 100644
--- a/ports/sysdeps/mips/sys/asm.h
+++ b/ports/sysdeps/mips/sys/asm.h
@@ -26,6 +26,14 @@
 # define CAT(str1,str2) __CAT(str1,str2)
 #endif
 
+#ifdef _LIBC
+# define __mips_cfi_startproc cfi_startproc
+# define __mips_cfi_endproc cfi_endproc
+#else
+# define __mips_cfi_startproc /* Empty.  */
+# define __mips_cfi_endproc /* Empty.  */
+#endif
+
 /*
  * Macros to handle different pointer/register sizes for 32/64-bit code
  *
@@ -147,7 +155,8 @@ l:							\
 		.align	2;                              \
 		.type	symbol,@function;               \
 		.ent	symbol,0;                       \
-symbol:		.frame	sp,0,ra
+symbol:		.frame	sp,0,ra;			\
+		__mips_cfi_startproc
 
 /*
  * NESTED - declare nested routine entry point
@@ -157,13 +166,15 @@ symbol:		.frame	sp,0,ra
 		.align	2;                              \
 		.type	symbol,@function;               \
 		.ent	symbol,0;                       \
-symbol:		.frame	sp, framesize, rpc
+symbol:		.frame	sp, framesize, rpc;		\
+		__mips_cfi_startproc
 
 /*
  * END - mark end of function
  */
 #ifndef END
 # define END(function)                                   \
+		__mips_cfi_endproc;			\
 		.end	function;		        \
 		.size	function,.-function
 #endif
@@ -173,7 +184,7 @@ symbol:		.frame	sp, framesize, rpc
  */
 #define	EXPORT(symbol)                                  \
 		.globl	symbol;                         \
-symbol:
+symbol:		__mips_cfi_startproc
 
 /*
  * ABS - export absolute symbol
diff --git a/ports/sysdeps/unix/mips/mips32/sysdep.h b/ports/sysdeps/unix/mips/mips32/sysdep.h
index d7d3892..5c5d769 100644
--- a/ports/sysdeps/unix/mips/mips32/sysdep.h
+++ b/ports/sysdeps/unix/mips/mips32/sysdep.h
@@ -24,8 +24,10 @@
 #ifdef __PIC__
 #define PSEUDO(name, syscall_name, args) \
   .align 2;								      \
+  cfi_startproc;							      \
   99: la t9,__syscall_error;						      \
   jr t9;								      \
+  cfi_endproc;								      \
   ENTRY(name)								      \
   .set noreorder;							      \
   .cpload t9;								      \
@@ -38,8 +40,10 @@ L(syse1):
 #define PSEUDO(name, syscall_name, args) \
   .set noreorder;							      \
   .align 2;								      \
+  cfi_startproc;							      \
   99: j __syscall_error;						      \
   nop;									      \
+  cfi_endproc;								      \
   ENTRY(name)								      \
   .set noreorder;							      \
   li v0, SYS_ify(syscall_name);						      \
diff --git a/ports/sysdeps/unix/mips/mips64/n32/sysdep.h b/ports/sysdeps/unix/mips/mips64/n32/sysdep.h
index 37a67a2..49ae769 100644
--- a/ports/sysdeps/unix/mips/mips64/n32/sysdep.h
+++ b/ports/sysdeps/unix/mips/mips64/n32/sysdep.h
@@ -26,13 +26,17 @@
 #ifdef __PIC__
 #define PSEUDO(name, syscall_name, args) \
   .align 2;								      \
+  cfi_startproc;							      \
   99:;									      \
   .set noat;								      \
   .cpsetup t9, $1, name;						      \
+  cfi_register (gp, $1);						      \
   .set at;								      \
   la t9,__syscall_error;						      \
   .cpreturn;								      \
+  cfi_restore (gp);							      \
   jr t9;								      \
+  cfi_endproc;								      \
   ENTRY(name)								      \
   li v0, SYS_ify(syscall_name);						      \
   syscall;								      \
@@ -42,8 +46,10 @@ L(syse1):
 #define PSEUDO(name, syscall_name, args) \
   .set noreorder;							      \
   .align 2;								      \
+  cfi_startproc;							      \
   99: j __syscall_error;						      \
   nop;                                                                        \
+  cfi_endproc;								      \
   ENTRY(name)								      \
   .set noreorder;							      \
   li v0, SYS_ify(syscall_name);						      \
diff --git a/ports/sysdeps/unix/mips/mips64/n64/sysdep.h b/ports/sysdeps/unix/mips/mips64/n64/sysdep.h
index 871184b..2670c68 100644
--- a/ports/sysdeps/unix/mips/mips64/n64/sysdep.h
+++ b/ports/sysdeps/unix/mips/mips64/n64/sysdep.h
@@ -26,13 +26,17 @@
 #ifdef __PIC__
 #define PSEUDO(name, syscall_name, args) \
   .align 2;								      \
+  cfi_startproc;							      \
   99:;									      \
   .set noat;								      \
   .cpsetup t9, $1, name;						      \
+  cfi_register (gp, $1);						      \
   .set at;								      \
   dla t9,__syscall_error;						      \
   .cpreturn;								      \
+  cfi_restore (gp);							      \
   jr t9;								      \
+  cfi_endproc;								      \
   ENTRY(name)								      \
   li v0, SYS_ify(syscall_name);						      \
   syscall;								      \
@@ -42,8 +46,10 @@ L(syse1):
 #define PSEUDO(name, syscall_name, args) \
   .set noreorder;							      \
   .align 2;								      \
+  cfi_startproc;							      \
   99: j __syscall_error;						      \
   nop;                                                                        \
+  cfi_endproc;								      \
   ENTRY(name)								      \
   .set noreorder;							      \
   li v0, SYS_ify(syscall_name);						      \
diff --git a/ports/sysdeps/unix/mips/sysdep.h b/ports/sysdeps/unix/mips/sysdep.h
index bab3bc0..ef5c089 100644
--- a/ports/sysdeps/unix/mips/sysdep.h
+++ b/ports/sysdeps/unix/mips/sysdep.h
@@ -27,17 +27,19 @@
   .globl name;								      \
   .align 2;								      \
   .ent name,0;								      \
-  name##:
+  name##:								      \
+  cfi_startproc;
 
 #undef END
 #define	END(function)                                   \
+		cfi_endproc;				\
 		.end	function;		        \
 		.size	function,.-function
 
 #define ret	j ra ; nop
 
 #undef PSEUDO_END
-#define PSEUDO_END(sym) .end sym; .size sym,.-sym
+#define PSEUDO_END(sym) cfi_endproc; .end sym; .size sym,.-sym
 
 #define PSEUDO_NOERRNO(name, syscall_name, args)	\
   .align 2;						\
@@ -47,7 +49,7 @@
   syscall
 
 #undef PSEUDO_END_NOERRNO
-#define PSEUDO_END_NOERRNO(sym) .end sym; .size sym,.-sym
+#define PSEUDO_END_NOERRNO(sym) cfi_endproc; .end sym; .size sym,.-sym
 
 #define ret_NOERRNO ret
 
@@ -59,7 +61,7 @@
   syscall
 
 #undef PSEUDO_END_ERRVAL
-#define PSEUDO_END_ERRVAL(sym) .end sym; .size sym,.-sym
+#define PSEUDO_END_ERRVAL(sym) cfi_endproc; .end sym; .size sym,.-sym
 
 #define ret_ERRVAL ret
 
diff --git a/ports/sysdeps/unix/sysv/linux/mips/clone.S b/ports/sysdeps/unix/sysv/linux/mips/clone.S
index 72360f9..351642d 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/clone.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/clone.S
@@ -47,7 +47,11 @@ NESTED(__clone,4*SZREG,sp)
 	SETUP_GP
 #endif
 	PTR_SUBU sp, FRAMESZ
+	cfi_adjust_cfa_offset (FRAMESZ)
 	SETUP_GP64 (GPOFF, __clone)
+#if _MIPS_SIM != _ABIO32
+	cfi_rel_offset (gp, GPOFF)
+#endif
 #ifdef __PIC__
 	SAVE_GP (GPOFF)
 #endif
@@ -88,26 +92,40 @@ NESTED(__clone,4*SZREG,sp)
 
 	/* Do the system call */
 	li		v0,__NR_clone
+	cfi_endproc
 	syscall
 
 	bnez		a3,L(error)
 	beqz		v0,L(thread_start)
 
 	/* Successful return from the parent */
+	cfi_startproc
+	cfi_adjust_cfa_offset (FRAMESZ)
+#if _MIPS_SIM != _ABIO32
+	cfi_rel_offset (gp, GPOFF)
+#endif
+	cfi_remember_state
 	RESTORE_GP64
+	cfi_restore (gp)
 	PTR_ADDU	sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 	ret
 
 	/* Something bad happened -- no child created */
 L(error):
+	cfi_restore_state
 #ifdef __PIC__
 	PTR_LA		t9,__syscall_error
 	RESTORE_GP64
+	cfi_restore (gp)
 	PTR_ADDU	sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 	jr		t9
 #else
 	RESTORE_GP64
+	cfi_restore (gp)
 	PTR_ADDU	sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 	j		__syscall_error
 #endif
 	END(__clone)
@@ -118,6 +136,7 @@ L(error):
 
 ENTRY(__thread_start)
 L(thread_start):
+	cfi_undefined ($31)
 	/* cp is already loaded.  */
 	SAVE_GP (GPOFF)
 	/* The stackframe has been created on entry of clone().  */
diff --git a/ports/sysdeps/unix/sysv/linux/mips/getcontext.S b/ports/sysdeps/unix/sysv/linux/mips/getcontext.S
index 0e3d35b..a52ff1c 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/getcontext.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/getcontext.S
@@ -54,7 +54,11 @@ NESTED (__getcontext, FRAMESZ, ra)
 # endif
 
 	PTR_ADDIU sp, -FRAMESZ
+	cfi_adjust_cfa_offset (FRAMESZ)
 	SETUP_GP64 (GPOFF, __getcontext)
+# if _MIPS_SIM != _ABIO32
+	cfi_rel_offset (gp, GPOFF)
+# endif
 	SAVE_GP (GPOFF)
 
 #else  /* ! __PIC__ */
@@ -124,19 +128,29 @@ NESTED (__getcontext, FRAMESZ, ra)
 	li	v0, SYS_ify (rt_sigprocmask)
 	syscall
 	bnez	a3, 99f
+	cfi_remember_state
 
 #ifdef __PIC__
 	RESTORE_GP64
+# if _MIPS_SIM != _ABIO32
+	cfi_restore (gp)
+# endif
 	PTR_ADDIU sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 #endif
 	move	v0, zero
 	jr	ra
 
 99:
+	cfi_restore_state
 #ifdef __PIC__
 	PTR_LA	t9, JUMPTARGET (__syscall_error)
 	RESTORE_GP64
+# if _MIPS_SIM != _ABIO32
+	cfi_restore (gp)
+# endif
 	PTR_ADDIU sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 	jr	t9
 
 #else  /* ! __PIC__ */
diff --git a/ports/sysdeps/unix/sysv/linux/mips/makecontext.S b/ports/sysdeps/unix/sysv/linux/mips/makecontext.S
index 65f1a6a..6a6130a 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/makecontext.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/makecontext.S
@@ -63,9 +63,13 @@ NESTED (__makecontext, FRAMESZ, ra)
 #endif
 
 	PTR_ADDIU sp, -FRAMESZ
+	cfi_adjust_cfa_offset (FRAMESZ)
 
 #ifdef __PIC__
 	SETUP_GP64 (GPOFF, __makecontext)
+# if _MIPS_SIM != _ABIO32
+	cfi_rel_offset (gp, GPOFF)
+# endif
 	SAVE_GP (GPOFF)
 #endif
 
@@ -146,7 +150,11 @@ NESTED (__makecontext, FRAMESZ, ra)
 
 #ifdef __PIC__
 	RESTORE_GP64
+# if _MIPS_SIM != _ABIO32
+	cfi_restore (gp)
+# endif
 	PTR_ADDIU sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 #endif
 	jr	ra
 
diff --git a/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S b/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S
index b3bed46..b1f5244 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S
@@ -32,8 +32,10 @@ ENTRY (__ioctl)
 
 L(error):
 	SETUP_GP64 (a0, __ioctl)
+	cfi_register (gp, a0)
 	PTR_LA t9, __syscall_error
 	RESTORE_GP64
+	cfi_restore (gp)
 	jr t9
 
 PSEUDO_END (__ioctl)
diff --git a/ports/sysdeps/unix/sysv/linux/mips/mips64/nptl/sysdep-cancel.h b/ports/sysdeps/unix/sysv/linux/mips/mips64/nptl/sysdep-cancel.h
index 354eba2..6565225 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/mips64/nptl/sysdep-cancel.h
+++ b/ports/sysdeps/unix/sysv/linux/mips/mips64/nptl/sysdep-cancel.h
@@ -57,6 +57,7 @@
     cfi_same_value (gp);						      \
     RESTORESTK;								      \
     ret;								      \
+    cfi_endproc;							      \
   .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
   ENTRY (name)								      \
     SAVESTK;								      \
diff --git a/ports/sysdeps/unix/sysv/linux/mips/mips64/syscall.S b/ports/sysdeps/unix/sysv/linux/mips/mips64/syscall.S
index 839276d..5d4a405 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/mips64/syscall.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/mips64/syscall.S
@@ -30,7 +30,9 @@ NESTED (syscall, SZREG, ra)
 	.mask 0x00010000, -SZREG
 	.fmask 0x00000000, 0
 	PTR_ADDIU sp, -SZREG
+	cfi_adjust_cfa_offset (SZREG)
 	REG_S s0, (sp)
+	cfi_rel_offset (s0, 0)
 
 	move s0, a0
 	move a0, a1		/* shift arg1 - arg7.  */
@@ -45,15 +47,19 @@ NESTED (syscall, SZREG, ra)
 	syscall			/* Do the system call.  */
 
 	REG_L s0, (sp)
+	cfi_restore (s0)
 	PTR_ADDIU sp, SZREG
+	cfi_adjust_cfa_offset (-SZREG)
 	bne a3, zero, L(error)
 
 	ret
 
 L(error):
 	SETUP_GP64 (a0, syscall)
+	cfi_register (gp, a0)
 	PTR_LA t9, __syscall_error
 	RESTORE_GP64
+	cfi_restore (gp)
 	jr t9
 
 END (syscall)
diff --git a/ports/sysdeps/unix/sysv/linux/mips/nptl/sysdep-cancel.h b/ports/sysdeps/unix/sysv/linux/mips/nptl/sysdep-cancel.h
index e1dd672..1e0bfed 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/nptl/sysdep-cancel.h
+++ b/ports/sysdeps/unix/sysv/linux/mips/nptl/sysdep-cancel.h
@@ -52,6 +52,7 @@
     .set reorder;							      \
     bne a3, zero, 99b;					       		      \
     ret;								      \
+    cfi_endproc;							      \
   .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
   ENTRY (name)								      \
     .set noreorder;							      \
diff --git a/ports/sysdeps/unix/sysv/linux/mips/setcontext.S b/ports/sysdeps/unix/sysv/linux/mips/setcontext.S
index 42f709d..097f2aa 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/setcontext.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/setcontext.S
@@ -56,9 +56,13 @@ NESTED (__setcontext, FRAMESZ, ra)
 #endif
 
 	PTR_ADDIU sp, -FRAMESZ
+	cfi_adjust_cfa_offset (FRAMESZ)
 
 #ifdef __PIC__
 	SETUP_GP64 (GPOFF, __setcontext)
+# if _MIPS_SIM != _ABIO32
+	cfi_rel_offset (gp, GPOFF)
+# endif
 	SAVE_GP (GPOFF)
 #endif
 
@@ -152,6 +156,7 @@ NESTED (__setcontext, FRAMESZ, ra)
 	   and call the signal return syscall as if a signal
 	   handler exited normally.  */
 	PTR_ADDIU sp, -((RT_SIGFRAME_SIZE + ALSZ) & ALMASK)
+	cfi_adjust_cfa_offset ((RT_SIGFRAME_SIZE + ALSZ) & ALMASK)
 
 	/* Only ucontext is referred to from rt_sigreturn,
 	   copy it.  */
@@ -175,11 +180,16 @@ NESTED (__setcontext, FRAMESZ, ra)
 	   path.  Successful rt_sigreturn never returns to
 	   its calling place.  */
 	PTR_ADDIU sp, ((RT_SIGFRAME_SIZE + ALSZ) & ALMASK)
+	cfi_adjust_cfa_offset (-((RT_SIGFRAME_SIZE + ALSZ) & ALMASK))
 99:
 #ifdef __PIC__
 	PTR_LA	t9, JUMPTARGET (__syscall_error)
 	RESTORE_GP64
+# if _MIPS_SIM != _ABIO32
+	cfi_restore (gp)
+# endif
 	PTR_ADDIU sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 	jr	t9
 
 #else  /* ! __PIC__ */
diff --git a/ports/sysdeps/unix/sysv/linux/mips/swapcontext.S b/ports/sysdeps/unix/sysv/linux/mips/swapcontext.S
index d965f39..4db10b8 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/swapcontext.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/swapcontext.S
@@ -63,7 +63,11 @@ NESTED (__swapcontext, FRAMESZ, ra)
 # endif
 
 	PTR_ADDIU sp, -FRAMESZ
+	cfi_adjust_cfa_offset (FRAMESZ)
 	SETUP_GP64 (GPOFF, __swapcontext)
+# if _MIPS_SIM != _ABIO32
+	cfi_rel_offset (gp, GPOFF)
+# endif
 	SAVE_GP (GPOFF)
 
 #else  /* ! __PIC__ */
@@ -199,7 +203,11 @@ NESTED (__swapcontext, FRAMESZ, ra)
 #ifdef __PIC__
 	PTR_LA	t9, JUMPTARGET (__syscall_error)
 	RESTORE_GP64
+# if _MIPS_SIM != _ABIO32
+	cfi_restore (gp)
+# endif
 	PTR_ADDIU sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 	jr	t9
 
 #else  /* ! __PIC__ */
diff --git a/ports/sysdeps/unix/sysv/linux/mips/vfork.S b/ports/sysdeps/unix/sysv/linux/mips/vfork.S
index b9503c3..be8c63b 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/vfork.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/vfork.S
@@ -42,7 +42,11 @@ NESTED(__vfork,FRAMESZ,sp)
 	SETUP_GP
 #endif
 	PTR_SUBU sp, FRAMESZ
+	cfi_adjust_cfa_offset (FRAMESZ)
 	SETUP_GP64 (a5, __vfork)
+#if _MIPS_SIM != _ABIO32
+	cfi_register (gp, a5)
+#endif
 #ifdef __PIC__
 	SAVE_GP (GPOFF)
 #endif
@@ -63,6 +67,7 @@ NESTED(__vfork,FRAMESZ,sp)
 #endif
 
 	PTR_ADDU	sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 
 	SAVE_PID
 
@@ -75,20 +80,31 @@ NESTED(__vfork,FRAMESZ,sp)
 
 	RESTORE_PID
 
+	cfi_remember_state
 	bnez		a3,L(error)
 
 	/* Successful return from the parent or child.  */
 	RESTORE_GP64
+#if _MIPS_SIM != _ABIO32
+	cfi_restore (gp)
+#endif
 	ret
 
 	/* Something bad happened -- no child created.  */
 L(error):
+	cfi_restore_state
 #ifdef __PIC__
 	PTR_LA		t9, __syscall_error
 	RESTORE_GP64
+# if _MIPS_SIM != _ABIO32
+	cfi_restore (gp)
+# endif
 	jr		t9
 #else
 	RESTORE_GP64
+# if _MIPS_SIM != _ABIO32
+	cfi_restore (gp)
+# endif
 	j		__syscall_error
 #endif
 	END(__vfork)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Add CFI information for MIPS assembly sources
  2013-02-07 22:52 Add CFI information for MIPS assembly sources Joseph S. Myers
@ 2013-02-08  0:08 ` Roland McGrath
  2013-02-08  0:42   ` Joseph S. Myers
  2013-02-08 14:57 ` Maciej W. Rozycki
  2013-02-11 18:20 ` Joseph S. Myers
  2 siblings, 1 reply; 10+ messages in thread
From: Roland McGrath @ 2013-02-08  0:08 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: libc-ports, macro

> For SETUP_GP64 and RESTORE_GP64, the cfi_* directives are in the
> individual .S files rather than the macro definitions because the
> macros can be used to save the old gp value in either a register or a
> stack slot, and those need different CFI directives, so a single macro
> SETUP_GP64 can't handle both cases and generate CFI at the same time.

It seems much cleaner to define two pairs of macros for the two cases,
so that the macros can contain the CFI details too.  Separating the code
from the CFI like you've done will always be error-prone.  Using separate
macros is less total text, as well as less duplication of magic numbers.


Thanks,
Roland

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Add CFI information for MIPS assembly sources
  2013-02-08  0:08 ` Roland McGrath
@ 2013-02-08  0:42   ` Joseph S. Myers
  2013-02-08  0:47     ` Roland McGrath
  0 siblings, 1 reply; 10+ messages in thread
From: Joseph S. Myers @ 2013-02-08  0:42 UTC (permalink / raw)
  To: Roland McGrath; +Cc: libc-ports, macro

On Thu, 7 Feb 2013, Roland McGrath wrote:

> > For SETUP_GP64 and RESTORE_GP64, the cfi_* directives are in the
> > individual .S files rather than the macro definitions because the
> > macros can be used to save the old gp value in either a register or a
> > stack slot, and those need different CFI directives, so a single macro
> > SETUP_GP64 can't handle both cases and generate CFI at the same time.
> 
> It seems much cleaner to define two pairs of macros for the two cases,
> so that the macros can contain the CFI details too.  Separating the code
> from the CFI like you've done will always be error-prone.  Using separate
> macros is less total text, as well as less duplication of magic numbers.

Unfortunately sys/asm.h is an installed header implementing some 
externally-defined SGI API, but also used internally in glibc for various 
things.  So the CFI in start/end of function macros there is using 
implementation-namespace __mips_cfi_* macros (existing practice for other 
architectures being to put CFI in the start/end of function macros), 
defined conditionally on _LIBC, and any variation on SETUP_GP64 would I 
suppose also need to be in the implementation namespace or conditioned on 
_LIBC.  (For a non-architecture-specific header you might have an internal 
include/sys/asm.h for internal macros, but that's not an option here.  Or 
put the variants in sysdep.h, but that's separating macros from 
closely-related other macros.)

(Putting CFI within those macros would also then bring in the need to deal 
with CFI for inline asm in the same patch - those macros are used, 
stringized, in inline asm in dl-machine.h and dl-trampoline.c, which would 
then need at least .cfi_startproc/.cfi_endproc for the functions defined 
in inline asm.  So it would also make it harder to get in useful pieces of 
CFI incrementally without needing to add all the CFI for all of glibc at 
once.)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Add CFI information for MIPS assembly sources
  2013-02-08  0:42   ` Joseph S. Myers
@ 2013-02-08  0:47     ` Roland McGrath
  2013-02-08  1:06       ` Joseph S. Myers
  0 siblings, 1 reply; 10+ messages in thread
From: Roland McGrath @ 2013-02-08  0:47 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: libc-ports, macro

> Unfortunately sys/asm.h is an installed header implementing some 
> externally-defined SGI API, but also used internally in glibc for various 
> things.  So the CFI in start/end of function macros there is using 
> implementation-namespace __mips_cfi_* macros (existing practice for other 
> architectures being to put CFI in the start/end of function macros), 
> defined conditionally on _LIBC, and any variation on SETUP_GP64 would I 
> suppose also need to be in the implementation namespace or conditioned on 
> _LIBC.  (For a non-architecture-specific header you might have an internal 
> include/sys/asm.h for internal macros, but that's not an option here.  Or 
> put the variants in sysdep.h, but that's separating macros from 
> closely-related other macros.)

For other similar reasons I've been considering supporting
sysdeps/.../include/ directories.  Those would be in the -I list for
building libc, but not in sysdirs and so not candidates for installation.
I can do the makefile hackery if you'd like to use that.

> (Putting CFI within those macros would also then bring in the need to deal 
> with CFI for inline asm in the same patch - those macros are used, 
> stringized, in inline asm in dl-machine.h and dl-trampoline.c, which would 
> then need at least .cfi_startproc/.cfi_endproc for the functions defined 
> in inline asm.  So it would also make it harder to get in useful pieces of 
> CFI incrementally without needing to add all the CFI for all of glibc at 
> once.)

Then if it were me I'd just leave out the SETUP_GP* cases in the first
patch and leave them for after the blocking issues were cleared out in
further incremental changes.


Thanks,
Roland

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Add CFI information for MIPS assembly sources
  2013-02-08  0:47     ` Roland McGrath
@ 2013-02-08  1:06       ` Joseph S. Myers
  0 siblings, 0 replies; 10+ messages in thread
From: Joseph S. Myers @ 2013-02-08  1:06 UTC (permalink / raw)
  To: Roland McGrath; +Cc: libc-ports, macro

On Thu, 7 Feb 2013, Roland McGrath wrote:

> > Unfortunately sys/asm.h is an installed header implementing some 
> > externally-defined SGI API, but also used internally in glibc for various 
> > things.  So the CFI in start/end of function macros there is using 
> > implementation-namespace __mips_cfi_* macros (existing practice for other 
> > architectures being to put CFI in the start/end of function macros), 
> > defined conditionally on _LIBC, and any variation on SETUP_GP64 would I 
> > suppose also need to be in the implementation namespace or conditioned on 
> > _LIBC.  (For a non-architecture-specific header you might have an internal 
> > include/sys/asm.h for internal macros, but that's not an option here.  Or 
> > put the variants in sysdep.h, but that's separating macros from 
> > closely-related other macros.)
> 
> For other similar reasons I've been considering supporting
> sysdeps/.../include/ directories.  Those would be in the -I list for
> building libc, but not in sysdirs and so not candidates for installation.
> I can do the makefile hackery if you'd like to use that.

I agree such directories would be useful for handling the sys/asm.h 
changes more cleanly.

> Then if it were me I'd just leave out the SETUP_GP* cases in the first
> patch and leave them for after the blocking issues were cleared out in
> further incremental changes.

I'd rather not have too much inaccurate / incomplete CFI (as opposed to 
code with no CFI at all), although since none of the affected places are 
valid for throwing exceptions through, the effects are much the same as 
for no CFI (inaccurate register values in backtraces e.g. with GDB, in the 
gp cases).  (I think with this patch, CFI is present but incomplete / 
inaccurate only for __syscall_error and a few instructions in setcontext, 
but not for the lots of other functions that save and restore gp.)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Add CFI information for MIPS assembly sources
  2013-02-07 22:52 Add CFI information for MIPS assembly sources Joseph S. Myers
  2013-02-08  0:08 ` Roland McGrath
@ 2013-02-08 14:57 ` Maciej W. Rozycki
  2013-02-08 16:30   ` Joseph S. Myers
  2013-02-11 18:20 ` Joseph S. Myers
  2 siblings, 1 reply; 10+ messages in thread
From: Maciej W. Rozycki @ 2013-02-08 14:57 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: libc-ports

On Thu, 7 Feb 2013, Joseph S. Myers wrote:

> This patch adds CFI information to many of the assembly sources in
> MIPS glibc, similar to that for various other architectures, to
> support better backtracing through such code by various tools.
> 
> This is a start on adding such CFI information rather than a patch
> intended to add complete CFI information everywhere in the library.
> Specifically, the following are not covered but could be covered by a
> separate patch:
> 
> * Assembly sources used through inline asm in .c files (including some
> complete functions generated that way through inline asm).
> 
> * The SETUP_GPX* macros.
> 
> * The bit of setcontext.S after sp is set from the saved context and
> before the jump to that saved context.
> 
> * sysdeps/mips/start.S.
> 
> * sysdeps/unix/mips/sysdep.S.
> 
> For SETUP_GP64 and RESTORE_GP64, the cfi_* directives are in the
> individual .S files rather than the macro definitions because the
> macros can be used to save the old gp value in either a register or a
> stack slot, and those need different CFI directives, so a single macro
> SETUP_GP64 can't handle both cases and generate CFI at the same time.
> This does mean that various callers need to condition the use of CFI
> with these macro so no such CFI is generated in the o32 case when the
> GP64 macros expand to empty (this is of course only needed for those
> callers in .S files actually shared by o32 and non-o32 ABIs).
> Although the RESTORE_GP64 doesn't actually depend on where the value
> was saved, it seems better to be consistent and have the directives in
> the .S files in both cases, rather than just for SETUP_GP64.
> 
> Quite a few of the changes are simply making functions consistently
> use macros such as ENTRY and END at the start and end of the functions
> to generate the cfi_startproc / cfi_endproc directives.  Some changes
> to use ENTRY may have the effect of changing the .align directives
> (which were .align 4 in some cases, now more consistently .align 2),
> but I see no particular reason for the variation in those directives
> in the cases where macros were previously not used at
> start-of-function.
> 
> I plan to commit this patch subject to the results of testing that is
> currently running, but comments or corrections are welcome.

 Just three quick notes:

1. If I were the maintainer, I'd expect the change to convert sources to
   use ENTRY/END/etc. properly to be done separately, preferably before
   making changes to add CFI pieces so as not to obfuscate the actual 
   matter of this change.  It would make people easier to review this 
   change too.  Of course it's you who are the MIPS maintainer, so it's 
   just my opinion, you're free to do whatever you like there.

2. Given the implementation I fail to see the point of modifying
   <sys/asm.h> at all.  Yes, it saves a line here or there, but at the
   cost of non-standard semantics, some obfuscation, and then you need to
   place other CFI ops manually throughout functions concerned anyway.
   Not worth the complication in my opinion, I'd suggest placing all the
   CFI ops outside these macros in the functions handled.  It's a one-off
   effort anyway, we can require further assembly contributions to copy
   the ops from existing examples -- which is much easier once there are
   some actually in place.

3. On the other hand it may be worthwhile to avoid obfuscation like:

# if _MIPS_SIM != _ABIO32
	cfi_rel_offset (gp, GPOFF)
# endif

   and define a macro like mips_cfi_rel_offset64 (a better name may be
   possible, perhaps just cfi_rel_offset64) that'll handle the ABI 
   condition in the definition, pretty much like SETUP_GP64 does.  
   Likewise with complementing cfi_restore.

I've had a look through individual changes too, and with the concerns
above put aside they look good to me.  Thanks for your work on this
problem.

  Maciej

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Add CFI information for MIPS assembly sources
  2013-02-08 14:57 ` Maciej W. Rozycki
@ 2013-02-08 16:30   ` Joseph S. Myers
  2013-02-08 17:52     ` Maciej W. Rozycki
  0 siblings, 1 reply; 10+ messages in thread
From: Joseph S. Myers @ 2013-02-08 16:30 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: libc-ports

On Fri, 8 Feb 2013, Maciej W. Rozycki wrote:

> 1. If I were the maintainer, I'd expect the change to convert sources to
>    use ENTRY/END/etc. properly to be done separately, preferably before
>    making changes to add CFI pieces so as not to obfuscate the actual 
>    matter of this change.  It would make people easier to review this 
>    change too.  Of course it's you who are the MIPS maintainer, so it's 
>    just my opinion, you're free to do whatever you like there.

I have committed this part separately.

> 2. Given the implementation I fail to see the point of modifying
>    <sys/asm.h> at all.  Yes, it saves a line here or there, but at the
>    cost of non-standard semantics, some obfuscation, and then you need to

Standard semantics in glibc are that cfi_startproc and cfi_endproc go in 
the macros used to define the start and end of functions, rather than in 
the .S files using those macros (except in special cases where it's 
necessary to avoid CFI covering part of a function, e.g. for clone).

Roland's addition of a sysdeps/.../include mechanism should allow most of 
the internal macros to go in sysdeps/mips/include/sys/asm.h rather than 
the installed header, although some changes will still be needed to the 
installed header to add the use of __mips_cfi_* to the relevant macros.

> 3. On the other hand it may be worthwhile to avoid obfuscation like:
> 
> # if _MIPS_SIM != _ABIO32
> 	cfi_rel_offset (gp, GPOFF)
> # endif
> 
>    and define a macro like mips_cfi_rel_offset64 (a better name may be
>    possible, perhaps just cfi_rel_offset64) that'll handle the ABI 
>    condition in the definition, pretty much like SETUP_GP64 does.  
>    Likewise with complementing cfi_restore.

SETUP_GP64_REG and SETUP_GP64_STACK (and similar RESTORE_GP64_*) are what 
I'm thinking of for include/sys/asm.h (the internal header) to combine the 
calls to the existing macros with providing CFI information.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Add CFI information for MIPS assembly sources
  2013-02-08 16:30   ` Joseph S. Myers
@ 2013-02-08 17:52     ` Maciej W. Rozycki
  2013-02-08 21:11       ` Joseph S. Myers
  0 siblings, 1 reply; 10+ messages in thread
From: Maciej W. Rozycki @ 2013-02-08 17:52 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: libc-ports

On Fri, 8 Feb 2013, Joseph S. Myers wrote:

> > 1. If I were the maintainer, I'd expect the change to convert sources to
> >    use ENTRY/END/etc. properly to be done separately, preferably before
> >    making changes to add CFI pieces so as not to obfuscate the actual 
> >    matter of this change.  It would make people easier to review this 
> >    change too.  Of course it's you who are the MIPS maintainer, so it's 
> >    just my opinion, you're free to do whatever you like there.
> 
> I have committed this part separately.

 Thanks.

> > 2. Given the implementation I fail to see the point of modifying
> >    <sys/asm.h> at all.  Yes, it saves a line here or there, but at the
> >    cost of non-standard semantics, some obfuscation, and then you need to
> 
> Standard semantics in glibc are that cfi_startproc and cfi_endproc go in 
> the macros used to define the start and end of functions, rather than in 
> the .S files using those macros (except in special cases where it's 
> necessary to avoid CFI covering part of a function, e.g. for clone).
> 
> Roland's addition of a sysdeps/.../include mechanism should allow most of 
> the internal macros to go in sysdeps/mips/include/sys/asm.h rather than 
> the installed header, although some changes will still be needed to the 
> installed header to add the use of __mips_cfi_* to the relevant macros.

 Hmm, this overall sounds like a good idea to me, however I still feel a 
bit uneasy about fiddling with these standard (as far as MIPS usage is 
concerned) macros in a publicly installed header.  At the same time I 
realise the semantics of the C preprocessor language makes it difficult to 
overload macros without pasting the same body over and over again.

 However it should be possible to wrap the macros into other ones by using 
a different name.  This way the public macros would remain intact (yes, I 
do have a concern as to the consistency of <sys/asm.h> vs <asm/asm.h> -- 
they share a common ancestor, they provide abstract definitions that have 
nothing to do specifically with userland or Linux kernel code and are both 
meant to serve the same purpose, so the fewer divergences the better), 
e.g.

#define _LIBC_LEAF(symbol)	\
  LEAF (symbol)			\
  cfi_startproc

(or perhaps call it _CFI_LEAF instead?).  What do you think?  Likewise the 
others, and...

> > 3. On the other hand it may be worthwhile to avoid obfuscation like:
> > 
> > # if _MIPS_SIM != _ABIO32
> > 	cfi_rel_offset (gp, GPOFF)
> > # endif
> > 
> >    and define a macro like mips_cfi_rel_offset64 (a better name may be
> >    possible, perhaps just cfi_rel_offset64) that'll handle the ABI 
> >    condition in the definition, pretty much like SETUP_GP64 does.  
> >    Likewise with complementing cfi_restore.
> 
> SETUP_GP64_REG and SETUP_GP64_STACK (and similar RESTORE_GP64_*) are what 
> I'm thinking of for include/sys/asm.h (the internal header) to combine the 
> calls to the existing macros with providing CFI information.

 ... that would solve the issue of these macros as well.

  Maciej

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Add CFI information for MIPS assembly sources
  2013-02-08 17:52     ` Maciej W. Rozycki
@ 2013-02-08 21:11       ` Joseph S. Myers
  0 siblings, 0 replies; 10+ messages in thread
From: Joseph S. Myers @ 2013-02-08 21:11 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: libc-ports

On Fri, 8 Feb 2013, Maciej W. Rozycki wrote:

>  However it should be possible to wrap the macros into other ones by using 
> a different name.  This way the public macros would remain intact (yes, I 
> do have a concern as to the consistency of <sys/asm.h> vs <asm/asm.h> -- 
> they share a common ancestor, they provide abstract definitions that have 
> nothing to do specifically with userland or Linux kernel code and are both 
> meant to serve the same purpose, so the fewer divergences the better), 
> e.g.
> 
> #define _LIBC_LEAF(symbol)	\
>   LEAF (symbol)			\
>   cfi_startproc
> 
> (or perhaps call it _CFI_LEAF instead?).  What do you think?  Likewise the 
> others, and...

I don't think having yet more macros for start and end of functions would 
be an improvement; it seems clearly better for functions to use END where 
possible, in particular, and that's in both sys/asm.h and sysdep.h (and 
while the definitions are such that the one in sysdep.h would take 
precedence if both are included, having different definitions of the same 
macro in those two headers would seem just too confusing).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Add CFI information for MIPS assembly sources
  2013-02-07 22:52 Add CFI information for MIPS assembly sources Joseph S. Myers
  2013-02-08  0:08 ` Roland McGrath
  2013-02-08 14:57 ` Maciej W. Rozycki
@ 2013-02-11 18:20 ` Joseph S. Myers
  2 siblings, 0 replies; 10+ messages in thread
From: Joseph S. Myers @ 2013-02-11 18:20 UTC (permalink / raw)
  To: libc-ports; +Cc: macro

This is the version I've committed, which uses new macros in a new
sysdeps/mips/include/sys/asm.h header to combine GP saves and restores
(separately for the stack and register cases) with associated CFI
information and avoid the need for _MIPS_SIM conditionals for that CFI
information in individual .S files.

2013-02-11  Joseph Myers  <joseph@codesourcery.com>

	* sysdeps/mips/include/sys/asm.h: New file.
	* sysdeps/mips/mips64/bsd-_setjmp.S (_setjmp): Use SETUP_GP64_REG
	and RESTORE_GP64_REG.
	* sysdeps/mips/mips64/bsd-setjmp.S (setjmp): Likewise.
	* sysdeps/mips/mips64/setjmp.S (__sigsetjmp): Likewise.
	* sysdeps/mips/sys/asm.h (__mips_cfi_startproc): Define to empty.
	(__mips_cfi_endproc): Likewise.
	(LEAF): Use __mips_cfi_startproc.
	(NESTED): Likewise.
	(END): Use __mips_cfi_endproc.
	(EXPORT): Use __mips_cfi_startproc.
	* sysdeps/unix/mips/mips32/sysdep.h (PSEUDO): Add CFI information
	for error-handling code in both definitions.
	* sysdeps/unix/mips/mips64/n32/sysdep.h (PSEUDO): Likewise.
	* sysdeps/unix/mips/mips64/n64/sysdep.h (PSEUDO): Likewise.
	* sysdeps/unix/mips/sysdep.h (ENTRY): Use cfi_startproc.
	(END): Use cfi_endproc.
	(PSEUDO_END): Likewise.
	(PSEUDO_END_NOERRNO): Likewise.
	(PSEUDO_END_ERRVAL): Likewise.
	* sysdeps/unix/sysv/linux/mips/clone.S (__clone): Add CFI
	information.  Use SETUP_GP64_STACK and RESTORE_GP64_STACK.
	* sysdeps/unix/sysv/linux/mips/getcontext.S (__getcontext):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/makecontext.S (__makecontext):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S (__ioctl): Use
	SETUP_GP64_REG and RESTORE_GP64_REG.
	* sysdeps/unix/sysv/linux/mips/mips64/nptl/sysdep-cancel.h
	[(!NOT_IN_libc || IS_IN_libpthread || IS_IN_librt) && __PIC__]
	(PSEUDO): Use cfi_endproc before ENTRY.
	* sysdeps/unix/sysv/linux/mips/mips64/syscall.S (syscall): Add CFI
	information.  Use SETUP_GP64_REG and RESTORE_GP64_REG.
	* sysdeps/unix/sysv/linux/mips/nptl/sysdep-cancel.h [(!NOT_IN_libc
	|| IS_IN_libpthread || IS_IN_librt) && __PIC__] (PSEUDO): Use
	cfi_endproc before ENTRY.
	* sysdeps/unix/sysv/linux/mips/setcontext.S (__setcontext): Add
	CFI information.  Use SETUP_GP64_STACK and RESTORE_GP64_STACK.
	* sysdeps/unix/sysv/linux/mips/swapcontext.S (__swapcontext):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/vfork.S (__vfork): Add CFI
	information.  Use SETUP_GP64_REG and RESTORE_GP64_REG.

diff --git a/ports/sysdeps/mips/include/sys/asm.h b/ports/sysdeps/mips/include/sys/asm.h
new file mode 100644
index 0000000..7b356e1
--- /dev/null
+++ b/ports/sysdeps/mips/include/sys/asm.h
@@ -0,0 +1,53 @@
+/* Copyright (C) 2013 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _SYS_ASM_H
+
+# include_next <sys/asm.h>
+
+# undef __mips_cfi_startproc
+# define __mips_cfi_startproc cfi_startproc
+# undef __mips_cfi_endproc
+# define __mips_cfi_endproc cfi_endproc
+
+# if _MIPS_SIM == _ABIO32
+#  define SETUP_GP64_REG_CFI(a)
+#  define SETUP_GP64_REG(a, b)
+#  define SETUP_GP64_STACK_CFI(a)
+#  define SETUP_GP64_STACK(a, b)
+#  define RESTORE_GP64_REG
+#  define RESTORE_GP64_STACK
+# else
+#  define SETUP_GP64_REG_CFI(gpsavereg)		\
+	cfi_register (gp, gpsavereg)
+#  define SETUP_GP64_REG(gpsavereg, proc)	\
+	SETUP_GP64 (gpsavereg, proc);		\
+	SETUP_GP64_REG_CFI (gpsavereg)
+#  define SETUP_GP64_STACK_CFI(gpoffset)	\
+	cfi_rel_offset (gp, gpoffset)
+#  define SETUP_GP64_STACK(gpoffset, proc)	\
+	SETUP_GP64 (gpoffset, proc);		\
+	SETUP_GP64_STACK_CFI (gpoffset)
+#  define RESTORE_GP64_REG			\
+	RESTORE_GP64;				\
+	cfi_restore (gp)
+#  define RESTORE_GP64_STACK			\
+	RESTORE_GP64;				\
+	cfi_restore (gp)
+# endif
+
+#endif
diff --git a/ports/sysdeps/mips/mips64/bsd-_setjmp.S b/ports/sysdeps/mips/mips64/bsd-_setjmp.S
index 83b1264..5d0f76c 100644
--- a/ports/sysdeps/mips/mips64/bsd-_setjmp.S
+++ b/ports/sysdeps/mips/mips64/bsd-_setjmp.S
@@ -31,12 +31,12 @@ ENTRY (_setjmp)
 #ifdef __PIC__
 	SETUP_GP
 #endif
-	SETUP_GP64 (v0, C_SYMBOL_NAME (_setjmp))
+	SETUP_GP64_REG (v0, C_SYMBOL_NAME (_setjmp))
 	PTR_LA t9, C_SYMBOL_NAME (__sigsetjmp)
 #if _MIPS_SIM == _ABIO32
 	nop
 #endif	
-	RESTORE_GP64
+	RESTORE_GP64_REG
 	move	a1, zero		/* Pass a second argument of zero.  */
 #ifdef __PIC__
 	jr	t9
diff --git a/ports/sysdeps/mips/mips64/bsd-setjmp.S b/ports/sysdeps/mips/mips64/bsd-setjmp.S
index 15af26a..784e16e 100644
--- a/ports/sysdeps/mips/mips64/bsd-setjmp.S
+++ b/ports/sysdeps/mips/mips64/bsd-setjmp.S
@@ -31,12 +31,12 @@ ENTRY (setjmp)
 #ifdef __PIC__
 	SETUP_GP
 #endif
-	SETUP_GP64 (v0, C_SYMBOL_NAME (setjmp))
+	SETUP_GP64_REG (v0, C_SYMBOL_NAME (setjmp))
 	PTR_LA t9, C_SYMBOL_NAME (__sigsetjmp)
 #if _MIPS_SIM == _ABIO32
 	nop
 #endif	
-	RESTORE_GP64
+	RESTORE_GP64_REG
 	dli a1, 1		/* Pass a second argument of one.  */
 #ifdef __PIC__
 	jr	t9
diff --git a/ports/sysdeps/mips/mips64/setjmp.S b/ports/sysdeps/mips/mips64/setjmp.S
index 621e390..5afbbe7 100644
--- a/ports/sysdeps/mips/mips64/setjmp.S
+++ b/ports/sysdeps/mips/mips64/setjmp.S
@@ -29,14 +29,14 @@ ENTRY (__sigsetjmp)
 #ifdef __PIC__
 	SETUP_GP
 #endif
-	SETUP_GP64 (v0, C_SYMBOL_NAME (__sigsetjmp))
+	SETUP_GP64_REG (v0, C_SYMBOL_NAME (__sigsetjmp))
 	move a2, sp
 	move a3, fp
 	PTR_LA t9, __sigsetjmp_aux
 #if _MIPS_SIM == _ABIO32
 	nop
 #endif	
-	RESTORE_GP64
+	RESTORE_GP64_REG
 #if _MIPS_SIM != _ABIO32
 	move a4, gp
 #endif
diff --git a/ports/sysdeps/mips/sys/asm.h b/ports/sysdeps/mips/sys/asm.h
index 605451a..293cf36 100644
--- a/ports/sysdeps/mips/sys/asm.h
+++ b/ports/sysdeps/mips/sys/asm.h
@@ -26,6 +26,10 @@
 # define CAT(str1,str2) __CAT(str1,str2)
 #endif
 
+/* Redefined as nonempty in the internal header.  */
+#define __mips_cfi_startproc /* Empty.  */
+#define __mips_cfi_endproc /* Empty.  */
+
 /*
  * Macros to handle different pointer/register sizes for 32/64-bit code
  *
@@ -147,7 +151,8 @@ l:							\
 		.align	2;                              \
 		.type	symbol,@function;               \
 		.ent	symbol,0;                       \
-symbol:		.frame	sp,0,ra
+symbol:		.frame	sp,0,ra;			\
+		__mips_cfi_startproc
 
 /*
  * NESTED - declare nested routine entry point
@@ -157,13 +162,15 @@ symbol:		.frame	sp,0,ra
 		.align	2;                              \
 		.type	symbol,@function;               \
 		.ent	symbol,0;                       \
-symbol:		.frame	sp, framesize, rpc
+symbol:		.frame	sp, framesize, rpc;		\
+		__mips_cfi_startproc
 
 /*
  * END - mark end of function
  */
 #ifndef END
 # define END(function)                                   \
+		__mips_cfi_endproc;			\
 		.end	function;		        \
 		.size	function,.-function
 #endif
@@ -173,7 +180,7 @@ symbol:		.frame	sp, framesize, rpc
  */
 #define	EXPORT(symbol)                                  \
 		.globl	symbol;                         \
-symbol:
+symbol:		__mips_cfi_startproc
 
 /*
  * ABS - export absolute symbol
diff --git a/ports/sysdeps/unix/mips/mips32/sysdep.h b/ports/sysdeps/unix/mips/mips32/sysdep.h
index d7d3892..5c5d769 100644
--- a/ports/sysdeps/unix/mips/mips32/sysdep.h
+++ b/ports/sysdeps/unix/mips/mips32/sysdep.h
@@ -24,8 +24,10 @@
 #ifdef __PIC__
 #define PSEUDO(name, syscall_name, args) \
   .align 2;								      \
+  cfi_startproc;							      \
   99: la t9,__syscall_error;						      \
   jr t9;								      \
+  cfi_endproc;								      \
   ENTRY(name)								      \
   .set noreorder;							      \
   .cpload t9;								      \
@@ -38,8 +40,10 @@ L(syse1):
 #define PSEUDO(name, syscall_name, args) \
   .set noreorder;							      \
   .align 2;								      \
+  cfi_startproc;							      \
   99: j __syscall_error;						      \
   nop;									      \
+  cfi_endproc;								      \
   ENTRY(name)								      \
   .set noreorder;							      \
   li v0, SYS_ify(syscall_name);						      \
diff --git a/ports/sysdeps/unix/mips/mips64/n32/sysdep.h b/ports/sysdeps/unix/mips/mips64/n32/sysdep.h
index 37a67a2..49ae769 100644
--- a/ports/sysdeps/unix/mips/mips64/n32/sysdep.h
+++ b/ports/sysdeps/unix/mips/mips64/n32/sysdep.h
@@ -26,13 +26,17 @@
 #ifdef __PIC__
 #define PSEUDO(name, syscall_name, args) \
   .align 2;								      \
+  cfi_startproc;							      \
   99:;									      \
   .set noat;								      \
   .cpsetup t9, $1, name;						      \
+  cfi_register (gp, $1);						      \
   .set at;								      \
   la t9,__syscall_error;						      \
   .cpreturn;								      \
+  cfi_restore (gp);							      \
   jr t9;								      \
+  cfi_endproc;								      \
   ENTRY(name)								      \
   li v0, SYS_ify(syscall_name);						      \
   syscall;								      \
@@ -42,8 +46,10 @@ L(syse1):
 #define PSEUDO(name, syscall_name, args) \
   .set noreorder;							      \
   .align 2;								      \
+  cfi_startproc;							      \
   99: j __syscall_error;						      \
   nop;                                                                        \
+  cfi_endproc;								      \
   ENTRY(name)								      \
   .set noreorder;							      \
   li v0, SYS_ify(syscall_name);						      \
diff --git a/ports/sysdeps/unix/mips/mips64/n64/sysdep.h b/ports/sysdeps/unix/mips/mips64/n64/sysdep.h
index 871184b..2670c68 100644
--- a/ports/sysdeps/unix/mips/mips64/n64/sysdep.h
+++ b/ports/sysdeps/unix/mips/mips64/n64/sysdep.h
@@ -26,13 +26,17 @@
 #ifdef __PIC__
 #define PSEUDO(name, syscall_name, args) \
   .align 2;								      \
+  cfi_startproc;							      \
   99:;									      \
   .set noat;								      \
   .cpsetup t9, $1, name;						      \
+  cfi_register (gp, $1);						      \
   .set at;								      \
   dla t9,__syscall_error;						      \
   .cpreturn;								      \
+  cfi_restore (gp);							      \
   jr t9;								      \
+  cfi_endproc;								      \
   ENTRY(name)								      \
   li v0, SYS_ify(syscall_name);						      \
   syscall;								      \
@@ -42,8 +46,10 @@ L(syse1):
 #define PSEUDO(name, syscall_name, args) \
   .set noreorder;							      \
   .align 2;								      \
+  cfi_startproc;							      \
   99: j __syscall_error;						      \
   nop;                                                                        \
+  cfi_endproc;								      \
   ENTRY(name)								      \
   .set noreorder;							      \
   li v0, SYS_ify(syscall_name);						      \
diff --git a/ports/sysdeps/unix/mips/sysdep.h b/ports/sysdeps/unix/mips/sysdep.h
index bab3bc0..ef5c089 100644
--- a/ports/sysdeps/unix/mips/sysdep.h
+++ b/ports/sysdeps/unix/mips/sysdep.h
@@ -27,17 +27,19 @@
   .globl name;								      \
   .align 2;								      \
   .ent name,0;								      \
-  name##:
+  name##:								      \
+  cfi_startproc;
 
 #undef END
 #define	END(function)                                   \
+		cfi_endproc;				\
 		.end	function;		        \
 		.size	function,.-function
 
 #define ret	j ra ; nop
 
 #undef PSEUDO_END
-#define PSEUDO_END(sym) .end sym; .size sym,.-sym
+#define PSEUDO_END(sym) cfi_endproc; .end sym; .size sym,.-sym
 
 #define PSEUDO_NOERRNO(name, syscall_name, args)	\
   .align 2;						\
@@ -47,7 +49,7 @@
   syscall
 
 #undef PSEUDO_END_NOERRNO
-#define PSEUDO_END_NOERRNO(sym) .end sym; .size sym,.-sym
+#define PSEUDO_END_NOERRNO(sym) cfi_endproc; .end sym; .size sym,.-sym
 
 #define ret_NOERRNO ret
 
@@ -59,7 +61,7 @@
   syscall
 
 #undef PSEUDO_END_ERRVAL
-#define PSEUDO_END_ERRVAL(sym) .end sym; .size sym,.-sym
+#define PSEUDO_END_ERRVAL(sym) cfi_endproc; .end sym; .size sym,.-sym
 
 #define ret_ERRVAL ret
 
diff --git a/ports/sysdeps/unix/sysv/linux/mips/clone.S b/ports/sysdeps/unix/sysv/linux/mips/clone.S
index 72360f9..ef80188 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/clone.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/clone.S
@@ -47,7 +47,8 @@ NESTED(__clone,4*SZREG,sp)
 	SETUP_GP
 #endif
 	PTR_SUBU sp, FRAMESZ
-	SETUP_GP64 (GPOFF, __clone)
+	cfi_adjust_cfa_offset (FRAMESZ)
+	SETUP_GP64_STACK (GPOFF, __clone)
 #ifdef __PIC__
 	SAVE_GP (GPOFF)
 #endif
@@ -88,26 +89,35 @@ NESTED(__clone,4*SZREG,sp)
 
 	/* Do the system call */
 	li		v0,__NR_clone
+	cfi_endproc
 	syscall
 
 	bnez		a3,L(error)
 	beqz		v0,L(thread_start)
 
 	/* Successful return from the parent */
-	RESTORE_GP64
+	cfi_startproc
+	cfi_adjust_cfa_offset (FRAMESZ)
+	SETUP_GP64_STACK_CFI (GPOFF)
+	cfi_remember_state
+	RESTORE_GP64_STACK
 	PTR_ADDU	sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 	ret
 
 	/* Something bad happened -- no child created */
 L(error):
+	cfi_restore_state
 #ifdef __PIC__
 	PTR_LA		t9,__syscall_error
-	RESTORE_GP64
+	RESTORE_GP64_STACK
 	PTR_ADDU	sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 	jr		t9
 #else
-	RESTORE_GP64
+	RESTORE_GP64_STACK
 	PTR_ADDU	sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 	j		__syscall_error
 #endif
 	END(__clone)
@@ -118,6 +128,7 @@ L(error):
 
 ENTRY(__thread_start)
 L(thread_start):
+	cfi_undefined ($31)
 	/* cp is already loaded.  */
 	SAVE_GP (GPOFF)
 	/* The stackframe has been created on entry of clone().  */
diff --git a/ports/sysdeps/unix/sysv/linux/mips/getcontext.S b/ports/sysdeps/unix/sysv/linux/mips/getcontext.S
index 0e3d35b..7af6825 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/getcontext.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/getcontext.S
@@ -54,7 +54,8 @@ NESTED (__getcontext, FRAMESZ, ra)
 # endif
 
 	PTR_ADDIU sp, -FRAMESZ
-	SETUP_GP64 (GPOFF, __getcontext)
+	cfi_adjust_cfa_offset (FRAMESZ)
+	SETUP_GP64_STACK (GPOFF, __getcontext)
 	SAVE_GP (GPOFF)
 
 #else  /* ! __PIC__ */
@@ -124,19 +125,23 @@ NESTED (__getcontext, FRAMESZ, ra)
 	li	v0, SYS_ify (rt_sigprocmask)
 	syscall
 	bnez	a3, 99f
+	cfi_remember_state
 
 #ifdef __PIC__
-	RESTORE_GP64
+	RESTORE_GP64_STACK
 	PTR_ADDIU sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 #endif
 	move	v0, zero
 	jr	ra
 
 99:
+	cfi_restore_state
 #ifdef __PIC__
 	PTR_LA	t9, JUMPTARGET (__syscall_error)
-	RESTORE_GP64
+	RESTORE_GP64_STACK
 	PTR_ADDIU sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 	jr	t9
 
 #else  /* ! __PIC__ */
diff --git a/ports/sysdeps/unix/sysv/linux/mips/makecontext.S b/ports/sysdeps/unix/sysv/linux/mips/makecontext.S
index 65f1a6a..d89db01 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/makecontext.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/makecontext.S
@@ -63,9 +63,10 @@ NESTED (__makecontext, FRAMESZ, ra)
 #endif
 
 	PTR_ADDIU sp, -FRAMESZ
+	cfi_adjust_cfa_offset (FRAMESZ)
 
 #ifdef __PIC__
-	SETUP_GP64 (GPOFF, __makecontext)
+	SETUP_GP64_STACK (GPOFF, __makecontext)
 	SAVE_GP (GPOFF)
 #endif
 
@@ -145,8 +146,9 @@ NESTED (__makecontext, FRAMESZ, ra)
 	REG_S	a1, MCONTEXT_PC(a0)
 
 #ifdef __PIC__
-	RESTORE_GP64
+	RESTORE_GP64_STACK
 	PTR_ADDIU sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 #endif
 	jr	ra
 
diff --git a/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S b/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S
index b3bed46..c5f1c35 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S
@@ -31,9 +31,9 @@ ENTRY (__ioctl)
 	ret
 
 L(error):
-	SETUP_GP64 (a0, __ioctl)
+	SETUP_GP64_REG (a0, __ioctl)
 	PTR_LA t9, __syscall_error
-	RESTORE_GP64
+	RESTORE_GP64_REG
 	jr t9
 
 PSEUDO_END (__ioctl)
diff --git a/ports/sysdeps/unix/sysv/linux/mips/mips64/nptl/sysdep-cancel.h b/ports/sysdeps/unix/sysv/linux/mips/mips64/nptl/sysdep-cancel.h
index 354eba2..6565225 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/mips64/nptl/sysdep-cancel.h
+++ b/ports/sysdeps/unix/sysv/linux/mips/mips64/nptl/sysdep-cancel.h
@@ -57,6 +57,7 @@
     cfi_same_value (gp);						      \
     RESTORESTK;								      \
     ret;								      \
+    cfi_endproc;							      \
   .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
   ENTRY (name)								      \
     SAVESTK;								      \
diff --git a/ports/sysdeps/unix/sysv/linux/mips/mips64/syscall.S b/ports/sysdeps/unix/sysv/linux/mips/mips64/syscall.S
index 839276d..850025c 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/mips64/syscall.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/mips64/syscall.S
@@ -30,7 +30,9 @@ NESTED (syscall, SZREG, ra)
 	.mask 0x00010000, -SZREG
 	.fmask 0x00000000, 0
 	PTR_ADDIU sp, -SZREG
+	cfi_adjust_cfa_offset (SZREG)
 	REG_S s0, (sp)
+	cfi_rel_offset (s0, 0)
 
 	move s0, a0
 	move a0, a1		/* shift arg1 - arg7.  */
@@ -45,15 +47,17 @@ NESTED (syscall, SZREG, ra)
 	syscall			/* Do the system call.  */
 
 	REG_L s0, (sp)
+	cfi_restore (s0)
 	PTR_ADDIU sp, SZREG
+	cfi_adjust_cfa_offset (-SZREG)
 	bne a3, zero, L(error)
 
 	ret
 
 L(error):
-	SETUP_GP64 (a0, syscall)
+	SETUP_GP64_REG (a0, syscall)
 	PTR_LA t9, __syscall_error
-	RESTORE_GP64
+	RESTORE_GP64_REG
 	jr t9
 
 END (syscall)
diff --git a/ports/sysdeps/unix/sysv/linux/mips/nptl/sysdep-cancel.h b/ports/sysdeps/unix/sysv/linux/mips/nptl/sysdep-cancel.h
index e1dd672..1e0bfed 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/nptl/sysdep-cancel.h
+++ b/ports/sysdeps/unix/sysv/linux/mips/nptl/sysdep-cancel.h
@@ -52,6 +52,7 @@
     .set reorder;							      \
     bne a3, zero, 99b;					       		      \
     ret;								      \
+    cfi_endproc;							      \
   .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
   ENTRY (name)								      \
     .set noreorder;							      \
diff --git a/ports/sysdeps/unix/sysv/linux/mips/setcontext.S b/ports/sysdeps/unix/sysv/linux/mips/setcontext.S
index 42f709d..6ed355c 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/setcontext.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/setcontext.S
@@ -56,9 +56,10 @@ NESTED (__setcontext, FRAMESZ, ra)
 #endif
 
 	PTR_ADDIU sp, -FRAMESZ
+	cfi_adjust_cfa_offset (FRAMESZ)
 
 #ifdef __PIC__
-	SETUP_GP64 (GPOFF, __setcontext)
+	SETUP_GP64_STACK (GPOFF, __setcontext)
 	SAVE_GP (GPOFF)
 #endif
 
@@ -152,6 +153,7 @@ NESTED (__setcontext, FRAMESZ, ra)
 	   and call the signal return syscall as if a signal
 	   handler exited normally.  */
 	PTR_ADDIU sp, -((RT_SIGFRAME_SIZE + ALSZ) & ALMASK)
+	cfi_adjust_cfa_offset ((RT_SIGFRAME_SIZE + ALSZ) & ALMASK)
 
 	/* Only ucontext is referred to from rt_sigreturn,
 	   copy it.  */
@@ -175,11 +177,13 @@ NESTED (__setcontext, FRAMESZ, ra)
 	   path.  Successful rt_sigreturn never returns to
 	   its calling place.  */
 	PTR_ADDIU sp, ((RT_SIGFRAME_SIZE + ALSZ) & ALMASK)
+	cfi_adjust_cfa_offset (-((RT_SIGFRAME_SIZE + ALSZ) & ALMASK))
 99:
 #ifdef __PIC__
 	PTR_LA	t9, JUMPTARGET (__syscall_error)
-	RESTORE_GP64
+	RESTORE_GP64_STACK
 	PTR_ADDIU sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 	jr	t9
 
 #else  /* ! __PIC__ */
diff --git a/ports/sysdeps/unix/sysv/linux/mips/swapcontext.S b/ports/sysdeps/unix/sysv/linux/mips/swapcontext.S
index d965f39..ddd3b28 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/swapcontext.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/swapcontext.S
@@ -63,7 +63,8 @@ NESTED (__swapcontext, FRAMESZ, ra)
 # endif
 
 	PTR_ADDIU sp, -FRAMESZ
-	SETUP_GP64 (GPOFF, __swapcontext)
+	cfi_adjust_cfa_offset (FRAMESZ)
+	SETUP_GP64_STACK (GPOFF, __swapcontext)
 	SAVE_GP (GPOFF)
 
 #else  /* ! __PIC__ */
@@ -198,8 +199,9 @@ NESTED (__swapcontext, FRAMESZ, ra)
 99:
 #ifdef __PIC__
 	PTR_LA	t9, JUMPTARGET (__syscall_error)
-	RESTORE_GP64
+	RESTORE_GP64_STACK
 	PTR_ADDIU sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 	jr	t9
 
 #else  /* ! __PIC__ */
diff --git a/ports/sysdeps/unix/sysv/linux/mips/vfork.S b/ports/sysdeps/unix/sysv/linux/mips/vfork.S
index b9503c3..d627923 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/vfork.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/vfork.S
@@ -42,7 +42,8 @@ NESTED(__vfork,FRAMESZ,sp)
 	SETUP_GP
 #endif
 	PTR_SUBU sp, FRAMESZ
-	SETUP_GP64 (a5, __vfork)
+	cfi_adjust_cfa_offset (FRAMESZ)
+	SETUP_GP64_REG (a5, __vfork)
 #ifdef __PIC__
 	SAVE_GP (GPOFF)
 #endif
@@ -63,6 +64,7 @@ NESTED(__vfork,FRAMESZ,sp)
 #endif
 
 	PTR_ADDU	sp, FRAMESZ
+	cfi_adjust_cfa_offset (-FRAMESZ)
 
 	SAVE_PID
 
@@ -75,20 +77,22 @@ NESTED(__vfork,FRAMESZ,sp)
 
 	RESTORE_PID
 
+	cfi_remember_state
 	bnez		a3,L(error)
 
 	/* Successful return from the parent or child.  */
-	RESTORE_GP64
+	RESTORE_GP64_REG
 	ret
 
 	/* Something bad happened -- no child created.  */
 L(error):
+	cfi_restore_state
 #ifdef __PIC__
 	PTR_LA		t9, __syscall_error
-	RESTORE_GP64
+	RESTORE_GP64_REG
 	jr		t9
 #else
-	RESTORE_GP64
+	RESTORE_GP64_REG
 	j		__syscall_error
 #endif
 	END(__vfork)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-02-11 18:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-07 22:52 Add CFI information for MIPS assembly sources Joseph S. Myers
2013-02-08  0:08 ` Roland McGrath
2013-02-08  0:42   ` Joseph S. Myers
2013-02-08  0:47     ` Roland McGrath
2013-02-08  1:06       ` Joseph S. Myers
2013-02-08 14:57 ` Maciej W. Rozycki
2013-02-08 16:30   ` Joseph S. Myers
2013-02-08 17:52     ` Maciej W. Rozycki
2013-02-08 21:11       ` Joseph S. Myers
2013-02-11 18:20 ` Joseph S. Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).