Recent

Author Topic: RTL/Packages as dynamically linked library  (Read 919 times)

Alex_Lutovinin

  • Newbie
  • Posts: 2
RTL/Packages as dynamically linked library
« on: February 07, 2023, 05:15:04 pm »
Hi.

Does anyone have experience using RTL/Packages as dynamically linked library?
In my case, several FPC applications should be installed on the host and it seems logical to me that
they will share the same RTL/Packages libraries.
I use crosscompiller 3.0.4 version for ARM_LINUX  platform.
I tried to combine all RTL/Packages *.ppu modules using "ppumove" into several *.so libraries.
After solving some problems, I managed to build a small test application with the key "XD".
The result: the tiny size of the executable module, the application works.
But there is a problem: after the application is shut down, "EAccessViolation" occurs.

A little debugging showed that most likely the error occurs when releasing resource strings:

Quote
Program received signal SIGSEGV, Segmentation fault.
0xb6f7955c in fpc_ansistr_decr_ref () from /usr/lib/libfpcrtl.so
(gdb)
(gdb) bt
#0  0xb6f7955c in fpc_ansistr_decr_ref () from /usr/lib/libfpcrtl.so
#1  0xb6f8695c in fpc_ansistr_assign () from /usr/lib/libfpcrtl.so
#2  0xb6f6fc8c in OBJPAS_$$_FINALIZERESOURCETABLES () from /usr/lib/libfpcrtl.so
#3  0xb6f6fcd4 in OBJPAS_$$_finalize$ () from /usr/lib/libfpcrtl.so
#4  0xb6f920fc in SYSTEM_$$_FINALIZEUNITS () from /usr/lib/libfpcrtl.so
#5  0xb6f9249c in SYSTEM_$$_INTERNALEXIT () from /usr/lib/libfpcrtl.so
#6  0xb6f92514 in SYSTEM_$$_DO_EXIT () from /usr/lib/libfpcrtl.so
#7  0x0000c5c0 in _haltproc_eabi ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Are there any ideas about my plan? How is this even possible?


marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: RTL/Packages as dynamically linked library
« Reply #1 on: February 07, 2023, 05:39:13 pm »
No, because automated types (like string) don't work over DLL borders without special care.

See e.g. https://wiki.freepascal.org/packages




PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: RTL/Packages as dynamically linked library
« Reply #2 on: February 07, 2023, 09:21:26 pm »
No, because automated types (like string) don't work over DLL borders without special care.

Due to the way ELF binaries work, on systems that use ELF binaries it can work, which is why ppumove was introduced after all.

I can't say whether it's still really usable however as it relies on a few assumptions...

In general I'd simply wait until dynamic packages support has been finalized (for arm-linux it's essentially only missing an adjustment of the startup code for the compile/link time case, like most targets).

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: RTL/Packages as dynamically linked library
« Reply #3 on: February 07, 2023, 11:12:03 pm »
No, because automated types (like string) don't work over DLL borders without special care.

Due to the way ELF binaries work, on systems that use ELF binaries it can work, which is why ppumove was introduced after all.

If you mean single _LINKER_ namespace, afaik not all ELF binaries do (e.g. Solaris, AIX). But anyway, what I was referring that as soon you have two RTLs you have to sub-allocators if you don't take special case.

« Last Edit: February 08, 2023, 05:28:42 pm by marcov »

Alex_Lutovinin

  • Newbie
  • Posts: 2
Re: RTL/Packages as dynamically linked library
« Reply #4 on: February 08, 2023, 05:23:22 pm »
No, because automated types (like string) don't work over DLL borders without special care.

Due to the way ELF binaries work, on systems that use ELF binaries it can work, which is why ppumove was introduced after all.

If you mean single namespace, afaik not all ELF binaries do (e.g. Solaris). But anyway, what I was referring that as soon you have two RTLs you have to sub-allocators if you don't take special case.

Thank you so much for your answer!

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: RTL/Packages as dynamically linked library
« Reply #5 on: February 08, 2023, 09:22:12 pm »
No, because automated types (like string) don't work over DLL borders without special care.

Due to the way ELF binaries work, on systems that use ELF binaries it can work, which is why ppumove was introduced after all.

If you mean single _LINKER_ namespace, afaik not all ELF binaries do (e.g. Solaris, AIX). But anyway, what I was referring that as soon you have two RTLs you have to sub-allocators if you don't take special case.

Yes, not all ELF targets might support this. The main target this has been tested on was Linux anyway.

And in the case of ppumove there is only one RTL as the RTL units are moved into a library. Even if you'd link against another library written in FPC with a linked in RTL (aka the default) this won't be a problem. What would be a problem however would be a binary with RTL in the libraries and an additional library with a different version of the RTL in libraries as well.

 

TinyPortal © 2005-2018