Lazarus

Free Pascal => FPC development => Topic started by: Okoba on April 20, 2020, 07:41:09 am

Title: Make system unit
Post by: Okoba on April 20, 2020, 07:41:09 am
Hi,

I wanted to try making a new system unit for a test, as explained here:
https://wiki.freepascal.org/System_unit
I made a system.pas unit into a blank project without any package and added the code explained in the wiki page, but In the last stable Lazarus and also Trunk, it gives an error on the "interface" line and says:
Quote
system.pas(3,1) Error: Internal error 2016060303

Am I missing something?
Title: Re: Make system unit
Post by: marcov on April 20, 2020, 10:07:46 am
Yes, look at the parameters:

e:\archive>fpc -h |grep -i system
     -T<x>  Target operating system:
      -Us        Compile a system unit
      -Xn        Use target system native linker instead of GNU ld (Solaris, AIX)

A system unit must be compiled with -Us, since it must not implicitely  import the system unit obviously.
Title: Re: Make system unit
Post by: Okoba on April 20, 2020, 10:12:04 am
If you mean adding -Us to project custom options I did it already.
To be more precise I did these:
Title: Re: Make system unit
Post by: PascalDragon on April 20, 2020, 11:56:30 am
I wanted to try making a new system unit for a test, as explained here:
https://wiki.freepascal.org/System_unit
I made a system.pas unit into a blank project without any package and added the code explained in the wiki page, but In the last stable Lazarus and also Trunk, it gives an error on the "interface" line and says:
Quote
system.pas(3,1) Error: Internal error 2016060303

I wouldn't advice to use that article as a base. There is quite some functionality required inside the System unit that the compiler expects to be there.

What exactly are you trying to achieve in the end?
Title: Re: Make system unit
Post by: Okoba on April 20, 2020, 12:03:55 pm
Learning.
As I read the Docs I found out the System unit is the only unit added if we use FPC mode, and we can make our own if we have the requirements, so I like to do that.
Title: Re: Make system unit
Post by: PascalDragon on April 20, 2020, 12:27:05 pm
I suggest you to take a look at the Embedded target then. It has a more minimal System unit. Best try to remove stuff until things don't compile to find out what's required and what is not.
Also depending on the platform it's not true that no further unit is added, because for example on Windows the SysInit unit is also used, because that contains the entry point for the binary.
Title: Re: Make system unit
Post by: Okoba on April 20, 2020, 12:32:05 pm
Interesting point on Sysinit. But I think there is another problem, as I said it will give error on interface and not the code. It seems something else is missing.
Maybe @marcov knows about it.
Title: Re: Make system unit
Post by: PascalDragon on April 20, 2020, 01:10:35 pm
The internal error occurs when the compiler tries to create its internal types for use inside the System unit, but it already exists. Try to compile with -vut to check whether it really does not try to use the distributed System unit. Or pass -n so that the compiler does not use its configuration file (where the search paths are defined).
Title: Re: Make system unit
Post by: Okoba on April 20, 2020, 01:56:44 pm
If I add -n it gives an error for fpintres but I added that too and it goes back to the error.
I attached a sample project for test.
Title: Re: Make system unit
Post by: Okoba on June 28, 2020, 12:19:41 am
Any idea on this will help.
Title: Re: Make system unit
Post by: marcov on June 28, 2020, 03:00:59 pm
Hmm, seems 3.2.0 gives more verbose errors in such case:

Quote
D:\Testing\minrtl>fpc -Us system
Free Pascal Compiler version 3.2.0 [2020/06/04] for i386
Copyright (c) 1993-2020 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling system.pas
system.pas(12,1) Fatal: Internal type "TEXCEPTADDR" was not found. Check if you use the correct run time library.
Fatal: Compilation aborted
Error: d:\FPC\3.2.0\bin\i386-Win32\ppc386.exe returned an error exitcode
Title: Re: Make system unit
Post by: Okoba on June 28, 2020, 03:16:39 pm
If I try to run the project with Lazarus it gives the error I said before.
Title: Re: Make system unit
Post by: PascalDragon on June 28, 2020, 04:53:09 pm
You must not manually add the unit fpintres to the uses clause, that is done by the compiler (and it's automatically removed again if not needed, but the compiler simply needs the unit available).
Title: Re: Make system unit
Post by: Okoba on June 28, 2020, 06:06:15 pm
Thanks for the point. I removed it but the error is still the same.
Title: Re: Make system unit
Post by: PascalDragon on June 28, 2020, 06:59:19 pm
I get the following:

Code: [Select]
Free Pascal Compiler version 3.0.4 [2020/04/11] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Win64 for x64
Compiling .\project1.lpr
Linking project1.exe
project1.lpr(5,1) Error: Entrypoint _mainCRTStartup not defined
project1.lpr(5,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: C:\lazarus\2.0.8\fpc\3.0.4\bin\x86_64-win64\ppcx64.exe returned an error exitcode

And with FPC 3.2.0 or newer I get the error that marcov mentioned.
Title: Re: Make system unit
Post by: Okoba on June 28, 2020, 07:19:04 pm
You are using fpc directly. Did you try opening the Lazarus project I attached? My response was based on that.
Title: Re: Make system unit
Post by: marcov on June 28, 2020, 07:20:41 pm
That sets -Us for all units in the project, that won't work.
Title: Re: Make system unit
Post by: Okoba on June 28, 2020, 07:23:33 pm
So I should compile the system unit directly and put the result in the lib directory to use with the project?
My intention is to find a way to replace system unit in a hopefully simple manner so I can work on it and test things.
Title: Re: Make system unit
Post by: PascalDragon on June 29, 2020, 09:43:19 am
For quite some time already FPC automatically applies (https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/compiler/pmodules.pas?view=markup#l913) the -Us switch to the unit named System, so you don't need the -Us switch (I didn't use it when compiling from the command line either).
Title: Re: Make system unit
Post by: Okoba on June 29, 2020, 06:24:40 pm
You are right, removeing -Us solved it. I added other types that it needed and now it want to compile objpas unit.
Any idea?
Code: Pascal  [Select][+][-]
  1. unit system;
  2. {$MODE FPC}
  3. interface
  4.  
  5. type
  6.   hresult = longint;
  7.   DWord = LongWord;
  8.   Cardinal = LongWord;
  9.   Integer = SmallInt;
  10.   UInt64 = QWord;
  11.   TTypeKind = (tkUnknown, tkInteger, tkChar, tkEnumeration, tkFloat, tkSet,
  12.     tkMethod, tkSString, tkLString, tkAString, tkWString, tkVariant, tkArray,
  13.     tkRecord, tkInterface, tkClass, tkObject, tkWChar, tkBool, tkInt64, tkQWord,
  14.     tkDynArray, tkInterfaceRaw, tkProcVar, tkUString, tkUChar, tkHelper, tkFile,
  15.     tkClassRef, tkPointer);
  16.  
  17. type
  18.   jmp_buf = packed record
  19.     rbx, rbp, r12, r13, r14, r15, rsp, rip: QWord;
  20. {$IFDEF win64}
  21.     rsi, rdi: QWord;
  22.     xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15: record m1,
  23.       m2: QWord;
  24.   end;
  25.  
  26. mxcsr:
  27. LongWord;
  28. fpucw:
  29. word;
  30. padding:
  31. word;
  32. {$ENDIF win64}
  33. end;
  34. pjmp_buf = ^jmp_buf;
  35. PExceptAddr = ^TExceptAddr;
  36. TExceptAddr = record buf: pjmp_buf;
  37. next:
  38. PExceptAddr;
  39. {$IFDEF CPU16}
  40. frametype:
  41. SmallInt;
  42. {$ELSE CPU16}
  43. frametype:
  44. longint;
  45. {$ENDIF CPU16}
  46. end;
  47. PGuid = ^TGuid;
  48. TGuid = packed record
  49. case Integer of
  50.   1:
  51.     (Data1: DWord;
  52.       Data2: word;
  53.       Data3: word;
  54.       Data4: array [0 .. 7] of byte;
  55.     );
  56.   2:
  57.     (D1: DWord;
  58.       D2: word;
  59.       D3: word;
  60.       D4: array [0 .. 7] of byte;
  61.     );
  62.   3:
  63.     ( { uuid fields according to RFC4122 }
  64.       time_low: DWord; // The low field of the timestamp
  65.       time_mid: word; // The middle field of the timestamp
  66.       time_hi_and_version: word;
  67.       // The high field of the timestamp multiplexed with the version number
  68.       clock_seq_hi_and_reserved: byte;
  69.       // The high field of the clock sequence multiplexed with the variant
  70.       clock_seq_low: byte; // The low field of the clock sequence
  71.       node: array [0 .. 5] of byte; // The spatially unique node identifier
  72.     );
  73. end;
  74.  
  75. var
  76.   exitCode: hresult = 0;
  77. export name 'operatingsystem_result';
  78.  
  79. implementation
  80.  
  81. procedure initializeUnits;
  82. alias:
  83. 'FPC_INITIALIZEUNITS';
  84.  
  85. begin
  86.  
  87. end;
  88.  
  89. procedure doExit;
  90. alias:
  91. 'FPC_DO_EXIT';
  92.  
  93. begin
  94.  
  95. end;
  96.  
  97. end.
Title: Re: Make system unit
Post by: PascalDragon on June 30, 2020, 09:57:44 am
That is because your project's mode is set to ObjFPC (Lazarus will pass a -MObjFPC parameter to the compiler then) which automatically leads to an insertion of the ObjPas unit. Either change your project's mode in Project Settings -> Compiler Settings -> Parsing or add a {$mode fpc} to your main program file.
Title: Re: Make system unit
Post by: Okoba on June 30, 2020, 02:49:15 pm
you were right, it solve the problem but now it can not find this:
Code: Pascal  [Select][+][-]
  1. Unknown compilerproc "fpc_initializeunits". Check if you use the correct run time library.
You pointed out very good points but wiki seams out of date, that is why it looks more complicated than it should.
I attached the project too.
Title: Re: Make system unit
Post by: PascalDragon on June 30, 2020, 03:20:23 pm
you were right, it solve the problem but now it can not find this:
Code: Pascal  [Select][+][-]
  1. Unknown compilerproc "fpc_initializeunits". Check if you use the correct run time library.

You need to add a procedure fpc_initializeunits; compilerproc; both in the interface and implementation section.

You pointed out very good points but wiki seams out of date, that is why it looks more complicated than it should.

There aren't many people that try to write their own, minimal System unit and we core devs don't care about that Wiki article, thus it only gets updates (if at all) if someone tries to do that again...
Title: Re: Make system unit
Post by: Okoba on June 30, 2020, 03:29:19 pm
You are right. I added that and some more and it now compiles, although next step is making debugger works.
I attached the project for the future.
Title: Re: Make system unit
Post by: Mussel on January 07, 2022, 01:03:25 pm
I am stuck in the same situation:

It says "Internal type "TEXCEPTADDR" was not found" when trying to compile system.pas.

I have followed the rules set out by https://wiki.freepascal.org/System_unit, and although my system.pas derived from https://wiki.osdev.org/Pascal_Bare_Bones

What have I done wrong?

The following are compilation errors. I installed fpc-3.2.0.i386-linux (overwriting fpc-3.2.0-x86_64-linux).
Code: Text  [Select][+][-]
  1. boo@debian:~$ fpc -Us  -vut system.pas
  2. Configfile search: /home/boo/.fpc.cfg
  3. Reading options from file /home/boo/.fpc.cfg
  4. Path "./fpc/lib/fpc/3.2.0/units/i386-linux/" not found
  5. Path "./fpc/lib/fpc/3.2.0/units/i386-linux/*/" not found
  6. Path "./fpc/lib/fpc/3.2.0/units/i386-linux/rtl/" not found
  7. Path "./fpc/lib/fpc/3.2.0/units/i386-linux/httpd22/" not found
  8. Path "./.fppkg/lib/fpc/3.2.0/units/i386-linux/*/" not found
  9. Path "./fpc/lib/fpc/3.2.0/lib/i386-linux/" not found
  10. Free Pascal Compiler version 3.2.0 [2020/06/09] for i386
  11. Copyright (c) 1993-2020 by Florian Klaempfl and others
  12. Searching file /lib/ld-linux.so.2... found
  13. Path "/usr/X11R6/lib/" not found
  14. Compiler: /usr/lib/fpc/3.2.0/ppc386
  15. Target OS: Linux for i386
  16. Using executable path: /usr/lib/fpc/3.2.0/
  17. Using unit path: /usr/lib/fpc/3.2.0/units/i386-linux/rtl/
  18. Using unit path: /usr/lib/fpc/3.2.0/
  19. Using library path: /usr/lib/i386-linux-gnu/
  20. Using library path: /lib/
  21. Using library path: /usr/lib/
  22. Using library path: /usr/lib/gcc/x86_64-linux-gnu/10/
  23. Using library path: /usr/lib/fpc/3.2.0/units/i386-linux/rtl/
  24. Using library path: /usr/lib/fpc/3.2.0/
  25. Using object path: /usr/lib/fpc/3.2.0/units/i386-linux/rtl/
  26. Using object path: /usr/lib/fpc/3.2.0/
  27. Compiling system.pas
  28. Searching file system.pas... found
  29. (SYSTEM)   Loading interface units from SYSTEM
  30. system.pas(5,1) (system)   Parsing interface of unit system
  31. (system)   Loading implementation units from SYSTEM
  32. system.pas(18,1) (system)   Parsing implementation of SYSTEM
  33. system.pas(18,1) Fatal: Internal type "TEXCEPTADDR" was not found. Check if you use the correct run time library.
  34. Fatal: Compilation aborted
  35. Error: /usr/bin/ppc386 returned an error exitcode
  36.  
Title: Re: Make system unit
Post by: AlexTP on January 07, 2022, 01:52:03 pm
I just added the info from @PascalDragon and @Okoba to the wiki
https://wiki.freepascal.org/System_unit
Title: Re: Make system unit
Post by: ccrause on January 07, 2022, 01:58:32 pm
I am stuck in the same situation:

It says "Internal type "TEXCEPTADDR" was not found" when trying to compile system.pas.

I have followed the rules set out by https://wiki.freepascal.org/System_unit, and although my system.pas derived from https://wiki.osdev.org/Pascal_Bare_Bones

What have I done wrong?

Look in the attachment of @Okoba...

The compiler expects some system defined types to be defined when parsing a subroutine (https://gitlab.com/freepascal.org/fpc/source/-/blob/release_3_2_0/compiler/psub.pas#L1846) such as the implementation section of system.pas.  This means you have to add some type definitions to system.pas.

It appears that this check was added to 3.2.0, so it is perhaps time to update the osdev example by some knowledgeable person  :-[

Edit: Thanks @Alextp, I see you where quicker and already updated the freepascal wiki.
Title: Re: Make system unit
Post by: furaidi on December 29, 2022, 12:43:48 pm
It says "Internal type "TEXCEPTADDR" was not found" when trying to compile system.pas.

I have followed the rules set out by https://wiki.freepascal.org/System_unit, and although my system.pas derived from https://wiki.osdev.org/Pascal_Bare_Bones

What have I done wrong?

Nothing, my friend. I'm just went to verify my last changes to that topic and found out same situation with system.pas. Now I'm gathering all my knowledge again (didn't used fpc for a long time) and I'll reassemble old topic for fpc-3.2.0+
Just if  I'm not too late, lol
Title: Re: Make system unit
Post by: Okoba on December 29, 2022, 01:20:24 pm
Thank you @AlexTP.
Title: Re: Make system unit
Post by: furaidi on December 29, 2022, 01:51:15 pm
Done. I've tested a few times building with different attributes and now https://wiki.osdev.org/Pascal_Bare_Bones (https://wiki.osdev.org/Pascal_Bare_Bones) works again.
TinyPortal © 2005-2018