diff --git a/compiler/systems/t_linux.pas b/compiler/systems/t_linux.pas index 80357b6003..652ba7f93e 100644 --- a/compiler/systems/t_linux.pas +++ b/compiler/systems/t_linux.pas @@ -1080,7 +1080,7 @@ begin { Create some replacements } { note: linux does not use exportlib.initname/fininame due to the custom startup code } InitStr:='-init FPC_SHARED_LIB_START'; - FiniStr:='-fini FPC_SHARED_LIB_EXIT'; + FiniStr:='-fini FPC_LIB_EXIT'; SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename^); { Call linker } diff --git a/rtl/linux/i386/si_dll.inc b/rtl/linux/i386/si_dll.inc index ae5cf2a925..1c1fb06f5c 100644 --- a/rtl/linux/i386/si_dll.inc +++ b/rtl/linux/i386/si_dll.inc @@ -70,10 +70,29 @@ begin PASCALMAIN; end; -Procedure lib_exit; external name 'FPC_LIB_EXIT'; - +{ this routine is only called when the halt() routine of the RTL embedded in + the shared library is called } procedure _FPC_shared_lib_haltproc; assembler; nostackframe; public name 'FPC_SHARED_LIB_EXIT'; public name '_haltproc'; asm .Lhaltproc: - call lib_exit + {$ifdef FPC_PIC} + 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 + incl %eax { eax=1, exit call } + int $0x80 + jmp .Lhaltproc end; diff --git a/rtl/linux/powerpc64/dllprt0.as b/rtl/linux/powerpc64/dllprt0.as index 77a86ef278..b7788ac8bc 100644 --- a/rtl/linux/powerpc64/dllprt0.as +++ b/rtl/linux/powerpc64/dllprt0.as @@ -356,10 +356,10 @@ FUNCTION_PROLOG FPC_SHARED_LIB_START mtlr 0 blr +/* this routine is only called when the halt() routine of the RTL embedded in + the shared library is called */ FUNCTION_PROLOG _haltproc FUNCTION_PROLOG FPC_SHARED_LIB_EXIT - bl FPC_LIB_EXIT - nop /* exit_group call */ LOAD_64BIT_VAL 3, operatingsystem_result lwz 3, 0(3) diff --git a/rtl/linux/x86_64/dllprt0.as b/rtl/linux/x86_64/dllprt0.as index cce8a5ecee..4ae50b2729 100644 --- a/rtl/linux/x86_64/dllprt0.as +++ b/rtl/linux/x86_64/dllprt0.as @@ -65,14 +65,19 @@ _startlib: popq %rbx ret +/* this routine is only called when the halt() routine of the RTL embedded in + the shared library is called */ .globl _haltproc .type _haltproc,@function _haltproc: .globl FPC_SHARED_LIB_EXIT .type FPC_SHARED_LIB_EXIT,@function FPC_SHARED_LIB_EXIT: - call FPC_LIB_EXIT@PLT - ret + movl $231,%eax /* exit_group call */ + movq operatingsystem_result@GOTPCREL(%rip),%rbx + movzwl (%rbx),%edi + syscall + jmp _haltproc@PLT /* Define a symbol for the first piece of initialized data. */ .data