Status: Accepted
Owner:
dvyu...@google.com
Labels: Type-Defect Priority-Medium
New issue 12 by
euge...@google.com: SEGV in pthread_create with TSan
http://code.google.com/p/thread-sanitizer/issues/detail?id=12
#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.