From patchwork Tue Dec 13 13:50:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 87885 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp2211295qgi; Tue, 13 Dec 2016 05:50:27 -0800 (PST) X-Received: by 10.84.215.158 with SMTP id l30mr71712115pli.132.1481637027443; Tue, 13 Dec 2016 05:50:27 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id e23si48080856pli.262.2016.12.13.05.50.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Dec 2016 05:50:27 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-444295-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-444295-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-444295-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=CQ1RpWDdZMVJdDV+1he/JAnffXN9y85sxfW6tovqMLCE22iGx5 qM+oNI0EP0vLL5X9NSLx0zFTUuIbim5hol4+ookJ76IYrQpS5LXtX52rNapWCmGv BU1tuDDSzMq1tXfH3q8VpE0PxFLk1D651IofqyoROrHemecL89wTFHE6o= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=y6UgzF33S2OxSyEHtz3880urmJU=; b=m3iwdH6SxFPn2qrWDdP/ 7llKGlA6HH2AjnsfFd0O18mZagB75ZxsQ0jJtlmRgpQRvnwTbEIYH4lGCZhN0FB8 eqEmDMJzU1T2iEEKWZfxBfxOmP25CtKDPYrfsdolW2YVwsQuMOOj0vFisocwYa0p 9ZZcFTDbfDDf+SJb3XG6DEI= Received: (qmail 125241 invoked by alias); 13 Dec 2016 13:50:15 -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 124308 invoked by uid 89); 13 Dec 2016 13:50:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.0 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=emergency, wheel, H*Ad:D*at, Guess X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Dec 2016 13:50:04 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C38427AE85; Tue, 13 Dec 2016 13:50:02 +0000 (UTC) Received: from localhost (ovpn-116-21.ams2.redhat.com [10.36.116.21]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uBDDo1Oq016791; Tue, 13 Dec 2016 08:50:01 -0500 Date: Tue, 13 Dec 2016 13:50:00 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Markus Eisenmann , Richard Biener Subject: RFC: Allow emergency EH pool size to be controlled (for stage 1) Message-ID: <20161213135000.GP6326@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.1 (2016-10-04) This patch allows the size of the emergency buffer for exception handling to be controlled by a build-time macro (to avoid dynamic allocation) or by a run-time environment variable (to allocate a larger or smaller buffer). This will have to wait for the next stage 1 now, as it's too late for GCC 7, but this shows what I'm thinking about and so might avoid anybody else reinventing the wheel. The patch doesn't include documentation updates for the manual, which would be needed to explain the use of the macro and the env var. We could also add a --with-libstdcxx-static-eh-pool=N configure flag to make it easier to set the macro. commit 4e021613dcda14dfec5c88286f8faf3001afcd17 Author: Jonathan Wakely Date: Tue Dec 13 13:23:48 2016 +0000 Allow pool size to be set by macro or env var diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index 7d0fafa..be4679e 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -257,6 +257,7 @@ if $GLIBCXX_IS_NATIVE; then AC_CHECK_FUNCS(__cxa_thread_atexit_impl) AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc) + AC_CHECK_FUNCS(secure_getenv) # For iconv support. AM_ICONV diff --git a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4 index 8cc788c..c01213a 100644 --- a/libstdc++-v3/crossconfig.m4 +++ b/libstdc++-v3/crossconfig.m4 @@ -184,6 +184,7 @@ case "${host}" in GCC_CHECK_TLS AC_CHECK_FUNCS(__cxa_thread_atexit_impl) AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc) + AC_CHECK_FUNCS(secure_getenv) AM_ICONV ;; *-mingw32*) diff --git a/libstdc++-v3/libsupc++/eh_alloc.cc b/libstdc++-v3/libsupc++/eh_alloc.cc index d362e40..571fe6b 100644 --- a/libstdc++-v3/libsupc++/eh_alloc.cc +++ b/libstdc++-v3/libsupc++/eh_alloc.cc @@ -29,6 +29,7 @@ #include #if _GLIBCXX_HOSTED #include +#include #endif #include #include @@ -36,6 +37,14 @@ #include #include +#ifdef STATIC_EH_ALLOC_POOL_BYTES +char* alloc_pool_arena(std::size_t& size) +{ + size = STATIC_EH_ALLOC_POOL_BYTES; + static alignas(void*) char arena[STATIC_EH_ALLOC_POOL_BYTES]; + return arena; +} +#else #if _GLIBCXX_HOSTED using std::free; using std::malloc; @@ -50,8 +59,6 @@ extern "C" void *memset (void *, int, std::size_t); using namespace __cxxabiv1; -// ??? How to control these parameters. - // Guess from the size of basic types how large a buffer is reasonable. // Note that the basic c++ exception header has 13 pointers and 2 ints, // so on a system with PSImode pointers we're talking about 56 bytes @@ -73,6 +80,32 @@ using namespace __cxxabiv1; # define EMERGENCY_OBJ_COUNT 4 #endif +char *alloc_pool_arena(std::size_t& size) +{ + size = 0; +#if _GLIBCXX_HOSTED + const char *name = "GLIBCXX_EH_ARENA_SIZE"; + char *env = nullptr; +# ifdef _GLIBCXX_HAVE_SECURE_GETENV + env = ::secure_getenv (name); +# else + env = std::getenv (name); +# endif + if (env) + { + char *end; + size = strtoul(env, &end, 0); + if (*end || (size == ULONG_MAX && errno == ERANGE)) + size = 0; + } +#endif // _GLIBCXX_HOSTED + if (size == 0) + size = (EMERGENCY_OBJ_SIZE * EMERGENCY_OBJ_COUNT + + EMERGENCY_OBJ_COUNT * sizeof (__cxa_dependent_exception)); + return (char *)malloc (size); +} +#endif // STATIC_EH_ALLOC_POOL_BYTES + namespace __gnu_cxx { void __freeres(); @@ -107,7 +140,7 @@ namespace // The free-list free_entry *first_free_entry; // The arena itself - we need to keep track of these only - // to implement in_pool. + // to implement in_pool and __freeres. char *arena; std::size_t arena_size; @@ -116,11 +149,8 @@ namespace pool::pool() { - // Allocate the arena - we could add a GLIBCXX_EH_ARENA_SIZE environment - // to make this tunable. - arena_size = (EMERGENCY_OBJ_SIZE * EMERGENCY_OBJ_COUNT - + EMERGENCY_OBJ_COUNT * sizeof (__cxa_dependent_exception)); - arena = (char *)malloc (arena_size); + // Allocate the arena. + arena = alloc_pool_arena (arena_size); if (!arena) { // If the allocation failed go without an emergency pool. @@ -255,11 +285,13 @@ namespace __gnu_cxx void __freeres() { +#ifndef STATIC_EH_ALLOC_POOL_BYTES if (emergency_pool.arena) { ::free(emergency_pool.arena); emergency_pool.arena = 0; } +#endif } }