From c14574bb56020c91441fc4a44e143e3f53588ec3 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sun, 14 Nov 2010 16:00:25 +0000 Subject: [PATCH] * don't change the fpu control word in the initialisation code of dynamic libraries (mantis #16263, #16801) git-svn-id: trunk@16347 - --- .gitattributes | 1 + rtl/arm/arm.inc | 4 +++- rtl/i386/i386.inc | 8 ++++++++ rtl/mips/mipsel.inc | 12 ++++++++---- rtl/powerpc/powerpc.inc | 4 +++- rtl/powerpc64/powerpc64.inc | 4 +++- rtl/x86_64/x86_64.inc | 20 +++++++++++++------- tests/webtbs/tw16263a.pp | 26 ++++++++++++++++++++++++++ 8 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 tests/webtbs/tw16263a.pp diff --git a/.gitattributes b/.gitattributes index ec68fa8de1..5530427fad 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10665,6 +10665,7 @@ tests/webtbs/tw16188.pp svneol=native#text/plain tests/webtbs/tw1622.pp svneol=native#text/plain tests/webtbs/tw16222.pp svneol=native#text/pascal 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/tw16315a.pp svneol=native#text/pascal tests/webtbs/tw16315b.pp svneol=native#text/pascal diff --git a/rtl/arm/arm.inc b/rtl/arm/arm.inc index eead47cbf0..d1148f6bca 100644 --- a/rtl/arm/arm.inc +++ b/rtl/arm/arm.inc @@ -69,7 +69,9 @@ end; procedure fpc_cpuinit; begin - SysInitFPU; + { don't let libraries influence the FPU cw set by the host program } + if not IsLibrary then + SysInitFPU; end; {$ifdef wince} diff --git a/rtl/i386/i386.inc b/rtl/i386/i386.inc index fc227ca291..9f89ac01f8 100644 --- a/rtl/i386/i386.inc +++ b/rtl/i386/i386.inc @@ -110,6 +110,9 @@ procedure fpc_cpuinit; setup_fastmove; } os_supports_sse:=false; + { don't let libraries influence the FPU cw set by the host program } + if IsLibrary then + Default8087CW:=Get8087CW; end; @@ -1522,6 +1525,11 @@ procedure fpc_cpucodeinit; sse_check:=false; end; 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; SysResetFPU; if not(IsLibrary) then diff --git a/rtl/mips/mipsel.inc b/rtl/mips/mipsel.inc index 2f4fac75c8..9fcf1400a0 100644 --- a/rtl/mips/mipsel.inc +++ b/rtl/mips/mipsel.inc @@ -43,11 +43,15 @@ procedure fpc_cpuinit; var tmp32: longint; begin - { enable div by 0 and invalid operation fpu exceptions } - { round towards zero; ieee compliant arithmetics } + { 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); + tmp32 := get_fsr(); + set_fsr((tmp32 and $fffffffc) or $00000001); + end; end; diff --git a/rtl/powerpc/powerpc.inc b/rtl/powerpc/powerpc.inc index 49d0a7dd25..5686bf3730 100644 --- a/rtl/powerpc/powerpc.inc +++ b/rtl/powerpc/powerpc.inc @@ -56,7 +56,9 @@ end; procedure fpc_cpuinit; 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; diff --git a/rtl/powerpc64/powerpc64.inc b/rtl/powerpc64/powerpc64.inc index 1a011be1c3..72f54aa799 100644 --- a/rtl/powerpc64/powerpc64.inc +++ b/rtl/powerpc64/powerpc64.inc @@ -43,7 +43,9 @@ end; procedure fpc_cpuinit; 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; {**************************************************************************** diff --git a/rtl/x86_64/x86_64.inc b/rtl/x86_64/x86_64.inc index 4ff76e57c4..58c86ee6a3 100644 --- a/rtl/x86_64/x86_64.inc +++ b/rtl/x86_64/x86_64.inc @@ -24,13 +24,6 @@ Primitives ****************************************************************************} -procedure fpc_cpuinit; - begin - SysResetFPU; - if not(IsLibrary) then - SysInitFPU; - end; - {$define FPC_SYSTEM_HAS_SPTR} Function Sptr : Pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif} asm @@ -593,6 +586,19 @@ const 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} Procedure SysInitFPU; var diff --git a/tests/webtbs/tw16263a.pp b/tests/webtbs/tw16263a.pp new file mode 100644 index 0000000000..ced052df9c --- /dev/null +++ b/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.