Recent

Author Topic: FPC 3.2.2 - initialization section - how does the Compiler handle it ?  (Read 1022 times)

ALLIGATOR

  • New Member
  • *
  • Posts: 24
Re: FPC 3.2.2 - initialization section - how does the Compiler handle it ?
« Reply #15 on: October 28, 2024, 10:15:47 am »
Yes, you are only looking at the compiled content of your module - don't forget that the linker will run next and link your modules to RTL

It is RTL that will call these functions - order.... I don't know what order it will be, most likely sequential, starting with program unit and then sequentially.

Maybe someone more experienced will correct me if I am wrong.

paule32

  • Sr. Member
  • ****
  • Posts: 280
Re: FPC 3.2.2 - initialization section - how does the Compiler handle it ?
« Reply #16 on: October 28, 2024, 10:22:31 am »
you see? - this is my concerns - how FPC include the unit code and make code from it.
because, on Design time, you write:

uses SysUtils, Classes, Dialogs, ... ;

and my code - you can see, it is linear:

Code: Pascal  [Select][+][-]
  1. procedure fpc_initializeunits; [public, alias:'FPC_INITIALIZEUNITS']; compilerproc;
  2.     procedure CallProcedure(proc: TProcedure);
  3.     begin
  4.         if Assigned(proc) then
  5.             TProcedure(proc)();
  6.     end;
  7. var
  8.     Index: DWORD;
  9. begin
  10.     printf('Count Items: %d'#13#10, InitFinalTable.TableCount);
  11.     if InitFinalTable.TableCount > 0 then
  12.     begin
  13.         for Index := 1 to InitFinalTable.TableCount - 1 do
  14.         CallProcedure(InitFinalTable.Procs[Index].InitProc);
  15.     end;
  16. end;
  17.  

currently, I have one unit... and it works.
But I will check of two or more units ...

I overthinking too much things.
But the order of .o bject files can be changed - e.g. your order of "uses" directive ...

ALLIGATOR

  • New Member
  • *
  • Posts: 24
Re: FPC 3.2.2 - initialization section - how does the Compiler handle it ?
« Reply #17 on: October 28, 2024, 10:59:43 am »
It's pretty easy to determine in person
But you need to use a home-built compiler - because debugging symbols are required (and by the way, I highly recommend that you figure this out because it makes it easier to understand the inner workings of the compiler and RTL in many places). You just need to stand the debugger on the function of module initialization and see the order.
Here, for example, is the order of module initialization for a simple GUI application created by default:



INITPROCFINALPROC
pt^.TABLECOUNT = 87


pt^.PROCS[1]
SYSTEM__initSYSTEM__finalize
pt^.PROCS[2]
nilOBJPAS__finalize
pt^.PROCS[3]
LNFODWRF__initLNFODWRF__finalize
pt^.PROCS[4]
FPINTRES__initnil
pt^.PROCS[5]
nilWINDIRS__finalize
pt^.PROCS[6]
SYSUTILS__initSYSUTILS__finalize
pt^.PROCS[7]
TYPINFO__init_implicitTYPINFO__finalize_implicit
pt^.PROCS[8]
CLASSES__initCLASSES__finalize
pt^.PROCS[9]
FPCADDS__initnil
pt^.PROCS[10]
JSONSCANNER__init_implicitJSONSCANNER__finalize_implicit
pt^.PROCS[11]
VARIANTS__initVARIANTS__finalize
pt^.PROCS[12]
FPJSON__initFPJSON__finalize_implicit
pt^.PROCS[13]
JSONPARSER__initJSONPARSER__finalize
pt^.PROCS[14]
COMMCTRL__initCOMMCTRL__finalize
pt^.PROCS[15]
LAZFILEUTILS__initLAZFILEUTILS__finalize
pt^.PROCS[16]
FILEUTIL__init_implicitFILEUTIL__finalize_implicit
pt^.PROCS[17]
DOS__initnil
pt^.PROCS[18]
LCONVENCODING__init_implicitLCONVENCODING__finalize_implicit
pt^.PROCS[19]
nilLAZLOGGERBASE__finalize
pt^.PROCS[20]
AVL_TREE__initAVL_TREE__finalize
pt^.PROCS[21]
STRINGHASHLIST__initnil
pt^.PROCS[22]
TRANSLATIONS__init_implicitTRANSLATIONS__finalize_implicit
pt^.PROCS[23]
LAZUTF8__initLAZUTF8__finalize
pt^.PROCS[24]
FPIMAGE__initFPIMAGE__finalize
pt^.PROCS[25]
nilLAZTRACER__finalize
pt^.PROCS[26]
SYSTEM.UITYPES__initnil
pt^.PROCS[27]
GRAPHTYPE__initnil
pt^.PROCS[28]
LCLTYPE__init_implicitLCLTYPE__finalize_implicit
pt^.PROCS[29]
LCLPROC__initLCLPROC__finalize
pt^.PROCS[30]
LCLPLATFORMDEF__init_implicitLCLPLATFORMDEF__finalize_implicit
pt^.PROCS[31]
FPIMGCMN__initnil
pt^.PROCS[32]
FPREADBMP__initnil
pt^.PROCS[33]
FPWRITEBMP__initnil
pt^.PROCS[34]
FPREADPNG__initnil
pt^.PROCS[35]
FPWRITEPNG__initnil
pt^.PROCS[36]
FPCOLORSPACE__initFPCOLORSPACE__finalize_implicit
pt^.PROCS[37]
FPREADTIFF__initnil
pt^.PROCS[38]
FPWRITETIFF__initnil
pt^.PROCS[39]
LCLVERSION__initnil
pt^.PROCS[40]
FPCANVAS__init_implicitFPCANVAS__finalize_implicit
pt^.PROCS[41]
FPREADPNM__initnil
pt^.PROCS[42]
FPWRITEPNM__initnil
pt^.PROCS[43]
FPREADJPEG__initnil
pt^.PROCS[44]
FPWRITEJPEG__initnil
pt^.PROCS[45]
FPREADGIF__initnil
pt^.PROCS[46]
LRESOURCES__initLRESOURCES__finalize
pt^.PROCS[47]
SYSTEM.TIMESPAN__init_implicitSYSTEM.TIMESPAN__finalize_implicit
pt^.PROCS[48]
LCLINTF__initLCLINTF__finalize
pt^.PROCS[49]
GRAPHICS__initGRAPHICS__finalize
pt^.PROCS[50]
INTFGRAPHICS__initnil
pt^.PROCS[51]
THEMES__init_implicitTHEMES__finalize_implicit
pt^.PROCS[52]
INTERFACEBASE__initnil
pt^.PROCS[53]
MULTIMON__initnil
pt^.PROCS[54]
UXTHEME__initUXTHEME__finalize
pt^.PROCS[55]
DWMAPI__initDWMAPI__finalize
pt^.PROCS[56]
UNICODEDATA__init_implicitUNICODEDATA__finalize_implicit
pt^.PROCS[57]
FPPIXLCANV__init_implicitFPPIXLCANV__finalize_implicit
pt^.PROCS[58]
nilWSLCLCLASSES__finalize
pt^.PROCS[59]
ACTNLIST__initnil
pt^.PROCS[60]
nilWSMENUS__finalize
pt^.PROCS[61]
CLIPBRD__initCLIPBRD__finalize
pt^.PROCS[62]
FORMS__initFORMS__finalize
pt^.PROCS[63]
MENUS__init_implicitMENUS__finalize_implicit
pt^.PROCS[64]
IMGLIST__initnil
pt^.PROCS[65]
RTTIUTILS__init_implicitRTTIUTILS__finalize_implicit
pt^.PROCS[66]
CONTROLS__initCONTROLS__finalize
pt^.PROCS[67]
BUTTONS__init_implicitBUTTONS__finalize_implicit
pt^.PROCS[68]
EXTCTRLS__initEXTCTRLS__finalize_implicit
pt^.PROCS[69]
DIALOGRES__initDIALOGRES__finalize_implicit
pt^.PROCS[70]
COMCTRLS__init_implicitCOMCTRLS__finalize_implicit
pt^.PROCS[71]
DATEUTILS__init_implicitDATEUTILS__finalize_implicit
pt^.PROCS[72]
nilTASKDLGEMULATION__finalize
pt^.PROCS[73]
DIALOGS__initDIALOGS__finalize
pt^.PROCS[74]
WIN32EXTRA__initWIN32EXTRA__finalize
pt^.PROCS[75]
WIN32PROC__initWIN32PROC__finalize
pt^.PROCS[76]
CALCFORM__init_implicitCALCFORM__finalize_implicit
pt^.PROCS[77]
HTMLDEFS__init_implicitHTMLDEFS__finalize_implicit
pt^.PROCS[78]
MASKEDIT__initnil
pt^.PROCS[79]
LAZFILECACHE__initnil
pt^.PROCS[80]
nilLAZ2_XMLUTILS__finalize
pt^.PROCS[81]
LAZ2_DOM__init_implicitLAZ2_DOM__finalize_implicit
pt^.PROCS[82]
URIPARSER__init_implicitURIPARSER__finalize_implicit
pt^.PROCS[83]
LAZ2_XMLREAD__initLAZ2_XMLREAD__finalize_implicit
pt^.PROCS[84]
SHELLCTRLS__init_implicitSHELLCTRLS__finalize_implicit
pt^.PROCS[85]
WIN32WSDIALOGS__initWIN32WSDIALOGS__finalize_implicit
pt^.PROCS[86]
WIN32INT__initWIN32INT__finalize
pt^.PROCS[87]
INTERFACES__initINTERFACES__finalize

ALLIGATOR

  • New Member
  • *
  • Posts: 24
Re: FPC 3.2.2 - initialization section - how does the Compiler handle it ?
« Reply #18 on: October 28, 2024, 11:03:37 am »
Although that may not be quite the answer you're expecting..... it's a fait accompli of how modules will be loaded, but it doesn't answer the question - how is it regulated... but for that you need to dive deeper and analyze it.

paule32

  • Sr. Member
  • ****
  • Posts: 280
Re: FPC 3.2.2 - initialization section - how does the Compiler handle it ?
« Reply #19 on: October 28, 2024, 11:06:39 am »
ok, what a fat list  ;D
what debugger do you prefer - Laz or Gdb ?
I am a nerd in using debuggers.
But when I have the right one, it will be okay.

ALLIGATOR

  • New Member
  • *
  • Posts: 24
Re: FPC 3.2.2 - initialization section - how does the Compiler handle it ?
« Reply #20 on: October 28, 2024, 11:14:26 am »
I don't know much about debuggers either, but so far all my needs are covered by FpDebud
For the very advanced - there is a new promising solution of professional level (IMHO) - CPU-View, but I haven't tested it yet:
https://forum.lazarus.freepascal.org/index.php/topic,68962.0.html

PascalDragon

  • Hero Member
  • *****
  • Posts: 5755
  • Compiler Developer
Re: FPC 3.2.2 - initialization section - how does the Compiler handle it ?
« Reply #21 on: October 30, 2024, 10:46:28 pm »
I overthinking too much things.
But the order of .o bject files can be changed - e.g. your order of "uses" directive ...

The order of the object files is irrelevant. The compiler generates the INITFINAL table when a program or library is created and the entry point in SysInit passes this table towards the entry point of the RTL which can then access it using InitFinalTable.

 

TinyPortal © 2005-2018