Преглед изворни кода

* reverted the rtl patches from r14184, because they cause an endless
loop when attempting to terminate a process via the RTL compiled into
a Linux shared library (mantis #17383)
* call FPC_LIB_EXIT (the internal/generic RTL finalisation routine) instead
of FPC_SHARED_LIB_EXIT (the Linux-specific "process exit" code for shared
libraries) as "fini" routine (fixes #14958 again after reverting r14184)

git-svn-id: trunk@16418 -

Jonas Maebe пре 14 година
родитељ
комит
1f61b5b30c

+ 1 - 1
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 }

+ 22 - 3
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;

+ 2 - 2
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)

+ 7 - 2
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