pthread_self() problem in DRD
Paul Floyd
pjfloyd at wanadoo.fr
Sat Dec 19 12:02:49 UTC 2020
Hi
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
https://github.com/paulfloyd/freebsd_valgrind/issues/57
In short, the flow of events is
1. [guest] The DRD init function gets called (as it is marked
__attribute__((constructor))
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
DRD_(set_pthread_id)()
I've marked thinks as guest/host, in reality there is only one process
executing.
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.
Two questions
1. Is there any reason why pthread_self() should return different
values when executed from a constructor and then from a dlopen()'d
function?
2. Is there any initialization code that affects the value returned by
pthread_self()? It's possible that something is missing.
A+
Paul
More information about the freebsd-hackers
mailing list