#1 2021-09-14 11:38:50

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 210

mORMot2 fpc linker error

I get a linker error when trying to build/compile this simple program

undefined reference to `.Lj14'
program test;

{$I mormot.defines.inc}

uses {$I mormot.uses.inc}
  mormot.core.json;

var
  P: Pointer;
  FDictionary: TSynDictionary;
begin
  P := FDictionary.Keys.ItemPtr(0);
end.    

Builds OK if ItemPtr Index parameter is > 0.

---------------------------------------------
Debian buster
FPC 3.2.0-r45643
PUREMORMOT2
No optimizations

I also tried on FPC stable 3.2.2.

Offline

#2 2021-09-14 13:15:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,220
Website

Re: mORMot2 fpc linker error

Isn't it a FPC bug?

What if you use a sub-procedure for the code?
The main begin..end. block of any program is likely to be broken, in terms of local variables and registers allocation.

Offline

#3 2021-09-14 17:40:54

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 210

Re: mORMot2 fpc linker error

FPC bug for sure, I just wanted to know if anyone else can reproduce it or if it's just my system that is borked.

the main begin.end block isn't the culprit, this is just a MWE example, I did test it in a sub-procedure originally. I bet the bug has something to do with namespaces , the monolithic unit structure of mORMot 1 didn't trigger this bug on the same compiler version.

Last edited by pvn0 (2021-09-14 17:42:03)

Offline

#4 2021-09-14 20:37:36

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: mORMot2 fpc linker error

Error: Compilation raised exception internally

Lazarus 2.0.10 + FPC 3.2.0 Win 32.
PUREMORMOT2

Offline

#5 2021-09-15 06:41:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,220
Website

Re: mORMot2 fpc linker error

FDictionary is not initialized in your code so I guess FPC has troubles inlining this code!

Offline

#6 2021-09-15 08:00:58

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 210

Re: mORMot2 fpc linker error

Initialization is not the problem, in my project I have everything set up correctly with constructor&destructor in a try..finally block and still produces this bug, I also tested it on this MWE example.
It's not that big of a deal tho because nobody should be calling ItemPtr function in production anyway since you can access the original Array directly, however it would be nice if TSynDictionary would have a public function that gives you a pointer to the start of the Keys & Values array respectively.

Offline

#7 2021-09-15 08:41:14

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 210

Re: mORMot2 fpc linker error

I've just compiled this example (and my project) successfully with FPC trunk 3.3.1-9066-gffc3e1780d [2021/09/14], so whatever bug seems to have been fixed somewhere after 3.2.2 stable.
FPC 3.2.0-r45643 is over a year old, when fpc team tags next stable release 3.3.x, consider testing mORMot 2 for that revision.

Another thing, since fpc source moved to gitlab, fpcupdeluxe wont accept the svn revision number r45643 because git hashes are now the "revision number", this makes documentation for installing on Linux obsolete.

Last edited by pvn0 (2021-09-15 08:42:00)

Offline

#8 2021-09-15 08:50:45

AOG
Member
Registered: 2014-02-24
Posts: 490

Re: mORMot2 fpc linker error

FPC trunk (main) on win32 : no problem.

Offline

#9 2021-09-15 09:59:56

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,540
Website

Re: mORMot2 fpc linker error

pvn0 wrote:

Another thing, since fpc source moved to gitlab, fpcupdeluxe wont accept the svn revision number r45643 because git hashes are now the "revision number", this makes documentation for installing on Linux obsolete.

IMHO under Linux the easiest way is to install from packages. May be we shod use this in documentation :

Debian (tested on Ubuntu 20.04):

mkdir -p ~/dist
cd ~/dist
wget -O fpc-laz_3.2.0-1_amd64.deb https://sourceforge.net/projects/lazarus/files/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.0.10/fpc-laz_3.2.0-1_amd64.deb/download
wget -O fpc-src_3.2.0-1_amd64.deb https://sourceforge.net/projects/lazarus/files/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.0.10/fpc-src_3.2.0-1_amd64.deb/download
sudo apt install ./fpc-laz_3.2.0-1_amd64.deb ./fpc-src_3.2.0-1_amd64.deb -y

RPM (tested on OracleLinux8)

wget -O fpc-3.2.0-1.x86_64.rpm https://sourceforge.net/projects/lazarus/files/Lazarus%20Linux%20x86_64%20RPM/Lazarus%202.0.10/fpc-3.2.0-1.x86_64.rpm/download
wget -O fpc-src-3.2.0-1.x86_64.rpm https://sourceforge.net/projects/lazarus/files/Lazarus%20Linux%20x86_64%20RPM/Lazarus%202.0.10/fpc-src-3.2.0-1.x86_64.rpm/download
sudo dnf install ./fpc-3.2.0-1.x86_64.rpm ./fpc-src-3.2.0-1.x86_64.rpm -y

Offline

#10 2021-09-15 10:32:44

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 210

Re: mORMot2 fpc linker error

Nice, I didn't even know someone was creating deb packages (I heard it's PITA), I think both ways should be documented. Also for the packages, a hash should be posted in the documentation, for security.

Offline

#11 2021-09-15 11:31:22

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,220
Website

Re: mORMot2 fpc linker error

Currently, we use FPC 3.2.0 because 3.2.2 has troubles with variant late bindings, and trunk/3.3 is too much unstable.
No need to use a SVN revision in FpcUpDeluxe: just select FPC 3.2.0.

About TSynDictionary access to the keys and values, you can access directly the PPointer storage via Keys.Value and Values.Value.
Don't forget to Lock/UnLock the instance if you may such direct access.

And for a more modern access, consider using mormot.core.collections which can leverage TSynDictionary use via IKeyValue<> storage.

Offline

#12 2021-09-15 11:47:29

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 210

Re: mORMot2 fpc linker error

thanks ab, I will stick to trunk for now and revert to 3.2.2 if necessary because I don't use variant late bindings.

btw, this forum desperately needs a thumbs up functionality for posts to reduce the amount of "thank you" replies big_smile

Offline

Board footer

Powered by FluxBB