This is the mail archive of the glibc-bugs@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]

[Bug libc/16291] New: feature request: provide simpler ways to compute stack and tls boundaries


https://sourceware.org/bugzilla/show_bug.cgi?id=16291

            Bug ID: 16291
           Summary: feature request: provide simpler ways to compute stack
                    and tls boundaries
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: konstantin.s.serebryany at gmail dot com
                CC: drepper.fsp at gmail dot com

This is both a feature request and a request for a suggestion. 
We are developing dynamic testing tools like AddressSanitizer and
ThreadSanitizer
which are now part of both LLVM and GCC distributions. 
The tools have a run-time library that needs to compute thread's stack and 
tls boundaries. Right now it is done with a series of ugly hacks.

For non-main threads we get the stack boundaries by querying
pthread_getattr_np and pthread_attr_getstack. This works, 
but is problematic because pthread_getattr_np calls malloc and we intercept
malloc. 

For the main thread we get the stack boundaries by querying 
getrlimit, /proc/self/maps, and an address of a local variable because at the
point when we need the info libpthread might not have initialized itself. 

Getting TLS boundaries is even more involved. 
Today we use the glibc's private symbol _dl_get_tls_static_info
and then subtract a magic constant (size of the glibc's thread descriptor).

Most of the code is here: 
http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc?revision=195441
(GetThreadStackTopAndBottom and InitTlsSize)

This works for us on a system we are testing (Ubuntu 12.04),
but this is very fragile and is often broken on older Linux distros. 

Is it possible to compute the stack and tls boundaries more reliably today?
If not, would it be possible to add some new functions to do that?

For every thread (including the main one) we need to know its stack and tls
boundaries and the functions that compute it for us should not call malloc
or any other public library functions. For the main thread, these functions
should
work reliably very early (in pre_init functions)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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