Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-12

Problems with Dynlibs.UnloadLibrary on Linux

10 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andrew Brunner

I've been experiencing problems with SOs under Linux and am trying to develop a "Plugin" system for my Server I'm porting to Lazarus. I'm confident can get these Plug-ins to Load and Operate just fine at least in (Ubuntu).

I can't however, Unload them. I want to be able to use the DynLibs.UnloadLibrary to unload a library. I can't because I keep getting a Segmentation Fault and the Application Crashes just by calling the Unload Library.

This problem makes using SOs/DLLs pointless because if one plugin is unloaded and the main service application closes due to a crash, all plugins running under that process will go down with it.

Here's my extensive thread so far. I'm hoping to find a good solution shortly as this is slowing me down.

http://www.lazarus.freepascal.org/index.php?name=PNphpBB2&file=viewtopic&t=6033&start=0&postdays=0&postorder=asc&highlight=

Are there a few tricks involved in getting FPC to compile these SOs properly? The minute I include Classes in my project's uses I can't Unload the library. If I just have straight forewared simple data types with no other uses I can get these to unload. Do you have any ideas?

I'm using all the latest and greatest FPC and Lazarus sources from subversion as of 2008.12.15.

Thanks for you input, if any, Andy.

Reply by email

Jonas Maebe
to Andrew Brunner
Andrew Brunner wrote 9 lines
I've been experiencing problems with SOs under Linux and am trying to develop a "Plugin" system for my Server I'm porting to Lazarus. I'm confident can get these Plug-ins to Load and Operate just fine at least in (Ubuntu). I can't however, Unload them. I want to be able to use the DynLibs.UnloadLibrary to unload a library. I can't because I keep getting a Segmentation Fault and the Application Crashes just by calling the Unload Library.

In what code does it crash? Inside unloadlibrary, or (shortly) afterwards? What is the backtrace at the point of the crash?

Are there a few tricks involved in getting FPC to compile these SOs properly? The minute I include Classes in my project's uses I can't Unload the library.

Even if you don't call any routines from that unit?

Jonas

Reply by email

Andrew Brunner
to Jonas Maebe
Jonas Maebe wrote
In what code does it crash? Inside unloadlibrary, or (shortly) afterwards? What is the backtrace at the point of the crash?

It blows out right during the DynLibs.UnloadLibrary(FLibHandle)

There is only a read access violation that is raised. Presumably by the MM of the SO.

Show quoted text 6 lines
> Are there a few tricks involved in getting FPC to compile these SOs > properly? The minute I include Classes in my project's uses I can't > Unload the library. Even if you don't call any routines from that unit?

Yes, If I compile with no uses clause the Lib loads and unloads as I want. As many times as I want with no issues. But if I re-build the SAME Library project with the uses Classes; The Main Application crashes on the UnloadLibrary call. I repeat, all I have to do to reproduce this bug is to use Classes; unit inside a Library under Ubuntu.

I have smart linking options enabled or else the Compiler can't link the project during build.

Reply by email

Jonas Maebe
to Andrew Brunner: It blows out right during the DynLibs.UnloadLibrary(FLibHandle) There is only a read…
Andrew Brunner wrote 11 lines
On Tue, Dec 16, 2008 at 3:29 PM, Jonas Maebe < > wrote: > In what code does it crash? Inside unloadlibrary, or (shortly) > afterwards? > What is the backtrace at the point of the crash? It blows out right during the DynLibs.UnloadLibrary(FLibHandle) There is only a read access violation that is raised. Presumably by the MM of the SO.

Please create a self-contained test case that demonstrates the problem and submit a bug report.

I have smart linking options enabled or else the Compiler can't link the project during build.

What is the error?

Jonas

Reply by email

Andrew Brunner
to Felipe Monteiro de Carvalho: Read this to create a backtrace: http://wiki.lazarus.freepascal.org/Creating_a_Backtrace_w…

Thanks for that tip! So running under GDB I get the following info...

This GDB was configured as "x86_64-linux-gnu"...
(gdb) run

Starting program: /mnt/Raid/Developer/Source/Lazarus/Test/TestApplication [Thread debugging using libthread_db enabled]
[New Thread 0x7f9e79102770 (LWP 7388)]
[WARNING] Out of OEM specific VK codes, changing to unassigned [WARNING] Out of unassigned VK codes, assigning $FF

Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7f9e79102770 (LWP 7388)]
0x00007f9e71a38d68 in fpc_finalize ()
from /home/atbrunner/Source/Lazarus/Libraries/MatrixMemory/MatrixMemoryManager.so (gdb)

#1 0x00007f9e719f6170 in ?? ()
#2 0x00007f9e71c40060 in _$CLASSES$_Ld233 ()
from /home/atbrunner/Source/Lazarus/Libraries/MatrixMemory/MatrixMemoryManager.so #3 0x00007fff8092e038 in ?? ()
#4 0x00007f9e719f6170 in ?? ()
#5 0x00007f9e71c40060 in _$CLASSES$_Ld233 ()
from /home/atbrunner/Source/Lazarus/Libraries/MatrixMemory/MatrixMemoryManager.so #6 0x00007fff8092e050 in ?? ()
#7 0x00007f9e719f6170 in ?? ()
#8 0x00007f9e71c40060 in _$CLASSES$_Ld233 ()
from /home/atbrunner/Source/Lazarus/Libraries/MatrixMemory/MatrixMemoryManager.so #9 0x00007fff8092e068 in ?? ()
#10 0x00007f9e719f6170 in ?? ()
#11 0x00007f9e71c40060 in _$CLASSES$_Ld233 ()
from /home/atbrunner/Source/Lazarus/Libraries/MatrixMemory/MatrixMemoryManager.so #12 0x00007fff8092e080 in ?? ()
#13 0x00007f9e719f6170 in ?? ()
#14 0x00007f9e71c40060 in _$CLASSES$_Ld233 ()
from /home/atbrunner/Source/Lazarus/Libraries/MatrixMemory/MatrixMemoryManager.so #15 0x00007fff8092e098 in ?? ()
#16 0x00007f9e719f6170 in ?? ()
#17 0x00007f9e71c40060 in _$CLASSES$_Ld233 ()
from /home/atbrunner/Source/Lazarus/Libraries/MatrixMemory/MatrixMemoryManager.so #18 0x00007fff8092e0b0 in ?? ()
#19 0x00007f9e719f6170 in ?? ()
#20 0x00007f9e71c40060 in _$CLASSES$_Ld233 ()
from /home/atbrunner/Source/Lazarus/Libraries/MatrixMemory/MatrixMemoryManager.so #21 0x00007fff8092e0c8 in ?? ()
#22 0x00007f9e719f6170 in ?? ()
#23 0x00007f9e71c40060 in _$CLASSES$_Ld233 ()
from /home/atbrunner/Source/Lazarus/Libraries/MatrixMemory/MatrixMemoryManager.so #24 0x00007fff8092e0e0 in ?? ()
#25 0x00007f9e719f6170 in ?? ()
#26 0x00007f9e71c40060 in _$CLASSES$_Ld233 ()

<SNIP>

It appears that something is wrong with the classes unit or something. Keep in mind, the compiled library is nothing more than 2 functions declared as exported booleans that don't have any parameters.

Felipe Monteiro de Carvalho wrote 10 lines
Read this to create a backtrace: http://wiki.lazarus.freepascal.org/Creating_a_Backtrace_with_GDB -- Felipe Monteiro de Carvalho _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Michael Van Canneyt
to Andrew Brunner
Andrew Brunner wrote 15 lines
Thanks for that tip! So running under GDB I get the following info... This GDB was configured as "x86_64-linux-gnu"... (gdb) run Starting program: /mnt/Raid/Developer/Source/Lazarus/Test/TestApplication [Thread debugging using libthread_db enabled] [New Thread 0x7f9e79102770 (LWP 7388)] [WARNING] Out of OEM specific VK codes, changing to unassigned [WARNING] Out of unassigned VK codes, assigning $FF Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7f9e79102770 (LWP 7388)] 0x00007f9e71a38d68 in fpc_finalize () from /home/atbrunner/Source/Lazarus/Libraries/MatrixMemory/MatrixMemoryManager.so

Are you using threads ?

Michael.

Reply by email

Andrew Brunner
to Michael Van Canneyt
Michael Van Canneyt wrote
Are you using threads ? Michael.

Hi Michael,

Not in the library project. Although I do plan on having threads in the Main Application. Many pooled threads will be running in the main application.

Just the "application" thread will be running in the "Matrix Modules" Libraries.

Reply by email

Jonas Maebe
to Werner Bochtler
Werner Bochtler wrote 9 lines
Andrew Brunner schrieb: > Thanks for that tip! So running under GDB I get the following > info... > > This GDB was configured as "x86_64-linux-gnu"... (gdb) run shared library problem and linux 64 bit -> maybe this problem is related to FPC bug reports 11931 / 12265 (jump table problem).

In that case, using the fixes branch or the previous release is probably a better idea.

Jonas

Reply by email