-- Edit --
This problem is result of two bugs in two different programs.
When linking a shared objects, fpc-3.0.0 (or newer) adds this to the dependencies (as the first dependency): /lib64/ld-linux-x86-64.so.2
ld-linux-x86-64.so.2 exports a calloc
variant, that doesn't (always) clears the memory it returns (details below)
The workaround OP suggested is linking in a separate pass (using -E
(or -Cn
) option of fpc
), but before running ./ppas.sh
fixing link.res
file. For that, I hacked this awk-script, but I do feel it a bit clumsy:
#!/usr/bin/awk -f
$0=="INPUT(" { state=1; next; }
$0=="/lib64/ld-linux-x86-64.so.2" { state=2; next; }
$0==")" && state>0 { state=0;next; }
state==1 { print "INPUT("; state=0; }
{ print $0; }
-- Original answer --
Sounds like a linking problem: you might have added /lib64/ld-linux-x86-64.so.2
into the dependent shared libraries, which is neither required or useful.
Actually, it resulted a calloc
version that returns non-zeroed memory. The details are described here: https://www.linuxquestions.org/questions/programming-9/debugging-dlopen-4175668676/ and here: Why does calling calloc in gdb not appear to zero out the memory?
Suggested solution: change the linkage according to the example:
- gcc -shared -o demodule.so demodule.o /lib64/ld-linux-x86-64.so.2 -lglib-2.0
+ gcc -shared -o demodule.so demodule.o -lglib-2.0
The difference can be checked with readelf -d
. Wrong:
Dynamic section at offset 0x828 contains 26 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [ld-linux-x86-64.so.2]
0x0000000000000001 (NEEDED) Shared library: [libglib-2.0.so.0]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
Right output:
Dynamic section at offset 0x7f8 contains 25 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libglib-2.0.so.0]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
Also, with command ldd demodule.so
the line containing /lib64/ld-linux-x86-64.so.2
should be the last one.
Edit: discussion on sourceware.org regarding this problem:
https://sourceware.org/bugzilla/show_bug.cgi?id=25486
Edit: on Freepascal side: https://bugs.freepascal.org/view.php?id=36706