From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 9574E384D16D for ; Fri, 14 Oct 2022 14:36:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9574E384D16D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665758217; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EDqsHUrwZwXuhLtHaI9tVjtAFOBCyRhZgPYpQ3pUlWY=; b=YyzWRf3ifgaJjSiAtPUwo+FvLWMFCIuny33HZEonRuzEcP7p+PAmoAEzWjPN3HE+Dg0chq wk68oV/9GsKe/UMo6XdWAqRndi3yUJXugYX1BJeg8+VDLphLylwqcEOxKKLQuKhKDHUxSk JP+qruno658FNj7+AfGq67/7YU8HckA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-378-C2a0CG_bPLGIEESMJ9KP9A-1; Fri, 14 Oct 2022 10:36:56 -0400 X-MC-Unique: C2a0CG_bPLGIEESMJ9KP9A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F3D0387B2A3; Fri, 14 Oct 2022 14:36:55 +0000 (UTC) Received: from localhost (unknown [10.33.36.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCF982144B2D; Fri, 14 Oct 2022 14:36:55 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Disable all emergency EH pool code if obj-count == 0 Date: Fri, 14 Oct 2022 15:36:55 +0100 Message-Id: <20221014143655.2512929-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested x86_64-linux. Pushed to trunk. -- >8 -- For a zero-sized static pool we can completely elide all code for the EH pool. We no longer need to adjust the static buffer size to ensure at least one free_entry can be created in it, because we no longer use a static buffer at all if obj_count == 0. If the buffer exists, obj_count >= 1 and the buffer will be much larger than sizeof(free_entry). libstdc++-v3/ChangeLog: * libsupc++/eh_alloc.cc [USE_POOL]: New macro. [!USE_POOL] (__gnu_cxx::__freeres, pool): Do not define. [_GLIBCXX_EH_POOL_STATIC] (pool::arena): Do not use std::max. (__cxxabiv1::__cxa_allocate_exception) [!USE_POOL]: Do not use pool. (__cxxabiv1::__cxa_free_exception) [!USE_POOL]: Likewise. (__cxxabiv1::__cxa_allocate_dependent_exception) [!USE_POOL]: Likewise. (__cxxabiv1::__cxa_free_dependent_exception) [!USE_POOL]: Likewise. --- libstdc++-v3/libsupc++/eh_alloc.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/libsupc++/eh_alloc.cc b/libstdc++-v3/libsupc++/eh_alloc.cc index 81b8a1548c6..e93f14c887b 100644 --- a/libstdc++-v3/libsupc++/eh_alloc.cc +++ b/libstdc++-v3/libsupc++/eh_alloc.cc @@ -101,12 +101,21 @@ using namespace __cxxabiv1; #ifdef _GLIBCXX_EH_POOL_NOBJS # if _GLIBCXX_EH_POOL_NOBJS > MAX_OBJ_COUNT # warning "_GLIBCXX_EH_POOL_NOBJS value is too large; ignoring it" +# elif _GLIBCXX_EH_POOL_NOBJS < 0 +# warning "_GLIBCXX_EH_POOL_NOBJS value is negative; ignoring it" # else # undef EMERGENCY_OBJ_COUNT # define EMERGENCY_OBJ_COUNT _GLIBCXX_EH_POOL_NOBJS # endif #endif +#if defined _GLIBCXX_EH_POOL_STATIC && EMERGENCY_OBJ_COUNT == 0 +# define USE_POOL 0 +#else +# define USE_POOL 1 +#endif + +#if USE_POOL namespace __gnu_cxx { void __freeres() noexcept; @@ -161,7 +170,7 @@ namespace #ifdef _GLIBCXX_EH_POOL_STATIC static constexpr std::size_t arena_size = buffer_size_in_bytes(EMERGENCY_OBJ_COUNT, EMERGENCY_OBJ_SIZE); - alignas(void*) char arena[std::max(arena_size, sizeof(free_entry))]; + alignas(void*) char arena[arena_size]; #else char *arena = nullptr; std::size_t arena_size = 0; @@ -374,6 +383,7 @@ namespace __gnu_cxx #endif } } +#endif // USE_POOL extern "C" void * __cxxabiv1::__cxa_allocate_exception(std::size_t thrown_size) noexcept @@ -382,8 +392,10 @@ __cxxabiv1::__cxa_allocate_exception(std::size_t thrown_size) noexcept void *ret = malloc (thrown_size); +#if USE_POOL if (!ret) ret = emergency_pool.allocate (thrown_size); +#endif if (!ret) std::terminate (); @@ -398,9 +410,11 @@ extern "C" void __cxxabiv1::__cxa_free_exception(void *vptr) noexcept { char *ptr = (char *) vptr - sizeof (__cxa_refcounted_exception); +#if USE_POOL if (emergency_pool.in_pool (ptr)) [[__unlikely__]] emergency_pool.free (ptr); else +#endif free (ptr); } @@ -410,8 +424,10 @@ __cxxabiv1::__cxa_allocate_dependent_exception() noexcept { void *ret = malloc (sizeof (__cxa_dependent_exception)); +#if USE_POOL if (!ret) ret = emergency_pool.allocate (sizeof (__cxa_dependent_exception)); +#endif if (!ret) std::terminate (); @@ -426,8 +442,10 @@ extern "C" void __cxxabiv1::__cxa_free_dependent_exception (__cxa_dependent_exception *vptr) noexcept { +#if USE_POOL if (emergency_pool.in_pool (vptr)) [[__unlikely__]] emergency_pool.free (vptr); else +#endif free (vptr); } -- 2.37.3