odyaka341 / thread-sanitizer

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

Incorrect wrapping of pthread_cond_init #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
$ cat t.c
#include <pthread.h>
#include <stdio.h>

int main() {
  pthread_cond_t cond;
  pthread_condattr_t condAttr;
  int result = pthread_condattr_init(&condAttr);
  if (result != 0) {
        fprintf(stderr, "HERE: %s:%d\n", __FILE__, __LINE__);
        return -1;
  }
  result = pthread_condattr_setclock(&condAttr, CLOCK_MONOTONIC);
  if (result != 0) {
    fprintf(stderr, "HERE: %s:%d\n", __FILE__, __LINE__);
    return -1;
  }
  fprintf(stderr, "pthread_cond_init(%p, %p)\n", &cond, &condAttr);
  result = pthread_cond_init(&cond, &condAttr);
  if (result != 0) {
    fprintf(stderr, "HERE: %s:%d\n", __FILE__, __LINE__);
    fprintf(stderr, "result: %d\n", result);
    return -1;
  }
  return 0;
}

$ $CC t.c -o t -fsanitize=thread -pie -fPIC && ./t
pthread_cond_init(0x7fffbb707118, 0x7fffbb707110)
HERE: t.c:20
result: 22
$ $CC t.c -o t -lpthread && ./t
pthread_cond_init(0x7fff6915cf78, 0x7fff6915cf70)

It turns out that an incorrect version of pthread_cond_init (there are two of 
them) is picked from libpthread.
This particular problem can be solved by removing the pthread_cond_init wrapper 
(thus issue type set to Enhancement)
However chances are that other pthread_cond_* functions will also behave 
incorrectly.

Original issue reported on code.google.com by gli...@google.com on 12 Dec 2012 at 11:30

GoogleCodeExporter commented 9 years ago

Original comment by dvyu...@google.com on 12 Dec 2012 at 1:12

GoogleCodeExporter commented 9 years ago
I'm hitting a similar problem when I'm trying to attach gdb to an instrumented 
program.
This time pthread_cond_wait is incorrectly replaced with a wrong one.

Original comment by gli...@chromium.org on 26 Apr 2013 at 7:05

GoogleCodeExporter commented 9 years ago
Reproducer?

Original comment by dvyu...@google.com on 29 Apr 2013 at 8:57

GoogleCodeExporter commented 9 years ago
That was while compiling PARSEC. Will try again.

Original comment by gli...@chromium.org on 29 Apr 2013 at 11:23