[PATCH]: Add to the stack size the TLS size before allocating
Carlos O'Donell
carlos@systemhalted.org
Fri Mar 23 20:42:00 GMT 2012
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.
More information about the Libc-alpha
mailing list