Unwind annotations for the libc and libthr asm

From: Konstantin Belousov <kostikbel_at_gmail.com>
Date: Sun, 7 Oct 2012 18:20:05 +0300
Please find below the patch to add the unwind annotations for the libc
and libthr assembler routines on amd64. The change shall have no impact
on the execution of the changed code, because no functions there ever
generate C++ exception or call a function that could generate exception.

The addition of the annotations significantly improves the results of
the libunwind test suite on FreeBSD/amd64. We are still not on par with
Linux, mainly due to the lack of the unwind annotations for the signal
trampolines. Fixing this requires VDSO.

The addition of the annotations is rather tedious and unrelieved work,
so I am sure that there are left bugs. Bugs would affect both libunwind
and gdb, but what I see looks like a step forward anyway. Any comments ?

diff --git a/lib/libc/amd64/SYS.h b/lib/libc/amd64/SYS.h
index a232383..3101be5 100644
--- a/lib/libc/amd64/SYS.h
+++ b/lib/libc/amd64/SYS.h
_at__at_ -41,15 +41,25 _at__at_
 			.set CNAME(x),CNAME(__CONCAT(__sys_,x));	\
 			.weak CNAME(__CONCAT(_,x));			\
 			.set CNAME(__CONCAT(_,x)),CNAME(__CONCAT(__sys_,x)); \
-			mov __CONCAT($SYS_,x),%eax; KERNCALL;		\
-			jb HIDENAME(cerror); ret;			\
+			mov __CONCAT($SYS_,x),%eax;			\
+			.cfi_undefined %rax;				\
+			KERNCALL;					\
+			jb HIDENAME(cerror);				\
+			ret;						\
 			END(__CONCAT(__sys_,x))
 
 #define	PSEUDO(x)	ENTRY(__CONCAT(__sys_,x));			\
 			.weak CNAME(__CONCAT(_,x));			\
 			.set CNAME(__CONCAT(_,x)),CNAME(__CONCAT(__sys_,x)); \
-			mov __CONCAT($SYS_,x),%eax; KERNCALL;		\
-			jb HIDENAME(cerror); ret;			\
+			mov __CONCAT($SYS_,x),%eax;			\
+			.cfi_undefined %rax;				\
+			KERNCALL;					\
+			jb HIDENAME(cerror);				\
+			ret;						\
 			END(__CONCAT(__sys_,x))
 
-#define KERNCALL	movq %rcx, %r10; syscall
+#define KERNCALL	movq %rcx,%r10;					\
+			.cfi_undefined %r10;				\
+			.cfi_register %rcx,%r10;			\
+			syscall;					\
+			.cfi_undefined %rax,%rdx
diff --git a/lib/libc/amd64/gen/_setjmp.S b/lib/libc/amd64/gen/_setjmp.S
index 9035632..84cc0c9 100644
--- a/lib/libc/amd64/gen/_setjmp.S
+++ b/lib/libc/amd64/gen/_setjmp.S
_at__at_ -48,7 +48,9 _at__at_ __FBSDID("$FreeBSD$");
 
 ENTRY(_setjmp)
 	movq	%rdi,%rax
+	.cfi_register	%rdi,%rax
 	movq	0(%rsp),%rdx		/* retval */
+	.cfi_undefined	%rdx
 	movq	%rdx, 0(%rax)		/* 0; retval */
 	movq	%rbx, 8(%rax)		/* 1; rbx */
 	movq	%rsp,16(%rax)		/* 2; rsp */
_at__at_ -60,6 +62,7 _at__at_ ENTRY(_setjmp)
 	fnstcw	64(%rax)		/* 8; fpu cw */
 	stmxcsr	68(%rax)		/*    and mxcsr */
 	xorq	%rax,%rax
+	.cfi_undefined	%rax
 	ret
 END(_setjmp)
 
_at__at_ -67,17 +70,30 _at__at_ END(_setjmp)
 	.set	CNAME(_longjmp),CNAME(___longjmp)
 ENTRY(___longjmp)
 	movq	%rdi,%rdx
+	.cfi_undefined	%rdx
+	.cfi_register	%rdi,%rdx
 	/* Restore the mxcsr, but leave exception flags intact. */
 	stmxcsr	-4(%rsp)
 	movl	68(%rdx),%eax
+	.cfi_undefined	%rax
 	andl	$0xffffffc0,%eax
 	movl	-4(%rsp),%edi
+	.cfi_undefined	%rdi
 	andl	$0x3f,%edi
 	xorl	%eax,%edi
 	movl	%edi,-4(%rsp)
 	ldmxcsr -4(%rsp)
 	movq	%rsi,%rax		/* retval */
+	.cfi_def_cfa	%rdx,16
+	.cfi_offset	%rbx,8
+	.cfi_offset	%rbp,24
+	.cfi_offset	%r12,32
+	.cfi_offset	%r13,40
+	.cfi_offset	%r14,48
+	.cfi_offset	%r15,56
 	movq	0(%rdx),%rcx
+	.cfi_undefined	%rcx
+	.cfi_return_column %rcx
 	movq	8(%rdx),%rbx
 	movq	16(%rdx),%rsp
 	movq	24(%rdx),%rbp
diff --git a/lib/libc/amd64/gen/rfork_thread.S b/lib/libc/amd64/gen/rfork_thread.S
index 5e764db..9ce0484 100644
--- a/lib/libc/amd64/gen/rfork_thread.S
+++ b/lib/libc/amd64/gen/rfork_thread.S
_at__at_ -46,7 +46,11 _at__at_ __FBSDID("$FreeBSD$");
 
 ENTRY(rfork_thread)
 	pushq	%rbx
+	.cfi_adjust_cfa_offset 8
+	.cfi_offset	%rbx,-8
 	pushq	%r12
+	.cfi_adjust_cfa_offset 8
+	.cfi_offset	%r12,-16
 	movq	%rdx, %rbx
 	movq	%rcx, %r12
 
_at__at_ -63,7 +67,11 _at__at_ ENTRY(rfork_thread)
 	cmpl	$0, %edx
 	jnz	1f
 	popq	%r12
+	.cfi_adjust_cfa_offset -8
+	.cfi_restore %r12
 	popq	%rbx
+	.cfi_adjust_cfa_offset -8
+	.cfi_restore %rbx
 	ret
 
 	/*
_at__at_ -73,6 +81,7 _at__at_ ENTRY(rfork_thread)
 	 */
 1:
 	movq	%rsi, %rsp
+	.cfi_def_cfa_register	%rsi
 	movq	%r12, %rdi 
 	call	*%rbx
 	movl	%eax, %edi
_at__at_ -92,7 +101,11 _at__at_ ENTRY(rfork_thread)
 	 */
 2:
 	popq	%r12
+	.cfi_adjust_cfa_offset -8
+	.cfi_restore %r12
 	popq	%rbx
+	.cfi_adjust_cfa_offset -8
+	.cfi_restore %rbx
 	jmp	HIDENAME(cerror)
 END(rfork_thread)
 
diff --git a/lib/libc/amd64/gen/setjmp.S b/lib/libc/amd64/gen/setjmp.S
index 47772be..356d34c 100644
--- a/lib/libc/amd64/gen/setjmp.S
+++ b/lib/libc/amd64/gen/setjmp.S
_at__at_ -50,13 +50,21 _at__at_ __FBSDID("$FreeBSD$");
 
 ENTRY(setjmp)
 	pushq	%rdi
+	.cfi_adjust_cfa_offset 8
 	movq	%rdi,%rcx
+	.cfi_undefined	%rcx
+	.cfi_register	%rdi,%rcx
 	movq	$1,%rdi			/* SIG_BLOCK       */
+	.cfi_undefined	%rdi
 	movq	$0,%rsi			/* (sigset_t*)set  */
+	.cfi_undefined	%rsi
 	leaq	72(%rcx),%rdx		/* 9,10; (sigset_t*)oset */
+	.cfi_undefined	%rdx
 	/* stack is 16-byte aligned */
 	call	PIC_PLT(CNAME(_sigprocmask))
 	popq	%rdi
+	.cfi_adjust_cfa_offset -8
+	.cfi_restore	%rdi
 	movq	%rdi,%rcx
 	movq	0(%rsp),%rdx		/* retval */
 	movq	%rdx, 0(%rcx)		/* 0; retval */
_at__at_ -77,28 +85,51 _at__at_ END(setjmp)
 	.set CNAME(longjmp),CNAME(__longjmp)
 ENTRY(__longjmp)
 	pushq	%rdi
+	.cfi_adjust_cfa_offset 8
+	.cfi_offset	%rdi,-8
 	pushq	%rsi
+	.cfi_adjust_cfa_offset 8
+	.cfi_offset	%rsi,-16
 	movq	%rdi,%rdx
+	.cfi_undefined	%rdx
+	.cfi_register	%rdi,%rdx
 	movq	$3,%rdi			/* SIG_SETMASK     */
 	leaq	72(%rdx),%rsi		/* (sigset_t*)set  */
 	movq	$0,%rdx			/* (sigset_t*)oset */
 	subq	$0x8,%rsp		/* make the stack 16-byte aligned */
+	.cfi_adjust_cfa_offset 8
 	call	PIC_PLT(CNAME(_sigprocmask))
 	addq	$0x8,%rsp
+	.cfi_adjust_cfa_offset -8
 	popq	%rsi
+	.cfi_adjust_cfa_offset -8
+	.cfi_restore	%rsi
 	popq	%rdi			/* jmpbuf */
+	.cfi_adjust_cfa_offset -8
+	.cfi_restore	%rdi
 	movq	%rdi,%rdx
+	.cfi_register	%rdi,%rdx
 	/* Restore the mxcsr, but leave exception flags intact. */
 	stmxcsr	-4(%rsp)
 	movl	68(%rdx),%eax
 	andl	$0xffffffc0,%eax
 	movl	-4(%rsp),%edi
+	.cfi_undefined	%rdi
 	andl	$0x3f,%edi
 	xorl	%eax,%edi
 	movl	%edi,-4(%rsp)
 	ldmxcsr -4(%rsp)
 	movq	%rsi,%rax		/* retval */
+	.cfi_def_cfa	%rdx,16
+	.cfi_offset	%rbx,8
+	.cfi_offset	%rbp,24
+	.cfi_offset	%r12,32
+	.cfi_offset	%r13,40
+	.cfi_offset	%r14,48
+	.cfi_offset	%r15,56
 	movq	0(%rdx),%rcx
+	.cfi_undefined	%rcx
+	.cfi_return_column %rcx
 	movq	8(%rdx),%rbx
 	movq	16(%rdx),%rsp
 	movq	24(%rdx),%rbp
diff --git a/lib/libc/amd64/gen/sigsetjmp.S b/lib/libc/amd64/gen/sigsetjmp.S
index ef90bc6..c264740 100644
--- a/lib/libc/amd64/gen/sigsetjmp.S
+++ b/lib/libc/amd64/gen/sigsetjmp.S
_at__at_ -58,14 +58,22 _at__at_ ENTRY(sigsetjmp)
 	testl	%esi,%esi
 	jz	2f
 	pushq	%rdi
+	.cfi_adjust_cfa_offset -8
 	movq	%rdi,%rcx
+	.cfi_undefined	%rcx
+	.cfi_register	%rdi,%rcx
 	movq	$1,%rdi			/* SIG_BLOCK       */
 	movq	$0,%rsi			/* (sigset_t*)set  */
 	leaq	72(%rcx),%rdx		/* 9,10 (sigset_t*)oset */
+	.cfi_undefined	%rdx
 	/* stack is 16-byte aligned */
 	call	PIC_PLT(CNAME(_sigprocmask))
 	popq	%rdi
+	.cfi_adjust_cfa_offset 8
+	.cfi_restore	%rdi
 2:	movq	%rdi,%rcx
+	.cfi_undefined	%rcx
+	.cfi_register	%rdi,%rcx
 	movq	0(%rsp),%rdx		/* retval */
 	movq	%rdx, 0(%rcx)		/* 0; retval */
 	movq	%rbx, 8(%rcx)		/* 1; rbx */
_at__at_ -86,8 +94,14 _at__at_ ENTRY(__siglongjmp)
 	cmpl	$0,88(%rdi)
 	jz	2f
 	movq	%rdi,%rdx
+	.cfi_undefined	%rdx
+	.cfi_register	%rdi,%rdx
 	pushq	%rdi
+	.cfi_adjust_cfa_offset 8
+	.cfi_offset	%rdi,-8
 	pushq	%rsi
+	.cfi_adjust_cfa_offset 8
+	.cfi_offset	%rsi,-16
 	movq	$3,%rdi			/* SIG_SETMASK     */
 	leaq	72(%rdx),%rsi		/* (sigset_t*)set  */
 	movq	$0,%rdx			/* (sigset_t*)oset */
_at__at_ -95,10 +109,23 _at__at_ ENTRY(__siglongjmp)
 	call	PIC_PLT(CNAME(_sigprocmask))
 	addq	$0x8,%rsp
 	popq	%rsi
+	.cfi_adjust_cfa_offset -8
+	.cfi_restore	%rsi
 	popq	%rdi			/* jmpbuf */
+	.cfi_adjust_cfa_offset -8
+	.cfi_restore	%rdi
 2:	movq	%rdi,%rdx
 	movq	%rsi,%rax		/* retval */
+	.cfi_def_cfa	%rdx,16
+	.cfi_offset	%rbx,8
+	.cfi_offset	%rbp,24
+	.cfi_offset	%r12,32
+	.cfi_offset	%r13,40
+	.cfi_offset	%r14,48
+	.cfi_offset	%r15,56
 	movq	0(%rdx),%rcx
+	.cfi_undefined	%rcx
+	.cfi_return_column %rcx
 	movq	8(%rdx),%rbx
 	movq	16(%rdx),%rsp
 	movq	24(%rdx),%rbp
diff --git a/lib/libc/amd64/string/bcopy.S b/lib/libc/amd64/string/bcopy.S
index cc38f47..378cb45 100644
--- a/lib/libc/amd64/string/bcopy.S
+++ b/lib/libc/amd64/string/bcopy.S
_at__at_ -54,9 +54,12 _at__at_ ENTRY(bcopy)
 	movq	%rdi,%rax	/* return dst */
 #else
 	xchgq	%rdi,%rsi
+	.cfi_register	%rdi,%rsi
+	.cfi_register	%rsi,%rdi
 #endif
 	movq	%rdx,%rcx
 	movq	%rdi,%r8
+	.cfi_undefined	%r8
 	subq	%rsi,%r8
 	cmpq	%rcx,%r8	/* overlapping? */
 	jb	1f
_at__at_ -64,6 +67,8 _at__at_ ENTRY(bcopy)
 	shrq	$3,%rcx		/* copy by words */
 	rep
 	movsq
+	.cfi_undefined	%rdi
+	.cfi_undefined	%rsi
 	movq	%rdx,%rcx
 	andq	$7,%rcx		/* any bytes left? */
 	rep
_at__at_ -71,7 +76,9 _at__at_ ENTRY(bcopy)
 	ret
 1:
 	addq	%rcx,%rdi	/* copy backwards. */
+	.cfi_undefined	%rdi
 	addq	%rcx,%rsi
+	.cfi_undefined	%rsi
 	std
 	andq	$7,%rcx		/* any fractional bytes? */
 	decq	%rdi
diff --git a/lib/libc/amd64/string/bzero.S b/lib/libc/amd64/string/bzero.S
index cf46a2a..e2acb56 100644
--- a/lib/libc/amd64/string/bzero.S
+++ b/lib/libc/amd64/string/bzero.S
_at__at_ -27,6 +27,7 _at__at_ ENTRY(bzero)
 	negq	%rcx
 	andq	$7,%rcx
 	subq	%rcx,%rsi
+	.cfi_undefined	%rsi
 	rep				/* zero until word aligned */
 	stosb
 
diff --git a/lib/libc/amd64/string/memcmp.S b/lib/libc/amd64/string/memcmp.S
index 66d64a0..a794238 100644
--- a/lib/libc/amd64/string/memcmp.S
+++ b/lib/libc/amd64/string/memcmp.S
_at__at_ -17,6 +17,8 _at__at_ ENTRY(memcmp)
 	shrq	$3,%rcx
 	repe
 	cmpsq
+	.cfi_undefined	%rsi
+	.cfi_undefined	%rdi
 	jne	L5			/* do we match so far? */
 
 	movq	%rdx,%rcx		/* compare remainder by bytes */
diff --git a/lib/libc/amd64/string/memset.S b/lib/libc/amd64/string/memset.S
index 84d1562..bec8654 100644
--- a/lib/libc/amd64/string/memset.S
+++ b/lib/libc/amd64/string/memset.S
_at__at_ -16,6 +16,7 _at__at_ ENTRY(memset)
 	andq	$0xff,%rax
 	movq	%rdx,%rcx
 	movq	%rdi,%r11
+	.cfi_undefined	%r11
 
 	cld				/* set fill direction forward */
 
_at__at_ -45,6 +46,7 _at__at_ ENTRY(memset)
 	movq	%rdx,%rcx		/* set until word aligned */
 	rep
 	stosb
+	.cfi_undefined	%rdi
 
 	movq	%r8,%rcx
 	shrq	$3,%rcx			/* set by words */
_at__at_ -55,6 +57,7 _at__at_ ENTRY(memset)
 	andq	$7,%rcx
 L1:	rep
 	stosb
+	.cfi_undefined	%rdi
 	movq	%r11,%rax
 
 	ret
diff --git a/lib/libc/amd64/string/stpcpy.S b/lib/libc/amd64/string/stpcpy.S
index 52ac69c..95054dc 100644
--- a/lib/libc/amd64/string/stpcpy.S
+++ b/lib/libc/amd64/string/stpcpy.S
_at__at_ -24,7 +24,9 _at__at_ __FBSDID("$FreeBSD$");
 ENTRY(stpcpy)
 __stpcpy:
 	movabsq $0x0101010101010101,%r8
+	.cfi_undefined	%r8
 	movabsq $0x8080808080808080,%r9
+	.cfi_undefined	%r9
 
 	/*
 	 * Align source to a word boundary.
_at__at_ -35,8 +37,10 _at__at_ __stpcpy:
 	je	.Lword_aligned
 	movb	(%rsi),%dl
 	incq	%rsi
+	.cfi_undefined	%rsi
 	movb	%dl,(%rdi)
 	incq	%rdi
+	.cfi_undefined	%rdi
 	testb	%dl,%dl
 	jne	.Lalign
 	movq	%rdi,%rax
_at__at_ -51,6 +55,7 _at__at_ __stpcpy:
 	movq	(%rsi),%rdx
 	movq	%rdx,%rcx
 	addq	$8,%rsi
+	.cfi_undefined	%rsi
 	subq	%r8,%rcx
 	testq	%r9,%rcx
 	je	.Lloop
_at__at_ -64,6 +69,7 _at__at_ __stpcpy:
 	testb	%dl,%dl		/* 1st byte == 0? */
 	je	.Ldone
 	incq	%rdi
+	.cfi_undefined	%rdi
 
 	shrq	$8,%rdx
 	movb	%dl,(%rdi)
diff --git a/lib/libc/amd64/string/strcat.S b/lib/libc/amd64/string/strcat.S
index 7b5a1dd..daaaac1 100644
--- a/lib/libc/amd64/string/strcat.S
+++ b/lib/libc/amd64/string/strcat.S
_at__at_ -33,6 +33,7 _at__at_ ENTRY(strcat)
 .Lscan_loop:
 	movq	(%rdi),%rdx
 	addq	$8,%rdi
+	.cfi_undefined	%rdi
 	subq	%r8,%rdx
 	testq	%r9,%rdx
 	je	.Lscan_loop
_at__at_ -91,6 +92,7 _at__at_ ENTRY(strcat)
 	je	.Lcopy_aligned
 	movb	(%rsi),%dl
 	incq	%rsi
+	.cfi_undefined	%rsi
 	movb	%dl,(%rdi)
 	incq	%rdi
 	testb	%dl,%dl
_at__at_ -101,10 +103,12 _at__at_ ENTRY(strcat)
 .Lcopy_loop:
 	movq	%rdx,(%rdi)
 	addq	$8,%rdi
+	.cfi_undefined	%rdi
 .Lcopy_aligned:
 	movq	(%rsi),%rdx
 	movq	%rdx,%rcx
 	addq	$8,%rsi
+	.cfi_undefined	%rsi
 	subq	%r8,%rcx
 	testq	%r9,%rcx
 	je	.Lcopy_loop
diff --git a/lib/libc/amd64/string/strcmp.S b/lib/libc/amd64/string/strcmp.S
index 07009c1..2132187 100644
--- a/lib/libc/amd64/string/strcmp.S
+++ b/lib/libc/amd64/string/strcmp.S
_at__at_ -20,8 +20,10 _at__at_ ENTRY(strcmp)
 	je	.Ls1aligned
 	movb	(%rdi),%al
 	incq	%rdi
+	.cfi_undefined	%rdi
 	movb	(%rsi),%dl
 	incq	%rsi
+	.cfi_undefined	%rsi
 	testb	%al,%al
 	je	.Ldone
 	cmpb	%al,%dl
diff --git a/lib/libc/amd64/sys/brk.S b/lib/libc/amd64/sys/brk.S
index 4048ae6..76e6280 100644
--- a/lib/libc/amd64/sys/brk.S
+++ b/lib/libc/amd64/sys/brk.S
_at__at_ -42,14 +42,18 _at__at_ __FBSDID("$FreeBSD$");
 	.globl	HIDENAME(minbrk)
 ENTRY(_brk)
 	pushq	%rdi
+	.cfi_adjust_cfa_offset 8
 	jmp	ok
 END(_brk)
 
 ENTRY(brk)
 	pushq	%rdi
+	.cfi_adjust_cfa_offset 8
 	movq	%rdi,%rax
+	.cfi_undefined	%rax
 #ifdef PIC
 	movq	PIC_GOT(HIDENAME(minbrk)),%rdx
+	.cfi_undefined	%rdx
 	cmpq	%rax,(%rdx)
 #else
 	cmpq	%rax,HIDENAME(minbrk)(%rip)
_at__at_ -60,8 +64,10 _at__at_ ENTRY(brk)
 #else
 	movq	HIDENAME(minbrk)(%rip),%rdi
 #endif
+	.cfi_undefined	%rdi
 ok:
 	movq	$SYS_break,%rax
+	.cfi_undefined	%rax
 	KERNCALL
 	jb	err
 	movq	0(%rsp),%rax
_at__at_ -73,9 +79,11 _at__at_ ok:
 #endif
 	movq	$0,%rax
 	popq	%rdi
+	.cfi_adjust_cfa_offset -8
 	ret
 err:
 	addq	$8, %rsp
+	.cfi_adjust_cfa_offset -8
 	jmp	HIDENAME(cerror)
 END(brk)
 
diff --git a/lib/libc/amd64/sys/cerror.S b/lib/libc/amd64/sys/cerror.S
index d01cf4a..43032e4 100644
--- a/lib/libc/amd64/sys/cerror.S
+++ b/lib/libc/amd64/sys/cerror.S
_at__at_ -48,12 +48,21 _at__at_ __FBSDID("$FreeBSD$");
 	.globl	CNAME(__error)
 	.type	CNAME(__error),_at_function
 HIDENAME(cerror):
+	.cfi_startproc
 	pushq	%rax
+	.cfi_adjust_cfa_offset 8
+	.cfi_offset %rax,0
 	call	PIC_PLT(CNAME(__error))
 	popq	%rcx
+	.cfi_adjust_cfa_offset -8
+	.cfi_undefined %rcx
+	.cfi_register %rax,%rcx
 	movl	%ecx,(%rax)
 	movq	$-1,%rax
+	.cfi_undefined %rax
 	movq	$-1,%rdx
+	.cfi_undefined %rdx
 	ret
+	.cfi_endproc
 
 	.section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/amd64/sys/exect.S b/lib/libc/amd64/sys/exect.S
index 04a97ed..ce5e717 100644
--- a/lib/libc/amd64/sys/exect.S
+++ b/lib/libc/amd64/sys/exect.S
_at__at_ -41,11 +41,17 _at__at_ __FBSDID("$FreeBSD$");
 
 ENTRY(exect)
 	movq	$SYS_execve,%rax
+	.cfi_undefined	%rax
 	pushfq
+	.cfi_adjust_cfa_offset 8
 	popq	%r8
+	.cfi_adjust_cfa_offset -8
+	.cfi_undefined	%r8
 	orq	$PSL_T,%r8
 	pushq	%r8
+	.cfi_adjust_cfa_offset 8
 	popfq
+	.cfi_adjust_cfa_offset -8
 	KERNCALL
 	jmp	HIDENAME(cerror)
 END(exect)
diff --git a/lib/libc/amd64/sys/getcontext.S b/lib/libc/amd64/sys/getcontext.S
index 1128796..94c894c 100644
--- a/lib/libc/amd64/sys/getcontext.S
+++ b/lib/libc/amd64/sys/getcontext.S
_at__at_ -40,10 +40,22 _at__at_ __FBSDID("$FreeBSD$");
 	.set	getcontext,__sys_getcontext
 ENTRY(__sys_getcontext)
 	movq	(%rsp),%rsi	/* save getcontext return address */
+	.cfi_undefined	%rsi
 	mov	$SYS_getcontext,%rax
+	.cfi_undefined	%rax
 	KERNCALL
 	jb	HIDENAME(cerror)
 	addq	$8,%rsp		/* remove stale (setcontext) return address */
+	/*
+	 * The instruction above adjusted top of the stack so that the stack
+	 * does not contain a return address anymore.  But, due to the red
+	 * zone existence, return address value right below the top of stack
+	 * is non-volatile. Try to describe the trick to unwinder by claiming
+	 * that the standard call frame is one long word below top of the
+	 * stack.
+	 */
+	.cfi_adjust_cfa_offset 8
+	.cfi_return_column	%rsi
 	jmp	*%rsi		/* restore return address */
 END(__sys_getcontext)
 
diff --git a/lib/libc/amd64/sys/pipe.S b/lib/libc/amd64/sys/pipe.S
index 8d089db..6eee962 100644
--- a/lib/libc/amd64/sys/pipe.S
+++ b/lib/libc/amd64/sys/pipe.S
_at__at_ -44,6 +44,7 _at__at_ __FBSDID("$FreeBSD$");
 	.set	pipe,__sys_pipe
 ENTRY(__sys_pipe)
 	mov	$SYS_pipe,%rax
+	.cfi_undefined %rax
 	KERNCALL
 	jb	HIDENAME(cerror)
 	movl	%eax,(%rdi)	/* %rdi is preserved by syscall */
diff --git a/lib/libc/amd64/sys/ptrace.S b/lib/libc/amd64/sys/ptrace.S
index 9c4628d..5dbde65 100644
--- a/lib/libc/amd64/sys/ptrace.S
+++ b/lib/libc/amd64/sys/ptrace.S
_at__at_ -40,8 +40,10 _at__at_ __FBSDID("$FreeBSD$");
 
 ENTRY(ptrace)
 	xorl	%eax,%eax
+	.cfi_undefined	%rax
 #ifdef PIC
 	movq	PIC_GOT(CNAME(errno)),%r8
+	.cfi_undefined	%r8
 	movl	%eax,(%r8)
 #else
 	movl	%eax,CNAME(errno)(%rip)
diff --git a/lib/libc/amd64/sys/reboot.S b/lib/libc/amd64/sys/reboot.S
index fd04ef4..57fa2df 100644
--- a/lib/libc/amd64/sys/reboot.S
+++ b/lib/libc/amd64/sys/reboot.S
_at__at_ -44,6 +44,7 _at__at_ __FBSDID("$FreeBSD$");
 	.set	reboot,__sys_reboot
 ENTRY(__sys_reboot)
 	mov	$SYS_reboot,%rax
+	.cfi_undefined %rax
 	KERNCALL
 	jb	HIDENAME(cerror)
 	iretq
diff --git a/lib/libc/amd64/sys/sbrk.S b/lib/libc/amd64/sys/sbrk.S
index 0332aae..f0e3c6b 100644
--- a/lib/libc/amd64/sys/sbrk.S
+++ b/lib/libc/amd64/sys/sbrk.S
_at__at_ -49,16 +49,22 _at__at_ HIDENAME(curbrk):	.quad	CNAME(_end)
 
 ENTRY(sbrk)
 	pushq	%rdi
+	.cfi_adjust_cfa_offset 8
 	movq	%rdi,%rcx
+	.cfi_register %rdi,%rcx
 #ifdef PIC
 	movq	PIC_GOT(HIDENAME(curbrk)),%rdx
+	.cfi_undefined	%rdx
 	movq	(%rdx),%rax
+	.cfi_undefined	%rax
 #else
 	movq	HIDENAME(curbrk)(%rip),%rax
+	.cfi_undefined	%rax
 #endif
 	testq	%rcx,%rcx
 	jz	back
 	addq	%rax,%rdi
+	.cfi_undefined	%rdi
 	mov	$SYS_break,%eax
 	KERNCALL
 	jb	err
_at__at_ -69,6 +75,7 _at__at_ ENTRY(sbrk)
 	movq	HIDENAME(curbrk)(%rip),%rax
 #endif
 	movq	0(%rsp), %rcx
+	.cfi_undefined	%rcx
 #ifdef PIC
 	addq	%rcx,(%rdx)
 #else
_at__at_ -76,9 +83,11 _at__at_ ENTRY(sbrk)
 #endif
 back:
 	addq	$8, %rsp
+	.cfi_adjust_cfa_offset -8
 	ret
 err:
 	addq	$8, %rsp
+	.cfi_adjust_cfa_offset -8
 	jmp	HIDENAME(cerror)
 END(sbrk)
 
diff --git a/lib/libc/amd64/sys/setlogin.S b/lib/libc/amd64/sys/setlogin.S
index a451491..86b220c 100644
--- a/lib/libc/amd64/sys/setlogin.S
+++ b/lib/libc/amd64/sys/setlogin.S
_at__at_ -46,10 +46,12 _at__at_ __FBSDID("$FreeBSD$");
 	.set	setlogin,__sys_setlogin
 ENTRY(__sys_setlogin)
 	mov	$SYS_setlogin,%rax
+	.cfi_undefined	%rax
 	KERNCALL
 	jb	HIDENAME(cerror)
 #ifdef PIC
 	movq	PIC_GOT(CNAME(_logname_valid)),%rdx
+	.cfi_undefined %rdx
 	movl	$0,(%rdx)
 #else
 	movl	$0,CNAME(_logname_valid)(%rip)
diff --git a/lib/libc/amd64/sys/vfork.S b/lib/libc/amd64/sys/vfork.S
index 2afba58..c2673da 100644
--- a/lib/libc/amd64/sys/vfork.S
+++ b/lib/libc/amd64/sys/vfork.S
_at__at_ -44,12 +44,18 _at__at_ __FBSDID("$FreeBSD$");
 	.set	vfork,__sys_vfork
 ENTRY(__sys_vfork)
 	popq	%rsi		/* fetch return address (%rsi preserved) */
+	/* See a comment in getcontext.S */
+	.cfi_adjust_cfa_offset -8
+	.cfi_undefined	%rsi
+	.cfi_return_column %rsi
 	mov	$SYS_vfork,%rax
+	.cfi_undefined	%rax
 	KERNCALL
 	jb	1f
 	jmp	*%rsi
 1:
 	pushq	%rsi
+	.cfi_adjust_cfa_offset 8
 	jmp	HIDENAME(cerror)
 END(__sys_vfork)
 
diff --git a/lib/libthr/arch/amd64/amd64/_umtx_op_err.S b/lib/libthr/arch/amd64/amd64/_umtx_op_err.S
index b54fe64..36d6cf4 100644
--- a/lib/libthr/arch/amd64/amd64/_umtx_op_err.S
+++ b/lib/libthr/arch/amd64/amd64/_umtx_op_err.S
_at__at_ -29,10 +29,20 _at__at_
 #include <sys/syscall.h>
 #include <machine/asm.h>
 
-#define	RSYSCALL_ERR(x)	ENTRY(__CONCAT(x, _err));		\
-			mov __CONCAT($SYS_,x),%rax; KERNCALL; ret; 
+#define	RSYSCALL_ERR(x)						\
+	ENTRY(__CONCAT(x, _err));				\
+	mov __CONCAT($SYS_,x),%rax;				\
+	.cfi_undefined	%rax;					\
+	KERNCALL;						\
+	ret;							\
+	END(__CONCAT(x, _err))
 
-#define KERNCALL	movq %rcx, %r10; syscall
+#define KERNCALL						\
+	movq %rcx,%r10;						\
+	.cfi_undefined %r10;					\
+	.cfi_register %rcx,%r10;				\
+	syscall;						\
+	.cfi_undefined %rax,%rdx
 
 RSYSCALL_ERR(_umtx_op)
 
diff --git a/sys/amd64/include/asm.h b/sys/amd64/include/asm.h
index 7efd642..75603ec 100644
--- a/sys/amd64/include/asm.h
+++ b/sys/amd64/include/asm.h
_at__at_ -59,25 +59,37 _at__at_
 #define _START_ENTRY	.text; .p2align 4,0x90
 
 #define _ENTRY(x)	_START_ENTRY; \
-			.globl CNAME(x); .type CNAME(x),_at_function; CNAME(x):
+			.globl CNAME(x); .type CNAME(x),_at_function; \
+			CNAME(x): .cfi_startproc
 
 #ifdef PROF
-#define	ALTENTRY(x)	_ENTRY(x); \
-			pushq %rbp; movq %rsp,%rbp; \
+#define	ALTENTRY(x)	_ENTRY(x);			\
+			pushq %rbp;			\
+			.cfi_adjust_cfa_offset 8;	\
+			.cfi_offset %rbp,0		\
+			movq %rsp,%rbp;			\
 			call PIC_PLT(HIDENAME(mcount)); \
-			popq %rbp; \
+			popq %rbp;			\
+			.cfi_adjust_cfa_offset -8;	\
+			.cfi_restore %rbp;		\
 			jmp 9f
-#define	ENTRY(x)	_ENTRY(x); \
-			pushq %rbp; movq %rsp,%rbp; \
+#define	ENTRY(x)	_ENTRY(x);			\
+			pushq %rbp;			\
+			.cfi_adjust_cfa_offset 8;	\
+			.cfi_offset %rbp,0		\
+			movq %rsp,%rbp;			\
 			call PIC_PLT(HIDENAME(mcount)); \
-			popq %rbp; \
+			popq %rbp;			\
+			.cfi_adjust_cfa_offset -8;	\
+			.cfi_restore %rbp;		\
 			9:
 #else
 #define	ALTENTRY(x)	_ENTRY(x)
 #define	ENTRY(x)	_ENTRY(x)
 #endif
 
-#define	END(x)		.size x, . - x
+#define	END(x)		.cfi_endproc;			\
+			.size x, . - x
 
 #define RCSID(x)	.text; .asciz x
 

Received on Sun Oct 07 2012 - 13:20:12 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:31 UTC