Lazarus

Free Pascal => Windows => Topic started by: jakubklos on April 08, 2018, 08:36:05 am

Title: [Fixed] FPC 3.0.4 Compilation exception (fatal 1018)
Post by: jakubklos on April 08, 2018, 08:36:05 am
When I build a project it all works. Then I make a small change and even revert the change and select to compile. The compilation is aborted because of the problem below.
(I used lazbuild from the command line to get the exception because Lazarus hides it)

It must be some bug in the FPC compiler but not sure how to deal with this and would like to help to get this resolved.

Free Pascal Compiler version 3.0.4 [2018/02/25] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
(1002) Target OS: Win32 for i386
(3104) Compiling SimpleObjectsTest.dpr
(3104) Compiling SimpleObjects.pas
C:\Repository\mail_server\Components\Lib\tests\SimpleObjectsTest\SimpleObjects.pas(207,9) Warning: (5043) Symbol "Resume" is deprecated
Fatal: (1018) Compilation aborted
An unhandled exception occurred at $0044EFB6:
EAccessViolation: Access violation
  $0044EFB6
  $004E7F50
  $004F8FB4
  $004F9C8B
  $004F9B19
  $0053DA3F
  $00433098
  $00534F48
  $0053CA4B
  $00540050
  $004330D7
  $00413A79

Error: C:\lazarus\fpc\3.0.4\bin\i386-win32\ppc386.exe returned an error exitcode
Error: (lazarus) Compile Project, Mode: Windows, Target: SimpleObjectsTest.exe: stopped with exit code 1
Error: (lazbuild) failed compiling of project C:\Repository\mail_server\Components\Lib\tests\SimpleObjectsTest\SimpleObjectsTest.lpi
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: Handoko on April 08, 2018, 09:17:51 am
Hallo jakubklos,
Welcome to the  forum.

Simply showing your issue isn't very useful for us to be able to help you fixing the problem. You should provide more information like the source code or the steps to reproduce the issue, etc.

Have you tried to remove the lib folder? I sometimes get 'weird' compilation result but it can be solved if I delete the lib folder and recompile again.
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: jakubklos on April 08, 2018, 09:24:06 am
Hi Handoko
than you for your response.

Deleting the lib folder helps of course because it is the same as building the project. That works but after a change (possible only a time stamp modification of one unit file) the compilation breaks.

It is a huge project so I cannot share it easily. I was mainly asking for some guidelines to how debug / troubleshoot this.
Currently I am thinking about compiling the compiler with debug information so I get the stack of the error with line numbers and function names.
Nothing else comes to my mind.

Thank you
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: Thaddy on April 08, 2018, 11:45:08 am
Which mode are you using? ObjFpc or Delphi mode?
I have seen this in more than one question and usually you need to change the mode (for that specific unit).
It often is caused by implicit procedural pointers (as in mode delphi) as opposed to explicit procedural pointers (that need @) in mode ObjFpc.

If you mix them up you'll get e.g. @@, a (pointer to a pointer to a reference)  instead, which does kaboom! a.k.a your 1018.
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: jakubklos on April 08, 2018, 12:35:48 pm
I gave it some time and was able to filter all the required units from the big project to reproduce this issue.
It is only 3 units now. I am attaching the project.

Reproduction:

1. Open the lpi project in Lazarus
2. Open the TestUnit.pas
3. Compile
so far so good
4. Make a change in the TestUnit.pas (add something to fail a compilation like "aaaa"). Compile. It fails. Now revert the added text and compile again.
It should compile properly but does not. Instead if fails with the exception in my original post.

- If you comment out the TTestDataCollection definition in the TestUnit.pas it can compile without building
- If you make a change in the ListUnit (when the issue occurs) then again it can compile just fine because this unit gets recompiled

As you can see you cannot really use this in production because after any change you must rebuild the whole project.
Please, let me know what else to do

Thank you
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: WooBean on April 08, 2018, 02:46:28 pm
Hi  jakubklos,

I have failed to reproduce the error (win32, FPC 3.0.4, Lazarus 1.8 ) - recompiling after changing a source works for me with no errors.

As the issue is very strange I can suggest 2 things - check your hdd and then check file attributes (suspected no write access for the current user for some existing binary files ".o", ".ppu").

WooBean
 
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: howardpc on April 08, 2018, 03:46:20 pm
@jakubklos

You do not specify a {$mode} in your project or units, which means they default to mode fpc (not objfpc, or delphi), which is probably not what you want.

Perhaps the compilation problem arises from a weakness in generics syntax  somewhere (this is just a guess) or your combination of generics and interfaces, which probes more recent compiler changes and either exposes a bug, or requires a stricter syntax adherence on your part. The compiler's inability to flag a more specific compilation error, or pin-point an offending source line is obviously unhelpful.
Perhaps to get line number information you will have to build the FPC RTL with debug information?
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: wp on April 08, 2018, 03:50:45 pm
You do not specify a {$mode} in your project or units, which means they default to mode fpc (not objfpc, or delphi), which is probably not what you want.
Howard, is this really true? In the Lazarus project options ("Compiler options" > "Parsing") there's a setting for "Syntax mode (-M, {$MODE})". Isn't this the mode used when a mode is not specified for a unit?
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: Handoko on April 08, 2018, 03:59:58 pm
Tested and followed what jakubklos said. It is 100% reproducible on Lazarus 1.8.0 FPC 3.04 64-bit Gtk2 Linux.

Using compile (Ctrl+F9) will get a compile-time error but no error if I use Build (Shift+F9).
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: Thaddy on April 08, 2018, 04:02:52 pm
@wp
Yes, but afaik only on full rebuilds ( -B in fpc ). There are a lot of users that assume a certain setting because mode and modeswtiches can be pretty confusing.
Even in the current codebase there are units that make assumptions,
Note in production you always do a full rebuild anyway.... (to OP)
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: wp on April 08, 2018, 04:08:13 pm
I don't have much experience with generics, but is your declaration of generic classes correct? You declare
Code: Pascal  [Select][+][-]
  1. type  
  2.   TNullable<T> = Class(TObject)
  3.     ...
  4.   end;
According to http://wiki.freepascal.org/Generics#Custom_Generic_Classes, shouldn't this be like this?
Code: Pascal  [Select][+][-]
  1. type
  2.   generic TList<T> = class
  3.     ...
  4.   end;
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: mse on April 08, 2018, 04:17:53 pm
It happens sometimes that FPC crashes without -B, we have to live with it. IIRC Free Pascal core members wrote that it is not fixable without a complete redesign of unit handling. Sometimes it is even necessary to delete all *.ppu and *.o files.
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: Thaddy on April 08, 2018, 04:29:34 pm
I don't have much experience with generics, but is your declaration of generic classes correct? You declare
Code: Pascal  [Select][+][-]
  1. type  
  2.   TNullable<T> = Class(TObject)
  3.     ...
  4.   end;
According to http://wiki.freepascal.org/Generics#Custom_Generic_Classes, shouldn't this be like this?
Code: Pascal  [Select][+][-]
  1. type
  2.   generic TList<T> = class
  3.     ...
  4.   end;

The first one is delphi mode, the second one is fpc mode. Both are legal. But NOT in the same unit.
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: WooBean on April 08, 2018, 04:34:37 pm
Tested and followed what jakubklos said. It is 100% reproducible on Lazarus 1.8.0 FPC 3.04 64-bit Gtk2 Linux.

Using compile (Ctrl+F9) will get a compile-time error but no error if I use Build (Shift+F9).

My previous post was based on "build" compilation, now I tested "compile" (Ctrl+F9) mode (win32, FPC 3.4, Lazarus 1.8, code parsing mode -MDelphi) and problem signalled by TS appeared for me too. The problem may be in FPC(/Lazarus) - changed source (even when the change is reverted) is badly treated by FPC in "compile" and "quick compile" compilation (file timestamps not properly maintaned?).

WooBean

Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: Thaddy on April 08, 2018, 04:48:04 pm
Tested and followed what jakubklos said. It is 100% reproducible on Lazarus 1.8.0 FPC 3.04 64-bit Gtk2 Linux.

Using compile (Ctrl+F9) will get a compile-time error but no error if I use Build (Shift+F9).

My previous post was based on "build" compilation, now I tested "compile" (Ctrl+F9) mode (win32, FPC 3.4, Lazarus 1.8, code parsing mode -MDelphi) and problem signalled by TS appeared for me too. The problem may be in FPC(/Lazarus) - changed source (even when the change is reverted) is badly treated by FPC in "compile" and "quick compile" compilation (file timestamps not properly maintaned?).

WooBean
No. It is just the unit concept that causes this and that is a feature. People coming from other languages are unfamiliar with this behavior, but it allows for (much!) faster compiles. Touched units are recompiled in any case, but related code in un-touched units may have to be recompiled as well. Usually it is caused by bad design but that is not always the case.
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: mse on April 08, 2018, 05:44:59 pm
If
Quote
problem signalled by TS appeared for me too
means
Code: [Select]
EAccessViolation: Access violation
  $0044EFB6
  $004E7F50
  $004F8FB4
...
that is a bug in FPC which is "unfixable", please read above.
http://forum.lazarus.freepascal.org/index.php/topic,40839.msg282420.html#msg282420
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: howardpc on April 08, 2018, 06:25:18 pm
You do not specify a {$mode} in your project or units, which means they default to mode fpc (not objfpc, or delphi), which is probably not what you want.
Howard, is this really true? In the Lazarus project options ("Compiler options" > "Parsing") there's a setting for "Syntax mode (-M, {$MODE})". Isn't this the mode used when a mode is not specified for a unit?

Werner, you are right, of course, for Lazarus projects.
I was thinking of FPC command line compilation of .pas files for which mode fpc is the default if no mode is specified (which is not relevant here).
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: jakubklos on April 09, 2018, 08:29:52 am
The issue does not occur on Linux with FPC 2.4.6
We could stick with 2.4.6 but the support for unicode filenames on Windows is crucial for us.
Looks like we will be stuck with old Delphi then :(. I was so hoping to get rid of it and use Lazarus
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: WooBean on April 09, 2018, 08:47:24 am
The issue does not occur on Linux with FPC 2.4.6
We could stick with 2.4.6 but the support for unicode filenames on Windows is crucial for us.
Looks like we will be stuck with old Delphi then :(. I was so hoping to get rid of it and use Lazarus
Crazy Monday?
It is not a good time to such strategic decision! The only problem is to press "build" instead of "compile" (or specify -B parameter in comand line for compiler), as far as I can undersand the topic.

WooBean
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: jakubklos on April 09, 2018, 08:56:34 am
Yes, that is true. But if you have hundreds of units it takes a few minutes for the build to finish. We wanted to migrate from Delphi because of the IDE horror (instability, slowness etc.) I have been using Lazarus for more than 2 years on Linux and I am happy with it. Now I wanted all developers to work in Lazarus but if there are issues like this they will not like me very much ;)
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: WooBean on April 09, 2018, 10:27:17 am
Yes, that is true. But if you have hundreds of units it takes a few minutes for the build to finish. We wanted to migrate from Delphi because of the IDE horror (instability, slowness etc.) I have been using Lazarus for more than 2 years on Linux and I am happy with it. Now I wanted all developers to work in Lazarus but if there are issues like this they will not like me very much ;)
Just guessing why you are in trouble I found in the Net some comments on huge time (minutes) compilation in Delphi (10.2 actually) when using generics. It seems to me,  that generics approache coding touches (in FPC too) so much of existing libraries ("hiddenly" used by a compiler) and needs checking (and replacing something) almost everywhere what forces a user to wait, wait .... . And it is your case, probably.

WooBean
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: Thaddy on April 09, 2018, 11:49:30 am
I am also guessing, but I am almost sure that my previous answer is the reason. {$mode objfpc} is still the default for Lazarus and he is porting Delphi code....So needs {$mode delphi} or {$mode delphiunicode}.
Once he understands that he should have no problem to port - older - Delphi code to Lazarus. < @@@@@@@@@@@...... O:-)> (yes.. pointer references)


Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: jakubklos on April 10, 2018, 08:23:26 am
I have changed the whole project to ObjFPC mode and it does not help. The behavior is the same.
Almost every 2nd unit suffers from this issue btw. So you can imagine how long it took me to re-build and re-build and finish porting the project. It took hours because of this issue.
Would it make a difference if I post this isse directly to the FPC bug tracker?
Thank you
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: mse on April 10, 2018, 09:04:20 am
Would it make a difference if I post this isse directly to the FPC bug tracker?
If it is reproducible I definitely would submit a bug report.

Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: jakubklos on April 10, 2018, 10:00:27 am
Thank you, will do

I compiled a debug version of the compiler and got stack with line numbers:

EAccessViolation: Access violation
  $004575E9 line 370 of symbase.pas
  $004FBB62 line 401 of pdecl.pas
  $004FB016 line 626 of pdecl.pas
  $004FBBF3 line 876 of pdecl.pas
  $0050D967 line 2218 of psub.pas
  $00509EFF line 307 of psub.pas
  $0050CCE9 line 1808 of psub.pas
  $0050D158 line 1959 of psub.pas
  $0050DE78 line 2394 of psub.pas
  $0050DD01 line 2425 of psub.pas
  $00422D0C line 1756 of cclasses.pas
  $0050DF71 line 2434 of psub.pas
  $005544A0 line 1057 of pmodules.pas
  $005543AC line 981 of pmodules.pas
  $00438D5D line 368 of parser.pas
  $0054B4D4 line 1734 of fppu.pas
  $005532E6 line 484 of pmodules.pas

It's definitely a problem with generics as it fails in the determine_generic_def function and it must be new to FPC 3.0 when all the generics have been updated/reworked
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: jakubklos on April 10, 2018, 10:21:30 am
I have filed an issue to the FPC bug trackker
https://bugs.freepascal.org/view.php?id=33593
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: Thaddy on April 10, 2018, 10:44:16 am
I have changed the whole project to ObjFPC mode and it does not help. The behavior is the same.
Almost every 2nd unit suffers from this issue btw. So you can imagine how long it took me to re-build and re-build and finish porting the project. It took hours because of this issue.
Would it make a difference if I post this isse directly to the FPC bug tracker?
Thank you
That's what you should NOT have done. Or you should do the opposite! Mode Delphi! when converting manually.
You should ONLY convert visual parts with the  converter and any non-visual units or libraries should be mode delphi.
Usually the converter does a good  job, but not on large projects.
Code: Pascal  [Select][+][-]
  1. {$ifdef fpc}{$mode delphi}{$endif}
Note that I personally would not recommend ObjFpc mode at all. It should be on the way out. But that is opinionated.
The above advice should be sufficient.
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: jakubklos on April 10, 2018, 10:46:42 am
The whole test project was tested with both the Delphi mode and ObjFPC. None of them work and suffer from the same issue.
There are no visual parts. It is only 3 units for the test purpose
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: Thaddy on April 10, 2018, 11:20:43 am
In that case I bet you - if it compiles under Delphi pre X series - I can fix that in less than half a day. If it pure pascal probably in less than an hour. And keep it compatible. If it is pure pascal. With some assembler code it takes max a day. (three units?). I usually win those bets.....

[edit] here you go....
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: jakubklos on April 10, 2018, 11:30:41 am
I am not sure if it compiles on pre X, it does compile with XE2 though. The code involves generics and the crash is in the compiler and is related to generics.
If you really think you can fix the compiler I am willing to take that bet :)
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: Thaddy on April 10, 2018, 12:13:39 pm
No need. I fixed your code mess.......

See attachment in my previous post..... <grumpy ... >:D > I am not here to clean up code for professional programmers.
http://forum.lazarus.freepascal.org/index.php?action=dlattach;topic=40839.0;attach=26134
Now...Well within an hour.... 8-) O:-) O:-) And still delphi compatible....
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: Thaddy on April 10, 2018, 12:28:10 pm
A nice reward for our bet would be to close the bug report.  O:-) :D ;D ;D
Because the fatal error was correct and your code was a mess....

And that code that your provided never compiled on XE too...(it does not know that syntax)  Messing up modes, as I wrote before....
If it is a huge project, contact me.
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: ccrause on April 10, 2018, 01:33:38 pm
Because the fatal error was correct and your code was a mess....
My expectation of the compiler is to report syntax and other code errors to the user, not puke all over itself when confronted with an invalid construct.  So regardless of whatever user code errors there may be in this case, the compilers should still not raise an exception - thus in my opinion there is a compiler bug.
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: Thaddy on April 10, 2018, 01:56:39 pm
That's exactly what it - the compiler - did.... Try all the code yourself and you see why. He made a mess. It is not a compiler CRASH it is a fatal error because of the FOOD and it terminates gracefully with a nice error message.... Now... How Trump-like are you????
(I know you are not, but just in case: again this is about bad code and the compiler will not eat it. Check for yourself. You have my permission to fire him...)
ATM there is no dwim compiler.... It just says: ok if you f*(British u on the keyboard)ck up I'll have a tea break... and rightly so, because this was a REAL mess. And was fixed in 30 minutes.

Pointer mistakes by professionals. That was the post-mortem... I Lazarussed his code.... O:-)
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: jakubklos on April 10, 2018, 02:15:45 pm
Hats off to Thaddy!
After fixing the generic pointers mess (you are right, it was a mess but I didn't write the code :)) it really works.
I wonder how you managed to pin point the origin of the issue.
Thank you again.
Title: Re: FPC 3.0.4 Compilation exception (fatal 1018)
Post by: PascalDragon on April 13, 2018, 02:58:42 pm
That's exactly what it - the compiler - did.... Try all the code yourself and you see why. He made a mess. It is not a compiler CRASH it is a fatal error because of the FOOD and it terminates gracefully with a nice error message.... Now... How Trump-like are you????

It is indeed a compiler crash, because every exception occurring in the compiler is a crash by definition. If it's merely a programmer's mistake then the compiler should complain to the user and continue parsing as far as feasible and not raise an exception. I can even reproduce the error with a simple example.
Title: Re: [Fixed] FPC 3.0.4 Compilation exception (fatal 1018)
Post by: Thaddy on April 13, 2018, 04:32:49 pm
Strange. In that case I misunderstood that part. Anyway: his code is fixed.
TinyPortal © 2005-2018