diff --git a/libstdc++-v3/Makefile.in b/libstdc++-v3/Makefile.in
index 58a0acdcc1b..a7c2b60678b 100644
--- a/libstdc++-v3/Makefile.in
+++ b/libstdc++-v3/Makefile.in
@@ -240,6 +240,7 @@ ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
+EH_POOL_FLAGS = @EH_POOL_FLAGS@
ERROR_CONSTANTS_SRCDIR = @ERROR_CONSTANTS_SRCDIR@
EXEEXT = @EXEEXT@
EXTRA_CFLAGS = @EXTRA_CFLAGS@
diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 719eab15c77..6523ba9a816 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -5092,6 +5092,51 @@ BACKTRACE_CPPFLAGS="$BACKTRACE_CPPFLAGS -DBACKTRACE_ELF_SIZE=$elfsize"
GLIBCXX_CONDITIONAL(ENABLE_BACKTRACE, [test "$enable_libstdcxx_backtrace" = yes])
])
+dnl
+dnl Allow the emergency EH pool to be configured.
+dnl
+dnl --enable-libstdcxx-static-eh-pool will cause a fixed-size static buffer
+dnl to be used for allocating exceptions after malloc fails. The default is
+dnl to allocate a buffer using malloc
+dnl
+dnl --with-libstdcxx-eh-pool-obj-count=N will set the default size for the
+dnl buffer. For a static buffer that size is fixed permanently. For a dynamic
+dnl buffer it's the default, but it can be overridden from the environment.
+dnl
+dnl To set the default to approximately the same values as GCC 12,
+dnl use --with-libstdcxx-eh-pool-obj-count=94 for 32-bit targets,
+dnl and --with-libstdcxx-eh-pool-obj-count=252 for 64-bit targets.
+dnl
+dnl Defines:
+dnl _GLIBCXX_EH_POOL_STATIC if a fixed-size static buffer should be used
+dnl instead of allocating a buffer on startup.
+dnl _GLIBCXX_EH_POOL_NOBJS to override the default EMERGENCY_OBJ_COUNT value.
+dnl
+AC_DEFUN([GLIBCXX_EMERGENCY_EH_ALLOC], [
+ eh_pool_static=
+ eh_pool_nobjs=
+ AC_ARG_ENABLE([libstdcxx-static-eh-pool],
+ AC_HELP_STRING([--enable-libstdcxx-static-eh-pool],
+ [use a fixed-size static buffer for allocating exceptions if malloc fails]),
+ [if test "${enableval}" = yes; then
+ eh_pool_static="-D_GLIBCXX_EH_POOL_STATIC"
+ AC_MSG_NOTICE([EH pool using static buffer])
+ fi],)
+
+ AC_ARG_WITH([libstdcxx-eh-pool-obj-count],
+ AC_HELP_STRING([--with-libstdcxx-eh-pool-obj-count],
+ [the number of exceptions that can be allocated from the pool if malloc fails]),
+ [if test "${withval}" -ge 0 2>/dev/null; then
+ eh_pool_obj_count="-D_GLIBCXX_EH_POOL_NOBJS=${withval}"
+ AC_MSG_NOTICE([EH pool object count: ${withval}])
+ else
+ AC_MSG_ERROR([EH pool obj count must be a non-negative integer: $withval])
+ fi],)
+
+ EH_POOL_FLAGS="$eh_pool_static $eh_pool_obj_count"
+ AC_SUBST(EH_POOL_FLAGS)
+])
+
# Macros from the top-level gcc directory.
m4_include([../config/gc++filt.m4])
m4_include([../config/tls.m4])
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 4bb1d73f0e0..b564175a040 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -675,6 +675,7 @@ DOT
DOXYGEN
BUILD_INFO_FALSE
BUILD_INFO_TRUE
+EH_POOL_FLAGS
ENABLE_BACKTRACE_FALSE
ENABLE_BACKTRACE_TRUE
BACKTRACE_SUPPORTS_THREADS
@@ -958,6 +959,8 @@ with_default_libstdcxx_abi
enable_libstdcxx_threads
enable_libstdcxx_filesystem_ts
enable_libstdcxx_backtrace
+enable_libstdcxx_static_eh_pool
+with_libstdcxx_eh_pool_obj_count
enable_cet
with_gxx_include_dir
enable_version_specific_runtime_libs
@@ -1668,6 +1671,9 @@ Optional Features:
turns on ISO/IEC TS 18822 support [default=auto]
--enable-libstdcxx-backtrace
turns on libbacktrace support [default=auto]
+ --enable-libstdcxx-static-eh-pool
+ use a fixed-size static buffer for allocating
+ exceptions if malloc fails
--enable-cet enable Intel CET in target libraries [default=auto]
--enable-version-specific-runtime-libs
Specify that runtime libraries should be installed
@@ -1695,6 +1701,9 @@ Optional Packages:
--with-system-libunwind use installed libunwind
--with-default-libstdcxx-abi
set the std::string ABI to use by default
+ --with-libstdcxx-eh-pool-obj-count
+ the number of exceptions that can be allocated from
+ the pool if malloc fails
--with-gxx-include-dir=DIR
installation directory for include files
--with-toolexeclibdir=DIR
@@ -12227,7 +12236,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 12206 "configure"
+#line 12215 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -12333,7 +12342,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 12312 "configure"
+#line 12321 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -16053,7 +16062,7 @@ $as_echo "$glibcxx_cv_atomic_long_long" >&6; }
# Fake what AC_TRY_COMPILE does.
cat > conftest.$ac_ext << EOF
-#line 16012 "configure"
+#line 16021 "configure"
int main()
{
typedef bool atomic_type;
@@ -16088,7 +16097,7 @@ $as_echo "$glibcxx_cv_atomic_bool" >&6; }
rm -f conftest*
cat > conftest.$ac_ext << EOF
-#line 16047 "configure"
+#line 16056 "configure"
int main()
{
typedef short atomic_type;
@@ -16123,7 +16132,7 @@ $as_echo "$glibcxx_cv_atomic_short" >&6; }
rm -f conftest*
cat > conftest.$ac_ext << EOF
-#line 16082 "configure"
+#line 16091 "configure"
int main()
{
// NB: _Atomic_word not necessarily int.
@@ -16159,7 +16168,7 @@ $as_echo "$glibcxx_cv_atomic_int" >&6; }
rm -f conftest*
cat > conftest.$ac_ext << EOF
-#line 16118 "configure"
+#line 16127 "configure"
int main()
{
typedef long long atomic_type;
@@ -16315,7 +16324,7 @@ $as_echo "mutex" >&6; }
# unnecessary for this test.
cat > conftest.$ac_ext << EOF
-#line 16274 "configure"
+#line 16283 "configure"
int main()
{
_Decimal32 d1;
@@ -16357,7 +16366,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
# unnecessary for this test.
cat > conftest.$ac_ext << EOF
-#line 16316 "configure"
+#line 16325 "configure"
template
Table of Contents
ios::nocreate/ios::noreplace
.
stream::attach(int fd)