This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
tls, valgrind gdbserver and qGetTLSAddr
- From: Philippe Waroquiers <philippe dot waroquiers at skynet dot be>
- To: libc-alpha at sourceware dot org
- Date: Mon, 04 Aug 2014 22:24:40 +0200
- Subject: tls, valgrind gdbserver and qGetTLSAddr
- Authentication-results: sourceware.org; auth=none
I am busy adding to the Valgrind gdbserver the code to handle
the gdbserver protocol query qGetTLSAddr.
First idea was to use libthread_db but that would make the
GDB<->vgdb<->Valgrind chain more complex:
vgdb would need to understand the GDB remote protocol to intercept
qGetTLSAddr (or Valgrind should do a query to vgdb that would use
libthread_db).
Then a 'parallel' protocol between vgdb and Valgrind is needed
to fullfil what libthread_db would request.
Looks complex, and a lot/too much work, even for an evening hobby :).
So, the less ugly solution I found is to implement inside
Valgrind the logic to handle qGetTLSAddr.
I have an implementation already working on x86/amd64/arm64/ppc32/ppc64.
However, this is based on 2 'magic' offsets:
1. Offset needed to get the dtv from the thread pointer
2. Offset needed to find the module id field in the link_map struct.
I am wondering if there is a (not too ugly) way to obtain these
offsets (knowing that building valgrind should not depend on the
glibc source code).
An ugly hack to get the module id offset in link_map is to launch
a small exe doing:
size_t sizes[10000];
size_t i;
size_t modid_offset;
for (i = 0; i < 10000; i++) sizes[i] = i;
if (dlinfo ((void*)sizes, RTLD_DI_TLS_MODID, &modid_offset) == 0)
printf("modid offset 0x%x\n", modid_offset*sizeof(size_t));
For the moment, I have not found a similar ugly hack to find the
dtv offset to add to thread pointer.
So, I am hardcoding the dtv offset, depending on the arch: x86,ppc32,...
Any better suggestion on how to get these offsets ?
Or alternatively, any better suggestion on how to implement
qGetTLSAddr inside Valgrind ?
Thanks
Philippe
NB: there is another tls/valgrind helgrind discussion in
https://sourceware.org/ml/libc-alpha/2014-07/msg00438.html
Additional feedback about this also welcome.