Pascal JIT lazarus / 64-FPC development ---------------------------------------------------------------------- tihory · 2021-05-19 10:47 Hi, I'm interested to implement a Pascal JIT linker, so I implemented a COFF 64bit linker and link object files generated by FPC trunk then link them with DLL dependencies like "kernel32.dll" and "user32.dll". Project source code is available at https://github.com/tihorygit/TheLinker. Now I have a problem with linking FPC compiler functions like "fpc_initializeunits". After files linked together, some of these functions point to an invalid location in object memory and cause an access violation exception. I read Pascal TInternalLinker code but didn't find any solution, is anyone experience with linkers to help me or have a solution? ---------------------------------------------------------------------- Leledumbo · 2021-05-19 21:31 The function is defined in rtl/inc/system.inc and is included in every system unit implementation: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i $ grep -ir fpc_initializeunits *inc/compproc.inc:procedure fpc_InitializeUnits; compilerproc;inc/system.inc:procedure fpc_InitializeUnits;[public,alias:'FPC_INITIALIZEUNITS']; compilerproc;inc/system.inc:procedure internal_initializeunits; external name 'FPC_INITIALIZEUNITS';java/jsystem.inc:procedure fpc_InitializeUnits;[public,alias:'FPC_INITIALIZEUNITS']; compilerproc;java/jsystem.inc:procedure internal_initializeunits; external name 'FPC_INITIALIZEUNITS';java/jcompproc.inc:procedure fpc_InitializeUnits; compilerproc;$ grep -ir system.inc *aix/system.pp:{$I system.inc}amiga/system.pp:{$I system.inc}aros/system.pp:{$I system.inc}atari/system.pp:    {$i system.inc}beos/system.pp:{$I system.inc}bsd/system.pp:{$I system.inc}embedded/system.pp:{$I system.inc}emx/system.pas:{$I system.inc}fpmake.pp:          AddInclude('system.inc',AllUnixOSes);freertos/system.pp:{$I system.inc}gba/system.pp:{$i system.inc}go32v2/system.pp:{$I system.inc}haiku/system.pp:{$I system.inc}inc/readme:system.inc      OS and Processor independent implementation part of system unit.java/system.pp:{$i jsystem.inc}linux/system.pp:{$I system.inc}macos/system.pp:{$I system.inc}morphos/system.pp:{$I system.inc}msdos/system.pp:{$I system.inc}msxdos/system.pp:{$I system.inc}nativent/system.pp:{$I system.inc}nds/system.pp:{$i system.inc}netware/system.pp:{$I system.inc}netwlibc/system.pp:{$I system.inc}os2/system.pas:{$I system.inc}palmos/system.pp:{$i system.inc}qnx/system.pp:{$I system.inc}sinclairql/system.pp:  {$i system.inc}solaris/system.pp:{$I system.inc}symbian/system.pp:{$I system.inc}wasi/system.pp:{$I system.inc}watcom/system.pp:{$include system.inc}wii/system.pp:{$i system.inc}win16/system.pp:{$I system.inc}win32/system.pp:{$I system.inc}win64/system.pp:{$I system.inc}wince/system.pp:{$I system.inc}zxspectrum/system.pp:{$I system.inc} do notice that it's exported ALL CAPS as FPC_INITIALIZEUNITS, bet your linker is case sensitive, right? ---------------------------------------------------------------------- PascalDragon · 2021-05-20 07:27 Quote from: Leledumbo on May 19, 2021, 11:31:31 pmdo notice that it's exported ALL CAPS as FPC_INITIALIZEUNITS, bet your linker is case sensitive, right? Linkers are supposed to be. The compilerproc directives leads to the compiler generating a lowercase mangled name (here fpc_initializeunits) which can't be accessed using an external directive, which is why an all uppercase alias (FPC_INITIALIZEUNITS) is added. ---------------------------------------------------------------------- tihory · 2021-05-21 00:54 Quotedo notice that it's exported ALL CAPS as FPC_INITIALIZEUNITS, bet your linker is case sensitive, right? Due to the "dumpbin" output, the "FPC_INITIALIZEUNITS" and "fpc_initializeunits" point to the same address in object memory. Maybe this problem occurs because FPC uses a custom linking script and the "FPC_INITIALIZEUNITS" searches for specific addresses in memory depends on the linking script. ---------------------------------------------------------------------- PascalDragon · 2021-05-21 14:34 Quote from: tihory on May 21, 2021, 02:54:23 amQuotedo notice that it's exported ALL CAPS as FPC_INITIALIZEUNITS, bet your linker is case sensitive, right? Due to the "dumpbin" output, the "FPC_INITIALIZEUNITS" and "fpc_initializeunits" point to the same address in object memory. Maybe this problem occurs because FPC uses a custom linking script and the "FPC_INITIALIZEUNITS" searches for specific addresses in memory depends on the linking script. As written above: one is merely an alias of the other. They're indeed expected to be the same. ---------------------------------------------------------------------- tihory · 2021-06-07 09:29 Hi, I implemented some other features but postponed development for now. Features: Link multiple object files togetherLink against DLL filesSupport Pascal Mangling for external DLL functionsSupport function injection