pthread_self() problem in DRD
pjfloyd at wanadoo.fr
Sat Dec 19 12:02:49 UTC 2020
I'm trying to debug an issue in DRD (a thread hazard detection tool,
part of Valgrind). There is an issue when using shared libraries.
A detailed description is here
In short, the flow of events is
1. [guest] The DRD init function gets called (as it is marked
2. [guest] DRD init sets the current thread id, calling pthread_self()
and using a client request.
3. [host] DRD_(thread_set_pthreadid)() gets called, and it is passed
the DRD tid and the value obtained from pthread_self().
4. [guest] The testcase does a dlopen() and then calls a function in
the shared library
5. [guest] the shard lib function calls pthread_create
6. [host] pthread_create gets intercepted and performs another call to
I've marked thinks as guest/host, in reality there is only one process
The problem is that the thread id obtained in step 3 is not the same as
the one obtained in step 6. The result is an assert.
1. Is there any reason why pthread_self() should return different
values when executed from a constructor and then from a dlopen()'d
2. Is there any initialization code that affects the value returned by
pthread_self()? It's possible that something is missing.
More information about the freebsd-hackers