Clear the stack frame pointer in _start and __bionic_clone

This CL adds an instruction to the _start label that clears the frame
pointer.  This allows stack walking code to determine when it has
reached the end of the stack.

The __bionic_clone function is similarly modified, for architectures
that weren't already doing both.

Test: bionic-unit-tests
Test: CtsBionicTestCases
Change-Id: Iea3949f52c44f7931f9fff2d60d4d9e5c742c120
diff --git a/libc/arch-arm/bionic/__bionic_clone.S b/libc/arch-arm/bionic/__bionic_clone.S
index 6669b93..3fe212b 100644
--- a/libc/arch-arm/bionic/__bionic_clone.S
+++ b/libc/arch-arm/bionic/__bionic_clone.S
@@ -61,6 +61,8 @@
     b       __set_errno_internal
 
 .L_bc_child:
+    # We're in the child now. Set the end of the frame record chain.
+    mov    fp, #0
     # Setting lr to 0 will make the unwinder stop at __start_thread.
     mov    lr, #0
     # Call __start_thread with the 'fn' and 'arg' we stored on the child stack.
diff --git a/libc/arch-common/bionic/crtbegin.c b/libc/arch-common/bionic/crtbegin.c
index 62878378..5f681c5 100644
--- a/libc/arch-common/bionic/crtbegin.c
+++ b/libc/arch-common/bionic/crtbegin.c
@@ -49,13 +49,15 @@
 #define POST "; .size _start, .-_start"
 
 #if defined(__aarch64__)
-__asm__(PRE "bti j; mov x0,sp; b _start_main" POST);
+__asm__(PRE "bti j; mov x29,#0; mov x30,#0; mov x0,sp; b _start_main" POST);
 #elif defined(__arm__)
-__asm__(PRE "mov r0,sp; b _start_main" POST);
+__asm__(PRE "mov fp,#0; mov lr,#0; mov r0,sp; b _start_main" POST);
 #elif defined(__i386__)
-__asm__(PRE "movl %esp,%eax; andl $~0xf,%esp; subl $12,%esp; pushl %eax; calll _start_main" POST);
+__asm__(PRE
+        "xorl %ebp,%ebp; movl %esp,%eax; andl $~0xf,%esp; subl $12,%esp; pushl %eax;"
+        "calll _start_main" POST);
 #elif defined(__x86_64__)
-__asm__(PRE "movq %rsp,%rdi; andq $~0xf,%rsp; callq _start_main" POST);
+__asm__(PRE "xorl %ebp, %ebp; movq %rsp,%rdi; andq $~0xf,%rsp; callq _start_main" POST);
 #else
 #error unsupported architecture
 #endif
diff --git a/libc/arch-x86/bionic/__bionic_clone.S b/libc/arch-x86/bionic/__bionic_clone.S
index b682b48..f0c58a0 100644
--- a/libc/arch-x86/bionic/__bionic_clone.S
+++ b/libc/arch-x86/bionic/__bionic_clone.S
@@ -45,6 +45,7 @@
 .L_bc_child:
         # We don't want anyone to unwind past this point.
         .cfi_undefined %eip
+        .cfi_undefined %ebp
         call    __start_thread
         hlt