From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21455 invoked by alias); 4 Dec 2013 04:49:57 -0000 Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org Received: (qmail 21429 invoked by uid 48); 4 Dec 2013 04:49:52 -0000 From: "konstantin.s.serebryany at gmail dot com" To: glibc-bugs@sourceware.org Subject: [Bug libc/16291] New: feature request: provide simpler ways to compute stack and tls boundaries Date: Wed, 04 Dec 2013 04:49:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: libc X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: konstantin.s.serebryany at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-12/txt/msg00046.txt.bz2 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.