Make system unit lazarus / 64-FPC development ---------------------------------------------------------------------- Okoba · 2020-04-20 05:41 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: Quotesystem.pas(3,1) Error: Internal error 2016060303 Am I missing something? ---------------------------------------------------------------------- marcov · 2020-04-20 08:07 Yes, look at the parameters: e:\archive>fpc -h |grep -i system      -T  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. ---------------------------------------------------------------------- Okoba · 2020-04-20 08:12 If you mean adding -Us to project custom options I did it already. To be more precise I did these: Make a new black project in FPC and Lazarus TrunkAdd a new unit called system.pasAdd the code from the wiki pageAdd -Usto custom options in project optionsCompile and get the error at the interface with this number 2016060303 ---------------------------------------------------------------------- PascalDragon · 2020-04-20 09:56 Quote from: OkobaPatino on April 20, 2020, 07:41:09 amI 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: Quotesystem.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? ---------------------------------------------------------------------- Okoba · 2020-04-20 10:03 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. ---------------------------------------------------------------------- PascalDragon · 2020-04-20 10:27 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. ---------------------------------------------------------------------- Okoba · 2020-04-20 10:32 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. ---------------------------------------------------------------------- PascalDragon · 2020-04-20 11:10 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). ---------------------------------------------------------------------- Okoba · 2020-04-20 11:56 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. ---------------------------------------------------------------------- Okoba · 2020-06-27 22:19 Any idea on this will help. ---------------------------------------------------------------------- marcov · 2020-06-28 13:00 Hmm, seems 3.2.0 gives more verbose errors in such case: QuoteD:\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 ---------------------------------------------------------------------- Okoba · 2020-06-28 13:16 If I try to run the project with Lazarus it gives the error I said before. ---------------------------------------------------------------------- PascalDragon · 2020-06-28 14:53 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). ---------------------------------------------------------------------- Okoba · 2020-06-28 16:06 Thanks for the point. I removed it but the error is still the same. ---------------------------------------------------------------------- PascalDragon · 2020-06-28 16:59 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. ---------------------------------------------------------------------- Okoba · 2020-06-28 17:19 You are using fpc directly. Did you try opening the Lazarus project I attached? My response was based on that. ---------------------------------------------------------------------- marcov · 2020-06-28 17:20 That sets -Us for all units in the project, that won't work. ---------------------------------------------------------------------- Okoba · 2020-06-28 17:23 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. ---------------------------------------------------------------------- PascalDragon · 2020-06-29 07:43 For quite some time already FPC automatically applies 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). ---------------------------------------------------------------------- Okoba · 2020-06-29 16:24 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit system;{$MODE FPC}interface type  hresult = longint;  DWord = LongWord;  Cardinal = LongWord;  Integer = SmallInt;  UInt64 = QWord;  TTypeKind = (tkUnknown, tkInteger, tkChar, tkEnumeration, tkFloat, tkSet,    tkMethod, tkSString, tkLString, tkAString, tkWString, tkVariant, tkArray,    tkRecord, tkInterface, tkClass, tkObject, tkWChar, tkBool, tkInt64, tkQWord,    tkDynArray, tkInterfaceRaw, tkProcVar, tkUString, tkUChar, tkHelper, tkFile,    tkClassRef, tkPointer); type  jmp_buf = packed record    rbx, rbp, r12, r13, r14, r15, rsp, rip: QWord;{$IFDEF win64}    rsi, rdi: QWord;    xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15: record m1,      m2: QWord;  end; mxcsr:LongWord;fpucw:word;padding:word;{$ENDIF win64}end;pjmp_buf = ^jmp_buf;PExceptAddr = ^TExceptAddr;TExceptAddr = record buf: pjmp_buf;next:PExceptAddr;{$IFDEF CPU16}frametype:SmallInt;{$ELSE CPU16}frametype:longint;{$ENDIF CPU16}end;PGuid = ^TGuid;TGuid = packed recordcase Integer of  1:    (Data1: DWord;      Data2: word;      Data3: word;      Data4: array [0 .. 7] of byte;    );  2:    (D1: DWord;      D2: word;      D3: word;      D4: array [0 .. 7] of byte;    );  3:    ( { uuid fields according to RFC4122 }      time_low: DWord; // The low field of the timestamp      time_mid: word; // The middle field of the timestamp    time_hi_and_version: word;      // The high field of the timestamp multiplexed with the version number      clock_seq_hi_and_reserved: byte;      // The high field of the clock sequence multiplexed with the variant      clock_seq_low: byte; // The low field of the clock sequence      node: array [0 .. 5] of byte; // The spatially unique node identifier    );end; var  exitCode: hresult = 0;export name 'operatingsystem_result'; implementation procedure initializeUnits;alias:'FPC_INITIALIZEUNITS'; begin end; procedure doExit;alias:'FPC_DO_EXIT'; begin end; end. ---------------------------------------------------------------------- PascalDragon · 2020-06-30 07:57 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. ---------------------------------------------------------------------- Okoba · 2020-06-30 12:49 you were right, it solve the problem but now it can not find this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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. ---------------------------------------------------------------------- PascalDragon · 2020-06-30 13:20 Quote from: OkobaPatino on June 30, 2020, 02:49:15 pmyou were right, it solve the problem but now it can not find this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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. Quote from: OkobaPatino on June 30, 2020, 02:49:15 pmYou 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... ---------------------------------------------------------------------- Okoba · 2020-06-30 13:29 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. ---------------------------------------------------------------------- Mussel · 2022-01-07 12:03 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i boo@debian:~$ fpc -Us  -vut system.pasConfigfile search: /home/boo/.fpc.cfgReading options from file /home/boo/.fpc.cfgPath "./fpc/lib/fpc/3.2.0/units/i386-linux/" not foundPath "./fpc/lib/fpc/3.2.0/units/i386-linux/*/" not foundPath "./fpc/lib/fpc/3.2.0/units/i386-linux/rtl/" not foundPath "./fpc/lib/fpc/3.2.0/units/i386-linux/httpd22/" not foundPath "./.fppkg/lib/fpc/3.2.0/units/i386-linux/*/" not foundPath "./fpc/lib/fpc/3.2.0/lib/i386-linux/" not foundFree Pascal Compiler version 3.2.0 [2020/06/09] for i386Copyright (c) 1993-2020 by Florian Klaempfl and othersSearching file /lib/ld-linux.so.2... foundPath "/usr/X11R6/lib/" not foundCompiler: /usr/lib/fpc/3.2.0/ppc386Target OS: Linux for i386Using executable path: /usr/lib/fpc/3.2.0/Using unit path: /usr/lib/fpc/3.2.0/units/i386-linux/rtl/Using unit path: /usr/lib/fpc/3.2.0/Using library path: /usr/lib/i386-linux-gnu/Using library path: /lib/Using library path: /usr/lib/Using library path: /usr/lib/gcc/x86_64-linux-gnu/10/Using library path: /usr/lib/fpc/3.2.0/units/i386-linux/rtl/Using library path: /usr/lib/fpc/3.2.0/Using object path: /usr/lib/fpc/3.2.0/units/i386-linux/rtl/Using object path: /usr/lib/fpc/3.2.0/Compiling system.pasSearching file system.pas... found(SYSTEM)   Loading interface units from SYSTEMsystem.pas(5,1) (system)   Parsing interface of unit system(system)   Loading implementation units from SYSTEMsystem.pas(18,1) (system)   Parsing implementation of SYSTEMsystem.pas(18,1) Fatal: Internal type "TEXCEPTADDR" was not found. Check if you use the correct run time library.Fatal: Compilation abortedError: /usr/bin/ppc386 returned an error exitcode ---------------------------------------------------------------------- AlexTP · 2022-01-07 12:52 I just added the info from @PascalDragon and @Okoba to the wiki https://wiki.freepascal.org/System_unit ---------------------------------------------------------------------- ccrause · 2022-01-07 12:58 Quote from: Mussel on January 07, 2022, 01:03:25 pmI 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 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. ---------------------------------------------------------------------- furaidi · 2022-12-29 11:43 Quote from: Mussel on January 07, 2022, 01:03:25 pmIt 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 ---------------------------------------------------------------------- Okoba · 2022-12-29 12:20 Thank you @AlexTP. ---------------------------------------------------------------------- furaidi · 2022-12-29 12:51 Done. I've tested a few times building with different attributes and now https://wiki.osdev.org/Pascal_Bare_Bones works again.