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: [PATCH]: Add to the stack size the TLS size before allocating


The aio thread creation already sets the thread stack size
correctly when needed (commit 232872379ee82cd040a52a48cbbae65a249b5765).

When I was creating the patch I also though about adjust the thread
stack size in 'pthread_attr_setstacksize', however GLIBC strategy using 
by some Ulrich patchs  was to adjust the stack size by just using the 
function '__pthread_get_minstack (&attr)'. The function already takes 
in consideration the static TLS size, the guardsize page, the dl_pagesize 
and PTHREAD_STACK_MIN.


On 03/23/2012 05:42 PM, Carlos O'Donell wrote:
> On Fri, Mar 23, 2012 at 1:44 PM, asharif tools <asharif.tools@gmail.com> wrote:
>> Currently glibc subtracts from the stack size the TLS size and the
>> stack allocation can fail when the TLS is large enough. See this bug:
>> http://sourceware.org/bugzilla/show_bug.cgi?id=11787. This patch
>> addresses that:
>>
>>
>> http://sourceware.org/bugzilla/show_bug.cgi?id=11787
>>
>> When stackallocate() is called, glibc allocates a stack space of:
>> requested_size - TLS_size. The TLS_size could be anything, and in the case of
>> Chrome built with -fprofile-generate, is large enough so stack allocation fails.
>> This patch increases the stack size by the TLS_size so that stack allocation
>> doesn't fail when the TLS is larger than the request size.
>>
>> --- ./glibc-2.11.1/nptl/allocatestack.c 2012-03-21 22:36:08.810112972 -0700
>> +++ ./glibc-2.11.1/nptl/allocatestack.c 2012-03-21 22:39:59.469273930 -0700
>> @@ -349,6 +349,10 @@
>>   /* Get the stack size from the attribute if it is set.  Otherwise we
>>      use the default we determined at start time.  */
>>   size = attr->stacksize ?: __default_stacksize;
>> +  size += __static_tls_size;
>> +#if TLS_TCB_AT_TP
>> +  size += TLS_TCB_SIZE;
>> +#endif
>>
>>   /* Get memory for the stack.  */
>>   if (__builtin_expect (attr->flags & ATTR_FLAG_STACKADDR, 0))
>> @@ -358,7 +363,7 @@
>>       /* If the user also specified the size of the stack make sure it
>>         is large enough.  */
>>       if (attr->stacksize != 0
>> -         && attr->stacksize < (__static_tls_size + MINIMAL_REST_STACK))
>> +         && attr->stacksize < (MINIMAL_REST_STACK))
>>        return EINVAL;
>>
>>       /* Adjust stack size for alignment of the TLS block.  */
>>
>>
>> Any feedback on this patch would be appreciated.
> I responded in the bug. Thanks for posting.
>
> Cheers,
> Carlos.
>


-- 
Adhemerval Zanella Netto


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