From 556182feb40916842b52087f442ebcb4e877dbd7 Mon Sep 17 00:00:00 2001 From: Andrew Hsieh Date: Thu, 28 Jun 2012 14:04:36 -0700 Subject: [PATCH] Fix SEGV when unwinding stack pasts __libc_init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed "jump __libc_init" to "call __libc_init" otherwise stack unwinding past __libc_init may get wrong return address and crash the program or do wield things. With "call", return address is pushed on stack and unwinding stops correctly at _start. Note that __libc_init never returns, so this fix wonʼt affect normal program execution. But just in case it "does" return, jump to address 0 and halt. Change-Id: Id194fb32adcbf89ae59939cee33c50b5bbdd36fe --- ndk/platforms/android-3/arch-arm/src/crtbegin_dynamic.S | 4 +++- ndk/platforms/android-3/arch-arm/src/crtbegin_static.S | 4 +++- ndk/platforms/android-9/arch-mips/src/crtbegin_dynamic.S | 2 ++ ndk/platforms/android-9/arch-mips/src/crtbegin_static.S | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ndk/platforms/android-3/arch-arm/src/crtbegin_dynamic.S b/ndk/platforms/android-3/arch-arm/src/crtbegin_dynamic.S index 6ca08458e..ec6d482d8 100644 --- a/ndk/platforms/android-3/arch-arm/src/crtbegin_dynamic.S +++ b/ndk/platforms/android-3/arch-arm/src/crtbegin_dynamic.S @@ -53,7 +53,9 @@ _start: ldr r2, =main adr r3, 1f ldr r4, =__libc_init - bx r4 + blx r4 + mov r0, #0 + bx r0 1: .long __PREINIT_ARRAY__ .long __INIT_ARRAY__ diff --git a/ndk/platforms/android-3/arch-arm/src/crtbegin_static.S b/ndk/platforms/android-3/arch-arm/src/crtbegin_static.S index ec13351eb..d9d12a786 100644 --- a/ndk/platforms/android-3/arch-arm/src/crtbegin_static.S +++ b/ndk/platforms/android-3/arch-arm/src/crtbegin_static.S @@ -53,7 +53,9 @@ _start: ldr r2, =main adr r3, 1f ldr r4, =__libc_init - bx r4 + blx r4 + mov r0, #0 + bx r0 1: .long __PREINIT_ARRAY__ .long __INIT_ARRAY__ diff --git a/ndk/platforms/android-9/arch-mips/src/crtbegin_dynamic.S b/ndk/platforms/android-9/arch-mips/src/crtbegin_dynamic.S index 7d1fac740..28f8fd551 100644 --- a/ndk/platforms/android-9/arch-mips/src/crtbegin_dynamic.S +++ b/ndk/platforms/android-9/arch-mips/src/crtbegin_dynamic.S @@ -64,6 +64,8 @@ _start: la $a3, 1f subu $sp, 32 la $t9, __libc_init + jalr $t9 + move $t9, $0 j $t9 .end __start diff --git a/ndk/platforms/android-9/arch-mips/src/crtbegin_static.S b/ndk/platforms/android-9/arch-mips/src/crtbegin_static.S index 9f00811ea..893863c17 100644 --- a/ndk/platforms/android-9/arch-mips/src/crtbegin_static.S +++ b/ndk/platforms/android-9/arch-mips/src/crtbegin_static.S @@ -64,6 +64,8 @@ _start: la $a3, 1f subu $sp, 32 la $t9, __libc_init + jalr $t9 + move $t9, $0 j $t9 .end __start