View Issue Details

IDProjectCategoryView StatusLast Update
0035147FPCFCLpublic2019-06-30 19:38
Reporterfrancesco sammarcoAssigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformWindowsOS10OS Version64 bit
Product Version3.3.1Product Build 
Target VersionFixed in Version 
Summary0035147: timestamptomsecs bug with cross compilation
DescriptionI installed lazarus 2.1.0 and fpc 3.3.1 using fpcupdeluxe (64-bit version for windows). I have also installed the cross compiler for 32-bit windows. Then I created this simple program

procedure TForm1.Button1Click(Sender: TObject);
var
   curmilli,latermilli:comp;
begin
  curmilli:=timestamptomsecs(datetimetotimestamp(now));
  showmessage('Waiting');
  latermilli:=timestamptomsecs(datetimetotimestamp(now));
  showmessage(IntToStr(QWord(latermilli)-QWord(curmilli)));
end;

When I compile for 64-bit windows everything works, when I compile for 32-bit windows (with the cross compiler) I get the error: External: SIGFPE
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Jonas Maebe

2019-02-25 20:46

manager   ~0114427

Normally, it is impossible to build a cross-compiler from win64 to win32, because the Win64 compiler does not support the required 80 bit extended floating point type. So are you certain it's a cross-compiler and not a native win32 compiler?

Additionally, when reporting bugs, please always include a complete compilable program, and also mention what the problem is.

francesco sammarco

2019-02-26 08:24

reporter   ~0114458

Well, on fpcupdeluxe I selected "install cross compiler", so I would say that it is just a cross compiler and not a native one. I will ask the fpcupdeluxe group better. For the program it does exactly just what I posted. However, tonight I will attach the complete program.

In addition, I reported the problem when it comes to executing the line

curmilli: = timestamptomsecs (datetimetotimestamp (now));

I get an External SIGFPE error

Andrew S. Baker (ASB)

2019-02-27 00:32

reporter   ~0114477

Jonas said: "Normally, it is impossible to build a cross-compiler from win64 to win32, because the Win64 compiler does not support the required 80 bit extended floating point type. So are you certain it's a cross-compiler and not a native win32 compiler?"

Jonas, yes, this is true for FPC 3.0.4, but FPC 3.2_Fixes and FPC Trunk both support cross-compiling a Win32 executable from Win64

francesco sammarco

2019-02-28 17:59

reporter  

test3.zip (1,930 bytes)

francesco sammarco

2019-02-28 18:00

reporter   ~0114509

I have attached an example as requested.
This is the result:

Exception at 00421CF6: EInvalidOp:
Invalid floating point operation.

Bart Broersma

2019-02-28 18:44

reporter   ~0114513

Stripped down version:

program project1;
{$mode objfpc}{$H+}
uses
  SysUtils;
var
  curmilli,latermilli:comp;
begin
  curmilli:=timestamptomsecs(datetimetotimestamp(now));
  writeln('Waiting');
  sleep(4000);
  latermilli:=timestamptomsecs(datetimetotimestamp(now));
  writeln(IntToStr(QWord(latermilli)-QWord(curmilli)));
end.

Runs fine with fpc trunk (r41352) 32 (native) and 64 (crosscompile) bit.

francesco sammarco

2019-02-28 18:55

reporter   ~0114514

The problem is 64 native and 32 crosscompile.

francesco sammarco

2019-02-28 18:56

reporter   ~0114515

The problem exists even when use 64 cocoa crosscompile from my win 64 bit installation.

Bart Broersma

2019-02-28 19:10

reporter   ~0114516

Last edited: 2019-03-01 13:50

View 2 revisions

I wasn't even aware that we have a native 64-bit compiler on Windows...

francesco sammarco

2019-03-01 11:48

reporter   ~0114536

Has anyone managed to reproduce the bug?

Starchild

2019-05-27 16:04

reporter   ~0116435

Last edited: 2019-05-27 16:28

View 2 revisions

Steps to reproduce (using FPCUpDeluxe):
1. Install fixes3_2 FPC on an x64 Windows machine.
2. Install either the i386-win32 or x86_64-linux cross-compiler. The isssue is *not* specific to 32-bit cross-compilers created from x64.
3. Build a program that uses the following procedure using the cross-compiler and run it on the target platform. It will print the correct DateTime (meaning the Timestamp data is valid), but crash in TimestampToMSecs. When compiled using the native Win64 compiler, the correct result is printed and no crash occurs.

procedure TSTest;
var
  TS: TTimestamp;
  C: Comp;
begin
  TS.Time := $03777768;
  TS.Date := $000B3FB1;
  Writeln(FormatDateTime('yyyy-mm-dd tt', TimeStampToDateTime(TS))); // 2019-05-22 16:09:21
  C := TimestampToMSecs(TS);
  Writeln(C); // 63694224561000
end;

I've found that this is because the function uses SSE2 on Win64, while it uses legacy FPU instructions on Win32 and Linux64 (see https://forum.lazarus.freepascal.org/index.php/topic,45536.0.html).

After some further digging, the MSecsPerDay constant in SysUtils has some bogus value. It's way too high, causing the resulting value to be invalid and thus fistp fails.

Max Nazhalov

2019-05-27 18:21

reporter   ~0116436

> the MSecsPerDay constant in SysUtils has some bogus value
0x4194997000000000 is a floationg-point [double] representation of 86400000.0, and it certainly is not intended to be "fild" into FPU..

Jonas Maebe

2019-06-30 19:38

manager   ~0117020

See Sven's comment here: https://bugs.freepascal.org/view.php?id=9262#c117012

It seems that FPCUpDeluxe enabled something that is not yet supported after all.

Issue History

Date Modified Username Field Change
2019-02-25 16:22 francesco sammarco New Issue
2019-02-25 20:46 Jonas Maebe Note Added: 0114427
2019-02-26 08:24 francesco sammarco Note Added: 0114458
2019-02-27 00:32 Andrew S. Baker (ASB) Note Added: 0114477
2019-02-28 17:59 francesco sammarco File Added: test3.zip
2019-02-28 18:00 francesco sammarco Note Added: 0114509
2019-02-28 18:44 Bart Broersma Note Added: 0114513
2019-02-28 18:55 francesco sammarco Note Added: 0114514
2019-02-28 18:56 francesco sammarco Note Added: 0114515
2019-02-28 19:10 Bart Broersma Note Added: 0114516
2019-03-01 11:48 francesco sammarco Note Added: 0114536
2019-03-01 13:50 Bart Broersma Note Edited: 0114516 View Revisions
2019-05-27 16:04 Starchild Note Added: 0116435
2019-05-27 16:28 Starchild Note Edited: 0116435 View Revisions
2019-05-27 18:21 Max Nazhalov Note Added: 0116436
2019-06-30 19:38 Jonas Maebe Note Added: 0117020