From a8bf34d3fc359b15d31b5ed4442992484aae6cc5 Mon Sep 17 00:00:00 2001 From: tom_at_work Date: Wed, 23 Feb 2011 09:41:19 +0000 Subject: [PATCH] Correctly return to caller in ARM/Linux shared library startup code instead of fall-through to system exit. git-svn-id: trunk@16982 - --- rtl/linux/arm/dllprt0.as | 43 +++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/rtl/linux/arm/dllprt0.as b/rtl/linux/arm/dllprt0.as index 77a467368b..269d691c04 100644 --- a/rtl/linux/arm/dllprt0.as +++ b/rtl/linux/arm/dllprt0.as @@ -6,31 +6,38 @@ _startlib: .globl FPC_SHARED_LIB_START .type FPC_SHARED_LIB_START,#function FPC_SHARED_LIB_START: - /* Clear the frame pointer since this is the outermost frame */ - mov fp, #0 - ldmia sp!, {a2} + mov ip, sp + push {fp, ip, lr, pc} + sub fp, ip, #4 + sub sp, sp, #40 - /* pop argc off the stack and save a pointer to argv */ - ldr ip,=operatingsystem_parameter_argc - ldr a3,=operatingsystem_parameter_argv - str a2,[ip] + /* load argc */ + mov a1, ip - /* calc envp */ - add a2,a2,#1 - add a2,sp,a2,lsl #2 - ldr ip,=operatingsystem_parameter_envp + /* load and save a copy of argc */ + ldr a2, [a1] + ldr ip, =operatingsystem_parameter_argc + str a2, [ip] - str sp,[a3] - str a2,[ip] + /* calc argv and store */ + add a1, a1, #4 + ldr ip, =operatingsystem_parameter_argv + str a1, [ip] + + /* calc envp and store */ + add a2, a2, #1 + add a2, a1, a2, lsl #2 + + ldr ip, =operatingsystem_parameter_envp + str a2, [ip] /* save initial stackpointer */ - ldr ip,=__stklen - str sp,[ip] - /* align sp again to 8 byte boundary, needed by eabi */ - sub sp,sp,#4 + ldr ip, =__stklen + str sp, [ip] - /* let the libc call main and exit with its return code */ + /* call main and exit normally */ bl PASCALMAIN + ldmdb fp, {fp, sp, pc} .globl _haltproc .type _haltproc,#function