www.digitalmars.com         C & C++   DMDScript  

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

https://issues.dlang.org/show_bug.cgi?id=17591

          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
$out_F

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7bc36b1 in pthread_mutex_destroy () from
/lib/x86_64-linux-gnu/libpthread.so.0

/lib/x86_64-linux-gnu/libpthread.so.0



()

_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ7tryExecMFNlMDFZvZv ()



/lib/x86_64-linux-gnu/libc.so.6


```

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)

--
Jul 03 2017