[Issue 17588] New: SIGSEGV in pthread_mutex_destroy on a shared library executable (with -pie)

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jul 3 10:46:36 PDT 2017


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

          Issue ID: 17588
           Summary: SIGSEGV in pthread_mutex_destroy on a shared library
                    executable (with -pie)
           Product: D
           Version: D2
          Hardware: x86
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: timothee.cour2 at gmail.com

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 ()

```

--


More information about the Digitalmars-d-bugs mailing list