Bug 17591 – SIGSEGV in pthread_mutex_destroy after dlopen'ing a shared library with -defaultlib=libphobos2.so

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2017-07-03T21:24:39Z
Last change time
2024-12-13T18:53:03Z
Assigned to
No Owner
Creator
Timothee Cour
Moved to GitHub: dmd#19273 →

Comments

Comment #0 by timothee.cour2 — 2017-07-03T21:24:39Z
another take at https://issues.dlang.org/show_bug.cgi?id=17588: ``` dmd -of$lib_F -shared -fPIC mylib.d -defaultlib=libphobos2.so dmd -of$out_F main.d $out_F Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7bc36b1 in pthread_mutex_destroy () from /lib/x86_64-linux-gnu/libpthread.so.0 #0 0x00007ffff7bc36b1 in pthread_mutex_destroy () from /lib/x86_64-linux-gnu/libpthread.so.0 #1 0x00000000004555da in _d_critical_term () #2 0x00000000004447e8 in rt_term () #3 0x000000000043c82e in _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFNlZv () #4 0x000000000043c7a4 in _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ7tryExecMFNlMDFZvZv () #5 0x000000000043c714 in _d_run_main () #6 0x000000000043b82e in main () #7 0x00007ffff6ee8830 in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6 #8 0x000000000043ab39 in _start () ``` with: ``` mylib.d: {} 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 finishes } ``` NOTE: if I replace -defaultlib=libphobos2.so with -defaultlib=libphobos2.a it works, but I'd like to use -defaultlib=libphobos2.so (my use case is more complex and mylib.d itself links against other libs that use libphobos.so)
Comment #1 by timothee.cour2 — 2017-07-03T22:56:48Z
* NOTE 1: commenting out: ``` int ret=dlclose(handle); assert(!ret); ``` will avoid the error but this will leak resources * NOTE 2: adding: ``` enum RTLD_NODELETE=0x01000; auto flag=RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE; ``` will also avoid the error but my understanding is it'll also leak resources (and RTLD_NODELETE isn't defined in core.sys.posix.dlfcn for X86_64 so i had to add the above defined enum) Is that safe?
Comment #2 by robert.schadek — 2024-12-13T18:53:03Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19273 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB