www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17591] New: SIGSEGV in pthread_mutex_destroy after dlopen'ing


          Issue ID: 17591
           Summary: SIGSEGV in pthread_mutex_destroy after dlopen'ing a
                    shared library with -defaultlib=libphobos2.so
           Product: D
           Version: D2
          Hardware: x86
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: timothee.cour2 gmail.com

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

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7bc36b1 in pthread_mutex_destroy () from
#0  0x00007ffff7bc36b1 in pthread_mutex_destroy () from
#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
#8  0x000000000043ab39 in _start ()



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);
  int ret=dlclose(handle);
  import std.stdio;
  // 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)

Jul 03 2017