[fpc-devel] Bugs/strange behaviour on linux with libraries
Koko
newsbox1026 at web.de
Fri Apr 6 19:20:34 CEST 2007
Hello!
Has anyone done more work using libraries FPC/Linux? I am porting a
software to fpc and my program loops at an segmentation fault on exit.
Not when running, but on exit only. When I abort with ctrl-c there is no
error. This happens when I declare the use of a library (.so) even
without using any of its function(s). A {$LINKLIB ...} or the
declaration procedeure ... external 'name' is enough to trigger the
error. I am using fpc 2.0.4 on Gentoo.
Here an example:
-------------------
library testlib;
end.
-------------------
and a corresponding program:
-------------------
program testprog;
{ $LINKLIB c}
{$LINKLIB testlib}
begin
end.
-------------------
Now when running the testprog (like LD_LIBRARY_PATH=. ./testprog as the
testlib is in the current directory in my case) this runs as expected
with no output. When I add the {$LINKLIB c} the program generates a
segmentation fault on exit. Running it in gdb outputs:
Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()
and this comes from the call <SYSTEM_DO_EXIT>. Why that?! Something gets
executed that shouldn't?!
I analyzed ldd output a bit. Without {$LINKLIB c} I have
linux-gate.so.1 => (0xb7fd9000)
libtestlib.so => ./libtestlib.so (0xb7fa1000)
With {$LINKLIB c} I have
linux-gate.so.1 => (0xb7f28000)
libtestlib.so => ./libtestlib.so (0xb7ef0000)
libc.so.6 => /lib/libc.so.6 (0xb7db1000)
/lib/ld-linux.so.2 (0xb7f29000)
which triggers the bug.
When I omit either {$LINKLIB c} or {$LINKLIB testlib} there is no
segmentation fault.
To find the source of my initial problem I looked at ldd output of my
program:
linux-gate.so.1 => (0xb7f72000)
libX11.so.6 => /usr/lib/libX11.so.6 (0xb7e4d000)
libXext.so.6 => /usr/lib/libXext.so.6 (0xb7e3b000)
libXv.so.1 => /usr/lib/libXv.so.1 (0xb7e36000)
libc.so.6 => /lib/libc.so.6 (0xb7d15000)
libXau.so.6 => /usr/lib/libXau.so.6 (0xb7d11000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0xb7d0c000)
libdl.so.2 => /lib/libdl.so.2 (0xb7d08000)
/lib/ld-linux.so.2 (0xb7f73000)
and tried to include all with $LINKLIB which triggered the error. After
removing them one by one I pinned down that it's {$LINKLIB c} - FPC lib
collides with that. Interestingly only when linked explicitly using
{$LINKLIB c}. When using only {$LINKLIB X11} in above test, ldd shows
that libc is also used:
linux-gate.so.1 => (0xb7f2f000)
libX11.so.6 => /usr/lib/libX11.so.6 (0xb7e0a000)
libtestlib.so => ./libtestlib.so (0xb7dd3000)
libc.so.6 => /lib/libc.so.6 (0xb7cb2000)
libXau.so.6 => /usr/lib/libXau.so.6 (0xb7caf000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0xb7ca9000)
libdl.so.2 => /lib/libdl.so.2 (0xb7ca5000)
/lib/ld-linux.so.2 (0xb7f30000)
but there is no segmentation fault. When I add {$LINKLIB c} here the
segmentation fault on exit is there again.
By the way, I checked my sources if there is any explicit reference to
libc but haven't found any. This segmentation fault seems to be
triggered not only by libc but that should be a good point to start
searching. In my case the error creates a loop with 100% CPU load, here
it is output only once.
Any ideas what can be done to fix that?
By the way, when trying to compile my software with -Cg I encountered
"Internal error 2005042501" of the compiler on a unit which seems to
have nothing special. If this is of interest I can try to make a simple
demo program for this error.
I tried the -Cg switch as compiling/linking the unit produced this warning:
/usr/bin/ld: warning: creating a DT_TEXTREL in object.
but -Cg changed nothing. This message appears also when compiling the
testlib above. Could this be a hint to the source of the problem? Any
idea why this warning is generated?
Have a nice weekend,
Konstantin
More information about the fpc-devel
mailing list