ramvasanth / thread-sanitizer

Automatically exported from code.google.com/p/thread-sanitizer
0 stars 0 forks source link

SEGV in pthread_create with TSan #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

void *threadfn(void*) {
  return NULL;
}
void *allocate_stack(pthread_attr_t &a, size_t n = 655360) {
  void *stack = malloc(n);
  pthread_attr_init(&a);
  pthread_attr_setstack(&a, stack, n);
  return stack;
}

int main(void) {
  pthread_attr_t a;
  allocate_stack(a);
  pthread_t t;
  pthread_create(&t, &a, threadfn, NULL);
}

# clang++ 1.cc -o 1 -lpthread -fPIE -pie -fsanitize=thread -O0 -g
# ./1
Segmentation fault (core dumped)

Debugging is diffucult:
# gdb ./1
(gdb) set disable-randomization off
(gdb) run

[...]

Program received signal SIGSEGV, Segmentation fault.
memset () at ../sysdeps/x86_64/multiarch/../memset.S:1285
1285    ../sysdeps/x86_64/multiarch/../memset.S: No such file or directory.
(gdb) bt
#0  memset () at ../sysdeps/x86_64/multiarch/../memset.S:1285
#1  0x00007f4e2f1e5ef7 in __GI__dl_allocate_tls_init (result=0x7f4e2e1e1700) at 
dl-tls.c:437
#2  0x00007f4e2efbf6f3 in allocate_stack (
../../gdb-7.5.x/gdb/dwarf2read.c:10202: internal-error: 
dwarf2_record_block_ranges: Assertion `dwarf2_per_objfile->ranges.readin' 
failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) 

Note that allocate_stack in the stack trace above refers to a function in glibc 
(called from pthread_create).

Increasing allocated stack size even further "fixes" the problem.

Original issue reported on code.google.com by euge...@google.com on 13 Feb 2013 at 9:06

GoogleCodeExporter commented 9 years ago
Is this still an issue? I can't reproduce in trunk.

I'm particularly after the GDB assertion, I constantly hit it and am looking 
for a minimized testcase to report to GDB devs.

Original comment by fakju66...@o2.pl on 2 Apr 2013 at 8:07

GoogleCodeExporter commented 9 years ago
In fact, I can't reproduce even with clang from Feb 14th:

llvm: git rev 382a5530ec0682d8dd17f7d9212f52ace38460ed
clang: git rev 8c42a67645145a7673d0313da7dcbab2b66f5611
compiler-rt: git rev 8da17ea3bc3ba0a28844642921247a3b9a1a3bcd

$ /home/name/src/llvm-feb14/obj/Release+Asserts/bin/clang++ 1.cc -o 1 -lpthread 
-fPIE -pie -fsanitize=thread -O0 -g
$ ./1
==================
WARNING: ThreadSanitizer: thread leak (pid=2416)
  Thread T1 (tid=2417, finished) created by main thread at:
    #0 pthread_create ??:0 (exe+0x00000001884a)
    #1 main /home/name/src/gdbcrash/1.cc:20 (exe+0x000000013955)

SUMMARY: ThreadSanitizer: thread leak ??:0 pthread_create
==================
ThreadSanitizer: reported 1 warnings

OS: Ubuntu 12.04.2 64bit

Maybe it's arch specific?

Original comment by fakju66...@o2.pl on 3 Apr 2013 at 12:32

GoogleCodeExporter commented 9 years ago
I can't reproduce the TSan segmentation fault, but GDB assertion is still here.

(gdb) set disable-randomization off
(gdb) run
...
[Inferior 1 (process 11240) exited with code 0102]
(gdb) br __GI__dl_allocate_tls_init
Breakpoint 1 at 0x7ffad35dfe10: file dl-tls.c, line 377.
(gdb) run
Starting program: /code/llvm/1 

Breakpoint 1, __GI__dl_allocate_tls_init (result=0x7f3631e18fc0) at dl-tls.c:377
377 dl-tls.c: No such file or directory.
(gdb) br memset
../../gdb-7.5.x/gdb/dwarf2read.c:10202: internal-error: 
dwarf2_record_block_ranges: Assertion `dwarf2_per_objfile->ranges.readin' 
failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) 

LLVM r178533

Original comment by euge...@google.com on 3 Apr 2013 at 8:11

GoogleCodeExporter commented 9 years ago
gdb bugs do not belong here

Original comment by dvyu...@google.com on 18 Jul 2013 at 4:24

GoogleCodeExporter commented 9 years ago
Adding Project:ThreadSanitizer as part of GitHub migration.

Original comment by gli...@google.com on 30 Jul 2015 at 9:21