Przeglądaj źródła

* don't change the fpu control word in the initialisation code of dynamic
libraries (mantis #16263, #16801)

git-svn-id: trunk@16347 -

Jonas Maebe 14 lat temu
rodzic
commit
c14574bb56

+ 1 - 0
.gitattributes

@@ -10665,6 +10665,7 @@ tests/webtbs/tw16188.pp svneol=native#text/plain
 tests/webtbs/tw1622.pp svneol=native#text/plain
 tests/webtbs/tw1622.pp svneol=native#text/plain
 tests/webtbs/tw16222.pp svneol=native#text/pascal
 tests/webtbs/tw16222.pp svneol=native#text/pascal
 tests/webtbs/tw1623.pp svneol=native#text/plain
 tests/webtbs/tw1623.pp svneol=native#text/plain
+tests/webtbs/tw16263a.pp svneol=native#text/plain
 tests/webtbs/tw16311.pp svneol=native#text/plain
 tests/webtbs/tw16311.pp svneol=native#text/plain
 tests/webtbs/tw16315a.pp svneol=native#text/pascal
 tests/webtbs/tw16315a.pp svneol=native#text/pascal
 tests/webtbs/tw16315b.pp svneol=native#text/pascal
 tests/webtbs/tw16315b.pp svneol=native#text/pascal

+ 3 - 1
rtl/arm/arm.inc

@@ -69,7 +69,9 @@ end;
 
 
 procedure fpc_cpuinit;
 procedure fpc_cpuinit;
 begin
 begin
-  SysInitFPU;
+  { don't let libraries influence the FPU cw set by the host program }
+  if not IsLibrary then
+    SysInitFPU;
 end;
 end;
 
 
 {$ifdef wince}
 {$ifdef wince}

+ 8 - 0
rtl/i386/i386.inc

@@ -110,6 +110,9 @@ procedure fpc_cpuinit;
     setup_fastmove;
     setup_fastmove;
     }
     }
     os_supports_sse:=false;
     os_supports_sse:=false;
+    { don't let libraries influence the FPU cw set by the host program }
+    if IsLibrary then
+      Default8087CW:=Get8087CW;
   end;
   end;
 
 
 
 
@@ -1522,6 +1525,11 @@ procedure fpc_cpucodeinit;
         sse_check:=false;
         sse_check:=false;
       end;
       end;
     has_sse_support:=os_supports_sse;
     has_sse_support:=os_supports_sse;
+    { don't let libraries influence the FPU cw set by the host program }
+    if has_sse_support and
+       IsLibrary then
+      mxcsr:=GetSSECSR;
+
     has_mmx_support:=mmx_support;
     has_mmx_support:=mmx_support;
     SysResetFPU;
     SysResetFPU;
     if not(IsLibrary) then
     if not(IsLibrary) then

+ 9 - 5
rtl/mips/mipsel.inc

@@ -43,11 +43,15 @@ procedure fpc_cpuinit;
 var
 var
   tmp32: longint;
   tmp32: longint;
   begin
   begin
-    { enable div by 0 and invalid operation fpu exceptions }
-    { round towards zero; ieee compliant arithmetics }
-
-    tmp32 := get_fsr();
-    set_fsr((tmp32 and $fffffffc) or $00000001);
+    { don't let libraries influence the FPU cw set by the host program }
+    if not IsLibrary then
+      begin
+        { enable div by 0 and invalid operation fpu exceptions }
+        { round towards zero; ieee compliant arithmetics }
+
+        tmp32 := get_fsr();
+        set_fsr((tmp32 and $fffffffc) or $00000001);
+      end;
   end;
   end;
 
 
 
 

+ 3 - 1
rtl/powerpc/powerpc.inc

@@ -56,7 +56,9 @@ end;
 
 
 procedure fpc_cpuinit;
 procedure fpc_cpuinit;
 begin
 begin
-  fpc_enable_ppc_fpu_exceptions;
+  { don't let libraries influence the FPU cw set by the host program }
+  if not IsLibrary then
+    fpc_enable_ppc_fpu_exceptions;
 end;
 end;
 
 
 
 

+ 3 - 1
rtl/powerpc64/powerpc64.inc

@@ -43,7 +43,9 @@ end;
 
 
 procedure fpc_cpuinit;
 procedure fpc_cpuinit;
 begin
 begin
-  fpc_enable_ppc_fpu_exceptions;
+  { don't let libraries influence the FPU cw set by the host program }
+  if not IsLibrary then
+    fpc_enable_ppc_fpu_exceptions;
 end;
 end;
 
 
 {****************************************************************************
 {****************************************************************************

+ 13 - 7
rtl/x86_64/x86_64.inc

@@ -24,13 +24,6 @@
                                Primitives
                                Primitives
 ****************************************************************************}
 ****************************************************************************}
 
 
-procedure fpc_cpuinit;
-  begin
-    SysResetFPU;
-    if not(IsLibrary) then
-      SysInitFPU;
-  end;
-
 {$define FPC_SYSTEM_HAS_SPTR}
 {$define FPC_SYSTEM_HAS_SPTR}
 Function Sptr : Pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
 Function Sptr : Pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
 asm
 asm
@@ -593,6 +586,19 @@ const
 
 
   mxcsr : dword = MM_MaskUnderflow or MM_MaskPrecision or MM_MaskDenorm;
   mxcsr : dword = MM_MaskUnderflow or MM_MaskPrecision or MM_MaskDenorm;
 
 
+procedure fpc_cpuinit;
+  begin
+    { don't let libraries influence the FPU cw set by the host program }
+    if IsLibrary then
+      begin
+        Default8087CW:=Get8087CW;
+        mxcsr:=GetSSECSR;
+      end;
+    SysResetFPU;
+    if not(IsLibrary) then
+      SysInitFPU;
+  end;
+
 {$define FPC_SYSTEM_HAS_SYSINITFPU}
 {$define FPC_SYSTEM_HAS_SYSINITFPU}
 Procedure SysInitFPU;
 Procedure SysInitFPU;
   var
   var

+ 26 - 0
tests/webtbs/tw16263a.pp

@@ -0,0 +1,26 @@
+{ %norun }
+{ %target=darwin,linux,freebsd,solaris,beos,haiku }
+
+{$mode delphi}
+
+{$ifdef darwin}
+{$PIC+}
+{$endif darwin}
+
+{$ifdef CPUX86_64}
+{$ifndef WINDOWS}
+{$PIC+}
+{$endif WINDOWS}
+{$endif CPUX86_64}
+
+library tw16263a;
+
+function divide(d1,d2: double): double; cdecl;
+begin
+  divide:=d1/d2;
+end;
+
+begin
+  // check that the library does not re-enable fpu exceptions
+  divide(1.0,0.0);
+end.