This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: tls, valgrind gdbserver and qGetTLSAddr


This question rings the bell...
https://sourceware.org/ml/libc-alpha/2014-04/msg00313.html
https://sourceware.org/glibc/wiki/ThreadPropertiesAPI

--kcc

On Tue, Aug 5, 2014 at 12:24 AM, Philippe Waroquiers
<philippe.waroquiers@skynet.be> wrote:
> 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.
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]