When linking shared object, unneccessary dependepcy to the linker-loader added
Original Reporter info from Mantis: lzsiga
-
Reporter name: Lőrinczy Zsigmond
Original Reporter info from Mantis: lzsiga
- Reporter name: Lőrinczy Zsigmond
Description:
When linking shared object, the compiler adds a dependency to the linker-loader into link.res
file, e.g.:
INPUT(
/lib64/ld-linux-x86-64.so.2
)
While the linker-loader is does interpret the shared object, it shouldn't be added as dependency: it doesn't export any useful symbols; on the contrary, it exports a calloc
implementation which under some conditions returns 'uncleared' memory, causing random errors.
Details can be read here:
https://stackoverflow.com/questions/59956996/problem-loading-a-library-with-ffi-in-php-7-4
https://sourceware.org/bugzilla/show_bug.cgi?id=25486
Note: This behaviour has been added into fpc-3.0.0, file compiler/systems/t_linux.pas
:
{ Write sharedlibraries like -l<lib>, also add the needed dynamic linker
here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
if (isdll) then
begin
Add('INPUT(');
Add(info.DynamicLinker);
Add(')');
end;
Output of readelf -d libexample.so
:
0x0000000000000001 (NEEDED) Shared library: [ld-linux-x86-64.so.2]
0x0000000000000001 (NEEDED) Shared library: [libglib-2.0.so.0]
0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
0x0000000000000001 (NEEDED) Shared library: [libxml2.so.2]
0x0000000000000001 (NEEDED) Shared library: [libdemodule.so]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000e (SONAME) Library soname: [libexample.so]
After the fix, the first dependency is gone:
0x0000000000000001 (NEEDED) Shared library: [libglib-2.0.so.0]
0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
0x0000000000000001 (NEEDED) Shared library: [libxml2.so.2]
0x0000000000000001 (NEEDED) Shared library: [libdemodule.so]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000e (SONAME) Library soname: [libexample.so]
Steps to reproduce:
Build a library with compiler 3.0.0, 3.0.2 or 3.0.4
Mantis conversion info:
- Mantis ID: 36706
- Version: 3.0.4
- Fixed in version: 3.3.1
- Fixed in revision: 44256 (#9c088bda)
- Monitored by: » Cyrax (Cyrax)