From patchwork Tue Jun 5 06:19:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 163022 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id F3C08B6F13 for ; Tue, 5 Jun 2012 16:20:18 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1339482019; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:From:To:Subject:Date:Message-ID:User-Agent: MIME-Version:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=5M7ItHLr4ddQxZs/G7UYWjGQs4Q=; b=iCETujBCYFWWUAY PAscu+9HuLhz7SYF5eEhmvlhgNHN6QtuJMTxMpdN3onqxFsN8BzCPRGWqQuXGka+ quFgN2zyPdHJ8ZjCj40UsvtNNSsG4m+sO1HPYG3zYcsIYjV7Xm1pr37m01J4b68G CIpz+kW1Cmltm24novHucI2759to= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:Received:Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=wc+5jNNRbgTKi4C5VizmnrabSesPi5avp2SnEew3Gn/CgcP3oI6Q6Jem9TsCx3 JeN4sL4RsWMVHlUPL2eIRDzZuk42xf7lXt/G6+j0xoRrkvvQYFNLIneERiKLPGfQ 26MvlZ3NbXJ5vXwUJr9fxKRYyenyRAp+8rcHV3dr+NmoU=; Received: (qmail 12088 invoked by alias); 5 Jun 2012 06:20:08 -0000 Received: (qmail 12060 invoked by uid 22791); 5 Jun 2012 06:20:04 -0000 X-SWARE-Spam-Status: No, hits=-4.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-pz0-f47.google.com (HELO mail-pz0-f47.google.com) (209.85.210.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 05 Jun 2012 06:19:49 +0000 Received: by dalh21 with SMTP id h21so6768085dal.20 for ; Mon, 04 Jun 2012 23:19:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type:x-gm-message-state; bh=njNf4TWHAMAMhfR7s2bO/I0FHxYj9nIFK/y1Jt9BO/c=; b=mDaZjco9U335CxXxtvpnZdV+iJFG8kC1c4/Hl7Qq7H0q06Bc9DR6GLH6ibC8/A5XXA Nc5X8XaDvqBG5TL2egGSRsZw6dRn2mGyJaKqCOsclGHQBSMWK/l34dNtjSWc2syZelZB zf89+I1W77JmLhr632rw4fJ5Vx9mXS+cGlzhzLpt3lHeoYY9wcAf/IVaBIuapNH3q3X8 lUjzjtJFIA0pCTHa0r1C+rd6KwtkkpeuBZ1nudj7+B3kQbhtx2giMj2kp7OOeZECefWv LD6alUEZwCccdDs2pe1XjEF5ROKfv6XLRUT4uwa811snUJseyCKMp4mTw/n1yLRqlJGL zjLw== Received: by 10.68.228.136 with SMTP id si8mr34216369pbc.159.1338877189359; Mon, 04 Jun 2012 23:19:49 -0700 (PDT) Received: by 10.68.228.136 with SMTP id si8mr34216356pbc.159.1338877189285; Mon, 04 Jun 2012 23:19:49 -0700 (PDT) Received: from coign.google.com ([216.239.45.130]) by mx.google.com with ESMTPS id z2sm1283876pbv.34.2012.06.04.23.19.47 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 04 Jun 2012 23:19:48 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: libgo patch committed: Include TLS size in stack size Date: Mon, 04 Jun 2012 23:19:46 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlkSuWyRGZLogT9tXEuxukdP2VXH5+/xFHk7qaG7ha0l54YbXvZ09wQwmudOrf+ZaNMIa84W34pKzJQQb0jXMZ2Vre0jPS9EZh19t7VYbq4dGeYCmLPLs4D+6SYY0uW3Mv1vcrke/AKWLxNMTkLstyGHrWfsA== X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch to libgo includes the TLS size in the requested stack size of a new thread, if possible. This relies on the glibc-specific (and undocumented) _dl_get_tls_static_info call. This is particularly necessary when using glibc, because glibc removes the static TLS size from the requested stack space, and gives an error if there is not enough space. That means that a program that has a lot of TLS variables will fail bizarrely, or worse may simply get a stack overflow segmentation violation at runtime. This patch is far from perfect, but at least works around that problem for such programs. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline and 4.7 branch. Ian Index: libgo/configure.ac =================================================================== --- libgo/configure.ac (revision 187020) +++ libgo/configure.ac (working copy) @@ -481,7 +481,7 @@ fi AM_CONDITIONAL(HAVE_SYS_MMAN_H, test "$ac_cv_header_sys_mman_h" = yes) -AC_CHECK_FUNCS(strerror_r strsignal wait4 mincore setenv) +AC_CHECK_FUNCS(strerror_r strsignal wait4 mincore setenv _dl_get_tls_static_info) AM_CONDITIONAL(HAVE_STRERROR_R, test "$ac_cv_func_strerror_r" = yes) AM_CONDITIONAL(HAVE_WAIT4, test "$ac_cv_func_wait4" = yes) Index: libgo/runtime/proc.c =================================================================== --- libgo/runtime/proc.c (revision 187854) +++ libgo/runtime/proc.c (working copy) @@ -1105,6 +1105,7 @@ runtime_newm(void) M *m; pthread_attr_t attr; pthread_t tid; + size_t stacksize; m = runtime_malloc(sizeof(M)); mcommoninit(m); @@ -1118,7 +1119,31 @@ runtime_newm(void) #ifndef PTHREAD_STACK_MIN #define PTHREAD_STACK_MIN 8192 #endif - if(pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN) != 0) + + stacksize = PTHREAD_STACK_MIN; + +#ifdef HAVE__DL_GET_TLS_STATIC_INFO + { + /* On GNU/Linux the static TLS size is taken out of + the stack size, and we get an error or a crash if + there is not enough stack space left. Add it back + in if we can, in case the program uses a lot of TLS + space. */ +#ifndef internal_function +#ifdef __i386__ +#define internal_function __attribute__ ((regparm (3), stdcall)) +#else +#define internal_function +#endif +#endif + extern void _dl_get_tls_static_info(size_t*, size_t*) internal_function; + size_t tlssize, tlsalign; + _dl_get_tls_static_info(&tlssize, &tlsalign); + stacksize += tlssize; + } +#endif + + if(pthread_attr_setstacksize(&attr, stacksize) != 0) runtime_throw("pthread_attr_setstacksize"); if(pthread_create(&tid, &attr, runtime_mstart, m) != 0)