#1 2022-03-13 17:26:25

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Mormot2 server as library + a relocate error in linux

I am looking for an automatic update mechanism and totally independent of the operating system that the mormot2 server is running.
In windows, if running as a windows service, I do not want a second windows service to exist for stopping/updating/starting the mormot2 service.
In both linux and windows, you need a separate script/executable to restart the service and I am not in favor of

My idea is to compile the mormot2 server with everything it needs to a library:
1. A .dll for windows that can be loaded/unloaded by a simple windows service that checks if a updated version of the dll exists and does the dirty job: download it, verify integrity, stops the mormot2 server, unloads the dll, updates the dll, reload itself the dll, start again the mormot2 server
2. A .so library for linux that it is loaded by a linux executable that runs as a service with the excellent TSynDaemon and does the same thing as the windows service.

As I am not so experienced as you, what do you think of this idea? What are the possible problems that I could arrive to? Does it needs something special? Do you propose something else?

I already managed to compile a small mormot2 server as windows DLL with both Delphi and Lazarus/fpc, and it works from a windows service.
I have not managed to do the same thing in linux with Lazarus/fpc as I am receiving the following linker error when compiling the same library:

Verbose: Linking C:\pchr\projects\pchr\servers\fpc\libserverlib.so
Debug: C:\fpcupdeluxe\fpcupdeluxe\cross\bin\x86_64-linux\x86_64-linux-ld.exe: C:\DG\mORMot2\src\db\..\..\static\x86_64-linux\sqlite3.o: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
Debug: C:\fpcupdeluxe\fpcupdeluxe\cross\bin\x86_64-linux\x86_64-linux-ld.exe: C:\DG\mORMot2\src\core\..\..\static\x86_64-linux\libdeflatepas.a(adler32.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
Debug: C:\fpcupdeluxe\fpcupdeluxe\cross\bin\x86_64-linux\x86_64-linux-ld.exe: C:\DG\mORMot2\src\core\..\..\static\x86_64-linux\libdeflatepas.a(crc32.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
Debug: C:\fpcupdeluxe\fpcupdeluxe\cross\bin\x86_64-linux\x86_64-linux-ld.exe: C:\DG\mORMot2\src\core\..\..\static\x86_64-linux\libdeflatepas.a(deflate_compress.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
Debug: C:\fpcupdeluxe\fpcupdeluxe\cross\bin\x86_64-linux\x86_64-linux-ld.exe: C:\DG\mORMot2\src\core\..\..\static\x86_64-linux\libdeflatepas.a(deflate_decompress.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
C:\fpcupdeluxe\fpcupdeluxe\cross\bin\x86_64-linux\x86_64-linux-ld.exe: final link failed: Nonrepresentable section on output

I am beginner with fpc and I have not managed to find anything about that. I have put the -fPIC in custom options and I have tried to use the options in "Compilation and Linking" without success
An probably this has to do with the compiled units from static.
Can you help me?

Last edited by dcoun (2022-03-13 17:28:56)

Offline

#2 2022-03-14 07:34:24

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

Re: Mormot2 server as library + a relocate error in linux

Some statics are currently not meant to be part of a library.

Why use a library?
Just run an executable, not a library, from your main service.

Offline

#3 2022-03-14 07:37:45

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

Re: Mormot2 server as library + a relocate error in linux

mORMot links external object files that haven't been compiled with -fPIC, you can avoid the errors by using external libraries instead,
for the errors you provided you need to set the following compile time flags :

NOSQLITE3STATIC
NOLIBDEFLATESTATIC

You can do this on command line or if IDE , for example lazarus ide :
Project Options -> Compiler Options -> Custom Options

I've done this for a different reason then you and I don't recommend it unless you are a seasoned veteran of writing external libraries. Things like shared memory will be prohibited because the framework wasn't designed with relocatable code in mind. mORMot has a lot of initialization hooks that hook into exceptions, rtti and system units and while there are (some) compile time flags that control this behavior it really goes against the "grain" of the project and may result in unwanted behavior.

That much said, if you don't care about shared memory, mORMot will work just fine in a library after all, without shared memory there's little difference between a program and a library.
For your use case I fail to see why you would want to use a library instead of a normal program, everything you mentioned can be achieved with writing a normal program and in your case there's only disadvantages to using a library instead.

Last edited by pvn0 (2022-03-14 07:48:42)

Offline

#4 2022-03-14 08:09:49

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: Mormot2 server as library + a relocate error in linux

Thank you very much for the reply.
The problem is much more complicated than I expected.
To run mormot2 server as a separate executable is OK for me and for my case.
For linux, I think it is more easy than windows.
To be honest, I am not sure how windows will deal with a service that executes programs and the program itself, but I will try
Thank you again

Offline

#5 2022-03-14 09:57:03

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

Re: Mormot2 server as library + a relocate error in linux

IIRC on both Windows and Linux, executing another program will let it run with the same user rights.

Offline

Board footer

Powered by FluxBB