www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14824] New: A stale function might get called when unloading


          Issue ID: 14824
           Summary: A stale function might get called when unloading
                    shared libraries on FBSD
           Product: D
           Version: D2
          Hardware: All
                OS: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: code dawg.eu

FreeBSD's runtime linker has a bug where it could resolve a PLT
function entry to a weak definition in a dynamically loaded shared
library without pinning that library. Once the lib get's unloaded
further calls to that function will crash.

This happens with the host test [¹] which loads plugin1.so and plugin2.so (both
depending on libdruntime.so).
On the first call to dur!"usecs" the PLT entry is resolved to
plugin1.so b/c it preceeds libdruntime.so in the symbol search
order. When plugin1.so gets unloaded, the PLT of druntime would still point to
the definition in plugin1, even though plugin2 might still call those functions
in druntime.

GLIBC get's this right and pins plugin1.so, see [²].

This was found on FBSD-8.4, but a look at the relevant source code [³]
indicates, that it's still not fixed.

A workaround is to explicitly load the common dependent library (libdruntime.so
here) before loading the plugins, that way the symbol search order will prefer


Jul 24 2015