View Issue Details

IDProjectCategoryView StatusLast Update
0036706FPCCompilerpublic2020-03-03 08:30
ReporterLőrinczy ZsigmondAssigned ToSven Barth 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.0.4Product Build 
Target VersionFixed in Version3.3.1 
Summary0036706: When linking shared object, unneccessary dependepcy to the linker-loader added
DescriptionWhen 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 ReproduceBuild a library with compiler 3.0.0, 3.0.2 or 3.0.4
TagsNo tags attached.
Fixed in Revision44256
FPCOldBugId
FPCTarget-
Attached Files

Activities

Sven Barth

2020-03-02 23:06

manager   ~0121326

Free Pascal now no longer links against the dynamic loader as long as the library requires the C library. Another dev said there was a reason why we're linking against the loader otherwise, but I've not yet been able to reproduce this, so we'll use that compromise for now.

Issue History

Date Modified Username Field Change
2020-02-17 16:25 Lőrinczy Zsigmond New Issue
2020-03-02 22:33 Sven Barth Assigned To => Sven Barth
2020-03-02 22:33 Sven Barth Status new => assigned
2020-03-02 23:06 Sven Barth Status assigned => resolved
2020-03-02 23:06 Sven Barth Resolution open => fixed
2020-03-02 23:06 Sven Barth Fixed in Version => 3.3.1
2020-03-02 23:06 Sven Barth FPCTarget => -
2020-03-02 23:06 Sven Barth Note Added: 0121326
2020-03-02 23:06 Sven Barth Fixed in Revision => 44256