[PATCH 2/3] libc/x86: add dwarf-2 cfi unwinding information to clone()

Timo Teräs timo.teras at iki.fi
Sun Nov 20 08:50:47 UTC 2011


Copied mostly from glibc. Adds proper information for unwinding application
created threads. Without the proper unwind information the stack trace is
considered as incomplete or corrupted after clone(). This adds the proper
end-of-stack markers and thus removes gdb errors.

Signed-off-by: Timo Teräs <timo.teras at iki.fi>
---
 libc/sysdeps/linux/i386/clone.S |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/libc/sysdeps/linux/i386/clone.S b/libc/sysdeps/linux/i386/clone.S
index a7de3fe..cf6cd35 100644
--- a/libc/sysdeps/linux/i386/clone.S
+++ b/libc/sysdeps/linux/i386/clone.S
@@ -25,6 +25,7 @@
 
 #define _ERRNO_H	1
 #include <bits/errno.h>
+#include <sysdep.h>
 #include <sys/syscall.h>
 
 /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
@@ -45,6 +46,7 @@
 .global clone
 .type   clone,%function
 clone:
+	cfi_startproc;
 	/* Sanity check arguments.  */
 	movl	$-EINVAL,%eax
 
@@ -86,17 +88,28 @@ clone:
 
 	/* Do the system call */
 	pushl	%ebx
+	cfi_adjust_cfa_offset (4)
 	pushl	%esi
+	cfi_adjust_cfa_offset (4)
 	pushl	%edi
+	cfi_adjust_cfa_offset (4)
+
 	movl	TLS+12(%esp),%esi
+	cfi_rel_offset (esi, 4)
 	movl	PTID+12(%esp),%edx
 	movl	FLAGS+12(%esp),%ebx
+	cfi_rel_offset (ebx, 8)
 	movl	CTID+12(%esp),%edi
+	cfi_rel_offset (edi, 0)
 	movl	$__NR_clone,%eax
 #ifdef RESET_PID
 	/* Remember the flag value.  */
 	movl	%ebx, (%ecx)
 #endif
+	/* End FDE now, because in the child the unwind info will be
+	   wrong.  */
+	cfi_endproc
+
 	int	$0x80
 	popl	%edi
 	popl	%esi
@@ -108,6 +121,9 @@ clone:
 	ret
 
 .Lthread_start:
+	cfi_startproc;
+	/* Clearing frame pointer is insufficient, use CFI.  */
+	cfi_undefined (eip);
 	/* Note: %esi is zero.  */
 	movl	%esi,%ebp	/* terminate the stack frame */
 	call	*%ebx
@@ -120,6 +136,7 @@ clone:
 	movl	%eax, %ebx
 	movl	$__NR_exit, %eax
 	int	$0x80
+	cfi_endproc;
 
 /* Need to indirect jump to syscall error 
  * or we end up with TEXTREL's
-- 
1.7.7.1



More information about the uClibc mailing list