* [PATCH] libstdc++: Configurable exception emergency pool size
@ 2022-10-12 19:29 Alexey Lapshin
2022-10-12 20:48 ` Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: Alexey Lapshin @ 2022-10-12 19:29 UTC (permalink / raw)
To: libstdc++; +Cc: Alexey Gerenkov, Anton Maklakov, Ivan Grokhotkov
From 8b27091310d2857880d8733a05813ca92a5a3e6f Mon Sep 17 00:00:00 2001
From: Alexey Gerenkov <alexey@espressif.com>
Date: Thu, 16 Nov 2017 15:06:35 +0300
Subject: [PATCH] libstdc++: Configurable exception emergency pool size
---
libstdc++-v3/libsupc++/eh_alloc.cc | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/libstdc++-v3/libsupc++/eh_alloc.cc b/libstdc++-
v3/libsupc++/eh_alloc.cc
index 68f319869f9..6503041c20a 100644
--- a/libstdc++-v3/libsupc++/eh_alloc.cc
+++ b/libstdc++-v3/libsupc++/eh_alloc.cc
@@ -50,12 +50,13 @@ 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
// just for overhead.
+// To fix this:
+// Implement C function __cxx_eh_arena_size_get() in your codebase
which
+// returns size (size_t) for buffer to allocate.
#if INT_MAX == 32767
# define EMERGENCY_OBJ_SIZE 128
@@ -73,6 +74,12 @@ using namespace __cxxabiv1;
# define EMERGENCY_OBJ_COUNT 4
#endif
+extern "C" __attribute__((weak)) size_t __cxx_eh_arena_size_get(void)
+{
+ return EMERGENCY_OBJ_SIZE * EMERGENCY_OBJ_COUNT
+ + EMERGENCY_OBJ_COUNT * sizeof (__cxa_dependent_exception);
+}
+
namespace __gnu_cxx
{
void __freeres();
@@ -116,11 +123,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);
+ arena_size = __cxx_eh_arena_size_get();
+ arena = arena_size ? (char *)malloc (arena_size) : NULL;
if (!arena)
{
// If the allocation failed go without an emergency pool.
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] libstdc++: Configurable exception emergency pool size
2022-10-12 19:29 [PATCH] libstdc++: Configurable exception emergency pool size Alexey Lapshin
@ 2022-10-12 20:48 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2022-10-12 20:48 UTC (permalink / raw)
To: Alexey Lapshin
Cc: libstdc++, Ivan Grokhotkov, Alexey Gerenkov, Anton Maklakov
On Wed, 12 Oct 2022 at 20:30, Alexey Lapshin via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> From 8b27091310d2857880d8733a05813ca92a5a3e6f Mon Sep 17 00:00:00 2001
> From: Alexey Gerenkov <alexey@espressif.com>
> Date: Thu, 16 Nov 2017 15:06:35 +0300
> Subject: [PATCH] libstdc++: Configurable exception emergency pool size
This patch won't apply to trunk because of
https://gcc.gnu.org/g:637e3668fdc17c4e226538fb14f9fab225433d01
Please take a look at that (and the follow up in
23c3cbaed36f6d2f3a7a64f6ebda69329723514b) and decide if you still want
to change anything.
In any case, I think some targets don't support __attribute((weak)) so
any change like that would have to make it conditional (possibly on
__GXX_WEAK__ but I'm not sure if that's the right check).
> ---
> libstdc++-v3/libsupc++/eh_alloc.cc | 18 +++++++++++-------
> 1 file changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/libstdc++-v3/libsupc++/eh_alloc.cc b/libstdc++-
> v3/libsupc++/eh_alloc.cc
> index 68f319869f9..6503041c20a 100644
> --- a/libstdc++-v3/libsupc++/eh_alloc.cc
> +++ b/libstdc++-v3/libsupc++/eh_alloc.cc
> @@ -50,12 +50,13 @@ 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
> // just for overhead.
> +// To fix this:
> +// Implement C function __cxx_eh_arena_size_get() in your codebase
> which
> +// returns size (size_t) for buffer to allocate.
>
> #if INT_MAX == 32767
> # define EMERGENCY_OBJ_SIZE 128
> @@ -73,6 +74,12 @@ using namespace __cxxabiv1;
> # define EMERGENCY_OBJ_COUNT 4
> #endif
>
> +extern "C" __attribute__((weak)) size_t __cxx_eh_arena_size_get(void)
> +{
> + return EMERGENCY_OBJ_SIZE * EMERGENCY_OBJ_COUNT
> + + EMERGENCY_OBJ_COUNT * sizeof (__cxa_dependent_exception);
> +}
> +
> namespace __gnu_cxx
> {
> void __freeres();
> @@ -116,11 +123,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);
> + arena_size = __cxx_eh_arena_size_get();
> + arena = arena_size ? (char *)malloc (arena_size) : NULL;
> if (!arena)
> {
> // If the allocation failed go without an emergency pool.
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-12 20:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12 19:29 [PATCH] libstdc++: Configurable exception emergency pool size Alexey Lapshin
2022-10-12 20:48 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).