mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-06-19 16:19:11 +02:00
* Clean up i386-Linux startup code for shared libraries:
* The initialization code is a normal function called by runtime linker, stack layout at process startup is irrelevant. * Stack pointer can be replaced by frame pointer, they are just a few bytes away. * IsLibrary is set to true in fpc_libinitializeunits and therefore assigning it here is redundant. * The exitcode is passed as argument to haltproc, so messing with PIC is not necessary. git-svn-id: trunk@26759 -
This commit is contained in:
parent
df6837fa12
commit
ead8d0c1d4
@ -12,35 +12,9 @@
|
|||||||
|
|
||||||
**********************************************************************}
|
**********************************************************************}
|
||||||
{$asmmode att}
|
{$asmmode att}
|
||||||
{$goto on}
|
|
||||||
{
|
|
||||||
Linux ELF startup code for Free Pascal
|
|
||||||
|
|
||||||
|
|
||||||
Stack layout at program start:
|
|
||||||
|
|
||||||
nil
|
|
||||||
envn
|
|
||||||
....
|
|
||||||
.... ENVIRONMENT VARIABLES
|
|
||||||
env1
|
|
||||||
env0
|
|
||||||
nil
|
|
||||||
argn
|
|
||||||
....
|
|
||||||
.... COMMAND LINE OPTIONS
|
|
||||||
arg1
|
|
||||||
arg0
|
|
||||||
argc <--- esp
|
|
||||||
}
|
|
||||||
|
|
||||||
procedure PASCALMAIN; external name 'PASCALMAIN';
|
procedure PASCALMAIN; external name 'PASCALMAIN';
|
||||||
|
|
||||||
function get1eipasebx : pointer; compilerproc; nostackframe; assembler;
|
|
||||||
asm
|
|
||||||
movl (%esp),%ebx
|
|
||||||
ret
|
|
||||||
end;
|
|
||||||
|
|
||||||
{******************************************************************************
|
{******************************************************************************
|
||||||
Shared library start/halt
|
Shared library start/halt
|
||||||
@ -52,45 +26,17 @@ begin
|
|||||||
operatingsystem_parameter_argc:=argc; { Copy the argument count }
|
operatingsystem_parameter_argc:=argc; { Copy the argument count }
|
||||||
operatingsystem_parameter_argv:=argv; { Copy the argument pointer }
|
operatingsystem_parameter_argv:=argv; { Copy the argument pointer }
|
||||||
operatingsystem_parameter_envp:=envp; { Copy the environment pointer }
|
operatingsystem_parameter_envp:=envp; { Copy the environment pointer }
|
||||||
|
initialstkptr:=get_frame;
|
||||||
IsLibrary:=true;
|
|
||||||
|
|
||||||
asm
|
|
||||||
{ Save initial stackpointer }
|
|
||||||
{$ifdef FPC_PIC}
|
|
||||||
call get1eipasebx
|
|
||||||
addl $_GLOBAL_OFFSET_TABLE_,%ebx
|
|
||||||
movl initialstkptr@GOT(%ebx),%ecx
|
|
||||||
movl %esp,(%ecx)
|
|
||||||
{$else FPC_PIC}
|
|
||||||
movl %esp,initialstkptr
|
|
||||||
{$endif FPC_PIC}
|
|
||||||
end;
|
|
||||||
|
|
||||||
PASCALMAIN;
|
PASCALMAIN;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ this routine is only called when the halt() routine of the RTL embedded in
|
{ this routine is only called when the halt() routine of the RTL embedded in
|
||||||
the shared library is called }
|
the shared library is called }
|
||||||
procedure _FPC_shared_lib_haltproc; assembler; nostackframe; public name 'FPC_SHARED_LIB_EXIT'; public name '_haltproc';
|
procedure _FPC_shared_lib_haltproc(e:longint); cdecl; assembler; nostackframe; public name '_haltproc';
|
||||||
asm
|
asm
|
||||||
.Lhaltproc:
|
.Lhaltproc:
|
||||||
{$ifdef FPC_PIC}
|
movl e,%ebx
|
||||||
call get1eipasebx
|
|
||||||
addl $_GLOBAL_OFFSET_TABLE_,%ebx
|
|
||||||
movl ExitCode@GOT(%ebx),%ebx
|
|
||||||
{$if sizeof(ExitCode)=2}
|
|
||||||
movzwl (%ebx),%ebx
|
|
||||||
{$else}
|
|
||||||
mov (%ebx),%ebx
|
|
||||||
{$endif}
|
|
||||||
{$else FPC_PIC}
|
|
||||||
{$if sizeof(ExitCode)=2}
|
|
||||||
movzwl ExitCode,%ebx
|
|
||||||
{$else}
|
|
||||||
mov ExitCode,%ebx
|
|
||||||
{$endif}
|
|
||||||
{$endif FPC_PIC}
|
|
||||||
xorl %eax,%eax
|
xorl %eax,%eax
|
||||||
incl %eax { eax=1, exit call }
|
incl %eax { eax=1, exit call }
|
||||||
int $0x80
|
int $0x80
|
||||||
|
Loading…
Reference in New Issue
Block a user