Bug 17588 – SIGSEGV in pthread_mutex_destroy on a shared library executable (with -pie)
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2017-07-03T17:46:00Z
Last change time
2017-07-03T18:42:52Z
Assigned to
nobody
Creator
timothee.cour2
Comments
Comment #0 by timothee.cour2 — 2017-07-03T17:46:36Z
a main program running dlopen/dlclose on a shared library executable (with -pie) generates a SEGFAULT on program termination:
```
dmd --version
DMD64 D Compiler v2.074.1
FLAGS_link=-L~/dmd2_074_1/linux/lib64/,-rpath=~/dmd2_074_1/linux/lib64/,-lphobos2
dmd -offoo.o -c -fPIC foo.d
/usr/bin/g++ -o libfoo foo.o -pie -Wl,$FLAGS_link,--export-dynamic
foo.d:
void main(){}
main.d:
void main(){
string file=`libfoo`;
import core.sys.posix.dlfcn;
import std.string:toStringz;
auto flag=RTLD_LAZY | RTLD_LOCAL;
auto handle=dlopen(file.toStringz, flag);
assert(handle);
int ret=dlclose(handle);
assert(!ret);
import std.stdio;
writeln("ok");
// segfaults before process executes
}
dmd -run main.d
#SEGFAULT
```
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7bc36b1 in pthread_mutex_destroy () from /lib/x86_64-linux-gnu/libpthread.so.0
(gdb) bt
#0 0x00007ffff7bc36b1 in pthread_mutex_destroy () from /lib/x86_64-linux-gnu/libpthread.so.0
#1 0x0000000000619836 in _d_critical_term ()
#2 0x0000000000605db8 in rt_term ()
#3 0x00000000005c6d46 in _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFNlZv ()
#4 0x00000000005c6cbc in _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ7tryExecMFNlMDFZvZv ()
#5 0x00000000005c6c2c in _d_run_main ()
#6 0x00000000005555ae in main ()
#7 0x00007ffff6ee8830 in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
#8 0x0000000000554019 in _start ()
```
Comment #1 by timothee.cour2 — 2017-07-03T18:41:38Z
it works with:
-Bstatic,-lphobos2,-Bdynamic
instead of:
-lphobos2
Comment #2 by timothee.cour2 — 2017-07-03T18:42:52Z