From patchwork Tue Oct 20 18:34:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 533102 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42BB51402B3 for ; Wed, 21 Oct 2015 05:35:41 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=YLnDj4PC; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=FvZW5yDEZpkZr4PbmKV8GA2e6yDDpjzluUtIURqACEgHwFSSjNV7t Dxk3ypYc48rQko7XCQl8IDsIa6kpKtO2eKBTwOHO+8aDgKZLQUC4TpqOrq69plie lK9U8u+wmN5frEuh4peY3Qdtzph7vQXbB//IbKWsEX9yrrE9CKIrLE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=RTOXuTCmdOXwixMQugh9hLUkoIg=; b=YLnDj4PCKKwiWMb1ApWY SOHirnBXRezjpW/oyxjnuUVkGzQWWmCAT9jiyUVJIRIsLYDkfIGv55kUyct1NrrV 1tRR5Rx6DEzydqoCGMuGQdH0PyiUxo+88ESB0uPo0k+pSsHz3DuPS5zq2N0ZrFtv 2Z9eyo2hVmaNAdCNSjsKX/A= Received: (qmail 8309 invoked by alias); 20 Oct 2015 18:34:46 -0000 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 Received: (qmail 8239 invoked by uid 89); 20 Oct 2015 18:34:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: smtp.ispras.ru Received: from smtp.ispras.ru (HELO smtp.ispras.ru) (83.149.199.79) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Oct 2015 18:34:44 +0000 Received: from condor.intra.ispras.ru (unknown [83.149.199.91]) by smtp.ispras.ru (Postfix) with ESMTP id 813BA21D55; Tue, 20 Oct 2015 21:34:37 +0300 (MSK) Received: by condor.intra.ispras.ru (Postfix, from userid 23246) id F049F1225DEB; Tue, 20 Oct 2015 21:34:36 +0300 (MSK) From: Alexander Monakov To: gcc-patches@gcc.gnu.org Cc: Jakub Jelinek , Dmitry Melnik Subject: [gomp4 11/14] libgomp: avoid variable-length stack allocation in team.c Date: Tue, 20 Oct 2015 21:34:33 +0300 Message-Id: <1445366076-16082-12-git-send-email-amonakov@ispras.ru> In-Reply-To: <1445366076-16082-1-git-send-email-amonakov@ispras.ru> References: <1445366076-16082-1-git-send-email-amonakov@ispras.ru> X-IsSubscribed: yes NVPTX does not support alloca or variable-length stack allocations, thus heap allocation needs to be used instead. I've opted to make this a generic change instead of guarding it with an #ifdef: libgomp usually leaves thread stack size up to libc, so avoiding unbounded stack allocation makes sense. * task.c (GOMP_task): Use a fixed-size on-stack buffer or a heap allocation instead of a variable-size on-stack allocation. --- libgomp/task.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libgomp/task.c b/libgomp/task.c index 74920d5..ffb7ed2 100644 --- a/libgomp/task.c +++ b/libgomp/task.c @@ -162,11 +162,16 @@ GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *), thr->task = &task; if (__builtin_expect (cpyfn != NULL, 0)) { - char buf[arg_size + arg_align - 1]; + long buf_size = arg_size + arg_align - 1; + char buf_fixed[2048], *buf = buf_fixed; + if (sizeof(buf_fixed) < buf_size) + buf = gomp_malloc (buf_size); char *arg = (char *) (((uintptr_t) buf + arg_align - 1) & ~(uintptr_t) (arg_align - 1)); cpyfn (arg, data); fn (arg); + if (buf != buf_fixed) + free (buf); } else fn (data);