mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-01 23:06:05 +02:00

Every startup code must now provide an additional entry point called "_dynamic_start" that is set as new the entry point if the program links to a Pascal shared library. Its purpose is to set up an exit hook usually passed via a register, which should be called during program finalization if non-nil. We use this additional entry point because this register only has meaningful content when there are any compile-time linked shared libraries, otherwise it often contains random garbage. The difference between the _dynamic_start and the original code is minimal; actually in all implementations the _dynamic_start code passes on control to the old startup code, so we use an additional entry point instead of an additional startup file. Detailed changes and fixes list: compiler: always link to the dynamic loader (ld.so) when compiling shared libraries. Fixes crashes in the loader during shared library finalization on some Linuxes remove additional ENTRY() section in arm linker script select either _dynamic_start or _start as entry point depending on whether this is a static or dynamic executable powerpc*: do not set System.isLibrary in startup code, it will be set during library initialization anyway trap in case of reaching code locations that should not be reached instead of looping (possibly endlessly) powerpc: register atexit() function pointer if supplied to the executable and call it during shutdown correctly set argc/argv/envp in shared library code and return correctly to the caller after initialization pass on exitcode in shared library haltproc use the more recent exit_group system call if available for shutdown powerpc64 fix .ptrgl stub, do not set the environment register to the value of the GOT entry in the function descriptor arm do not set System.isLibrary in startup code, it will be set during library initialization anyway reload exitcode to pass to shutdown mips,mipsel,sparc added stubs to allow correct linking git-svn-id: trunk@19036 -
90 lines
2.6 KiB
ActionScript
90 lines
2.6 KiB
ActionScript
/* Startup code for elf32-sparc
|
|
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, write to the Free
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
02111-1307 USA. */
|
|
|
|
.section ".text"
|
|
|
|
.align 4
|
|
.global _dynamic_start
|
|
.type _dynamic_start,#function
|
|
_dynamic_start:
|
|
/* TODO: need to set __dl_fini here */
|
|
b _start
|
|
|
|
.align 4
|
|
.global _start
|
|
.type _start,#function
|
|
_start:
|
|
|
|
/* Terminate the stack frame, and reserve space for functions to
|
|
drop their arguments. */
|
|
mov %g0, %fp
|
|
sub %sp, 6*4, %sp
|
|
|
|
/* Extract the arguments and environment as encoded on the stack. The
|
|
argument info starts after one register window (16 words) past the SP. */
|
|
ld [%sp+22*4], %o2
|
|
sethi %hi(operatingsystem_parameter_argc),%o1
|
|
or %o1,%lo(operatingsystem_parameter_argc),%o1
|
|
st %o2, [%o1]
|
|
|
|
add %sp, 23*4, %o0
|
|
sethi %hi(operatingsystem_parameter_argv),%o1
|
|
or %o1,%lo(operatingsystem_parameter_argv),%o1
|
|
st %o0, [%o1]
|
|
|
|
/* envp=(argc+1)*4+argv */
|
|
inc %o2
|
|
sll %o2, 2, %o2
|
|
add %o2, %o0, %o2
|
|
sethi %hi(operatingsystem_parameter_envp),%o1
|
|
or %o1,%lo(operatingsystem_parameter_envp),%o1
|
|
st %o2, [%o1]
|
|
|
|
/* Save initial stackpointer */
|
|
sethi %hi(__stkptr),%o1
|
|
or %o1,%lo(__stkptr),%o1
|
|
st %sp, [%o1]
|
|
|
|
/* Call the user program entry point. */
|
|
call PASCALMAIN
|
|
nop
|
|
/* Die very horribly if main returns. */
|
|
unimp
|
|
|
|
.globl _haltproc
|
|
.type _haltproc,@function
|
|
_haltproc:
|
|
/* TODO: need to check whether __dl_fini is non-zero and call the function pointer in case */
|
|
|
|
mov 188, %g1 /* "exit_group" system call */
|
|
ta 0x10 /* dot the system call */
|
|
nop /* delay slot */
|
|
/* Die very horribly if exit returns. */
|
|
unimp
|
|
|
|
.size _start, .-_start
|
|
|
|
.comm __stkptr,4
|
|
.comm __dl_fini,4
|
|
|
|
.comm operatingsystem_parameter_envp,4
|
|
.comm operatingsystem_parameter_argc,4
|
|
.comm operatingsystem_parameter_argv,4
|