Open
Description
Martin Nowak reported this on 2015-07-24T23:34:51Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=14824
CC List
- ponce
Description
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 druntime.
[¹]: https://github.com/D-Programming-Language/druntime/blob/645edac3483c8908de29c55c9312dc5dcf2f6bdd/test/shared/src/host.c
[²]: https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/dl-lookup.c;hb=6b183b833968010a95ba41ed307dd8bea7b2e641#l917
[³]: https://github.com/freebsd/freebsd/blob/527ac1e9fb2b2f29df0bcfb2e91053cea93956bb/libexec/rtld-elf/rtld.c#L3846