diff options
| -rw-r--r-- | meta-oe/recipes-devtools/jemalloc/files/1a15fe33a48c52bfe26ea83e49f0d317a47da3ea.patch | 158 | ||||
| -rw-r--r-- | meta-oe/recipes-devtools/jemalloc/jemalloc_5.3.1.bb | 1 |
2 files changed, 159 insertions, 0 deletions
diff --git a/meta-oe/recipes-devtools/jemalloc/files/1a15fe33a48c52bfe26ea83e49f0d317a47da3ea.patch b/meta-oe/recipes-devtools/jemalloc/files/1a15fe33a48c52bfe26ea83e49f0d317a47da3ea.patch new file mode 100644 index 0000000000..a4fad4af61 --- /dev/null +++ b/meta-oe/recipes-devtools/jemalloc/files/1a15fe33a48c52bfe26ea83e49f0d317a47da3ea.patch | |||
| @@ -0,0 +1,158 @@ | |||
| 1 | From 1a15fe33a48c52bfe26ea83e49f0d317a47da3ea Mon Sep 17 00:00:00 2001 | ||
| 2 | From: lexprfuncall <cshapiro@meta.com> | ||
| 3 | Date: Mon, 27 Apr 2026 11:50:27 -0700 | ||
| 4 | Subject: [PATCH] Replace std::__throw_bad_alloc call with standard C++ (#2900) | ||
| 5 | |||
| 6 | * Replace std::__throw_bad_alloc call with standard C++ | ||
| 7 | |||
| 8 | Since December of 2025, std::__throw_bad_alloc is no longer visible | ||
| 9 | through #include <new> causing jemalloc build failures with gcc 16. | ||
| 10 | As far as I can tell, all std::__throw_bad_alloc did was arrange to | ||
| 11 | raise a std::bad_alloc exception if exceptions are enabled. I am not | ||
| 12 | sure whether its usage was truly meaningful in jemalloc since the call | ||
| 13 | is wrapped in a try catch and any usage of try catch is considered an | ||
| 14 | error when compiling with -fno-exceptions on gcc, at least. | ||
| 15 | |||
| 16 | This change adds a check to configure.ac that determines whether | ||
| 17 | exceptions are enabled by compiling a simple try catch that raises a | ||
| 18 | std::bad_alloc exception. If that test succeeds, the macro | ||
| 19 | JEMALLOC_HAVE_CXX_EXCEPTIONS is defined, and jemalloc will raise an | ||
| 20 | exception. Otherwise, we call std::terminate() to abort. | ||
| 21 | |||
| 22 | This was tested on FreeBSD with the gcc16 port with and without exceptions | ||
| 23 | enabled. | ||
| 24 | |||
| 25 | * Replace std::set_new_handler calls with std::get_new_handler | ||
| 26 | |||
| 27 | Previously, std::set_new_handler was used as a workaround for | ||
| 28 | compilers with only partial support for C++11. Now that C++14 is a | ||
| 29 | requirement to enable C++ support, we can assume std::get_new_handler | ||
| 30 | is available. | ||
| 31 | |||
| 32 | Upstream-Status: Backport [https://github.com/jemalloc/jemalloc/commit/1a15fe33a48c52bfe26ea83e49f0d317a47da3ea] | ||
| 33 | --- | ||
| 34 | Makefile.in | 6 +++-- | ||
| 35 | configure.ac | 23 +++++++++++++++++ | ||
| 36 | .../internal/jemalloc_internal_defs.h.in | 3 +++ | ||
| 37 | src/jemalloc_cpp.cpp | 25 ++++++++++--------- | ||
| 38 | 4 files changed, 43 insertions(+), 14 deletions(-) | ||
| 39 | |||
| 40 | diff --git a/Makefile.in b/Makefile.in | ||
| 41 | index a93048d7b8..1f9d14f1f2 100644 | ||
| 42 | --- a/Makefile.in | ||
| 43 | +++ b/Makefile.in | ||
| 44 | @@ -337,9 +337,11 @@ TESTS_INTEGRATION += \ | ||
| 45 | endif | ||
| 46 | ifeq (@enable_cxx@, 1) | ||
| 47 | CPP_SRCS := $(srcroot)src/jemalloc_cpp.cpp | ||
| 48 | -TESTS_INTEGRATION_CPP := $(srcroot)test/integration/cpp/basic.cpp \ | ||
| 49 | - $(srcroot)test/integration/cpp/infallible_new_true.cpp \ | ||
| 50 | +TESTS_INTEGRATION_CPP := $(srcroot)test/integration/cpp/basic.cpp | ||
| 51 | +ifeq (@enable_cxx_exceptions@, 1) | ||
| 52 | +TESTS_INTEGRATION_CPP += $(srcroot)test/integration/cpp/infallible_new_true.cpp \ | ||
| 53 | $(srcroot)test/integration/cpp/infallible_new_false.cpp | ||
| 54 | +endif | ||
| 55 | else | ||
| 56 | CPP_SRCS := | ||
| 57 | TESTS_INTEGRATION_CPP := | ||
| 58 | diff --git a/configure.ac b/configure.ac | ||
| 59 | index 321a729012..d151829832 100644 | ||
| 60 | --- a/configure.ac | ||
| 61 | +++ b/configure.ac | ||
| 62 | @@ -374,7 +374,30 @@ fi | ||
| 63 | if test "x$enable_cxx" = "x1"; then | ||
| 64 | AC_DEFINE([JEMALLOC_ENABLE_CXX], [ ], [ ]) | ||
| 65 | fi | ||
| 66 | +if test "x$enable_cxx" = "x1"; then | ||
| 67 | + dnl Now check whether the C++ compiler has exceptions enabled. | ||
| 68 | + AC_LANG_PUSH([C++]) | ||
| 69 | + SAVED_CXXFLAGS="${CXXFLAGS}" | ||
| 70 | + CXXFLAGS="${CXXFLAGS} ${EXTRA_CXXFLAGS}" | ||
| 71 | + JE_COMPILABLE([C++ exception support], [ | ||
| 72 | +#include <new> | ||
| 73 | +], [ | ||
| 74 | + try { | ||
| 75 | + throw std::bad_alloc(); | ||
| 76 | + } catch (const std::bad_alloc &) { | ||
| 77 | + } | ||
| 78 | +], [je_cv_cxx_exceptions]) | ||
| 79 | + CXXFLAGS="${SAVED_CXXFLAGS}" | ||
| 80 | + AC_LANG_POP([C++]) | ||
| 81 | + if test "x${je_cv_cxx_exceptions}" = "xyes" ; then | ||
| 82 | + AC_DEFINE([JEMALLOC_HAVE_CXX_EXCEPTIONS], [ ], [ ]) | ||
| 83 | + enable_cxx_exceptions="1" | ||
| 84 | + else | ||
| 85 | + enable_cxx_exceptions="0" | ||
| 86 | + fi | ||
| 87 | +fi | ||
| 88 | AC_SUBST([enable_cxx]) | ||
| 89 | +AC_SUBST([enable_cxx_exceptions]) | ||
| 90 | AC_SUBST([CONFIGURE_CXXFLAGS]) | ||
| 91 | AC_SUBST([SPECIFIED_CXXFLAGS]) | ||
| 92 | AC_SUBST([EXTRA_CXXFLAGS]) | ||
| 93 | diff --git a/include/jemalloc/internal/jemalloc_internal_defs.h.in b/include/jemalloc/internal/jemalloc_internal_defs.h.in | ||
| 94 | index 31ae2e8ed2..54d4da2032 100644 | ||
| 95 | --- a/include/jemalloc/internal/jemalloc_internal_defs.h.in | ||
| 96 | +++ b/include/jemalloc/internal/jemalloc_internal_defs.h.in | ||
| 97 | @@ -465,6 +465,9 @@ | ||
| 98 | /* Is C++ support being built? */ | ||
| 99 | #undef JEMALLOC_ENABLE_CXX | ||
| 100 | |||
| 101 | +/* Are C++ exceptions enabled? */ | ||
| 102 | +#undef JEMALLOC_HAVE_CXX_EXCEPTIONS | ||
| 103 | + | ||
| 104 | /* Performs additional size checks when defined. */ | ||
| 105 | #undef JEMALLOC_OPT_SIZE_CHECKS | ||
| 106 | |||
| 107 | diff --git a/src/jemalloc_cpp.cpp b/src/jemalloc_cpp.cpp | ||
| 108 | index 4e838d3b51..ac109bb28e 100644 | ||
| 109 | --- a/src/jemalloc_cpp.cpp | ||
| 110 | +++ b/src/jemalloc_cpp.cpp | ||
| 111 | @@ -1,4 +1,4 @@ | ||
| 112 | -#include <mutex> | ||
| 113 | +#include <exception> | ||
| 114 | #include <new> | ||
| 115 | // NOLINTBEGIN(misc-use-anonymous-namespace) | ||
| 116 | |||
| 117 | @@ -78,29 +78,30 @@ handleOOM(std::size_t size, bool nothrow) { | ||
| 118 | void *ptr = nullptr; | ||
| 119 | |||
| 120 | while (ptr == nullptr) { | ||
| 121 | - std::new_handler handler; | ||
| 122 | - // GCC-4.8 and clang 4.0 do not have std::get_new_handler. | ||
| 123 | - { | ||
| 124 | - static std::mutex mtx; | ||
| 125 | - std::lock_guard<std::mutex> lock(mtx); | ||
| 126 | - | ||
| 127 | - handler = std::set_new_handler(nullptr); | ||
| 128 | - std::set_new_handler(handler); | ||
| 129 | - } | ||
| 130 | + std::new_handler handler = std::get_new_handler(); | ||
| 131 | if (handler == nullptr) | ||
| 132 | break; | ||
| 133 | |||
| 134 | +#ifdef JEMALLOC_HAVE_CXX_EXCEPTIONS | ||
| 135 | try { | ||
| 136 | handler(); | ||
| 137 | } catch (const std::bad_alloc &) { | ||
| 138 | break; | ||
| 139 | } | ||
| 140 | +#else | ||
| 141 | + handler(); | ||
| 142 | +#endif | ||
| 143 | |||
| 144 | ptr = je_malloc(size); | ||
| 145 | } | ||
| 146 | |||
| 147 | - if (ptr == nullptr && !nothrow) | ||
| 148 | - std::__throw_bad_alloc(); | ||
| 149 | + if (ptr == nullptr && !nothrow) { | ||
| 150 | +#ifdef JEMALLOC_HAVE_CXX_EXCEPTIONS | ||
| 151 | + throw std::bad_alloc(); | ||
| 152 | +#else | ||
| 153 | + std::terminate(); | ||
| 154 | +#endif | ||
| 155 | + } | ||
| 156 | return ptr; | ||
| 157 | } | ||
| 158 | |||
diff --git a/meta-oe/recipes-devtools/jemalloc/jemalloc_5.3.1.bb b/meta-oe/recipes-devtools/jemalloc/jemalloc_5.3.1.bb index 261ff02e16..f3a310029f 100644 --- a/meta-oe/recipes-devtools/jemalloc/jemalloc_5.3.1.bb +++ b/meta-oe/recipes-devtools/jemalloc/jemalloc_5.3.1.bb | |||
| @@ -14,6 +14,7 @@ SECTION = "libs" | |||
| 14 | LIC_FILES_CHKSUM = "file://COPYING;md5=ea061f8731d5e6a5761dfad951ef5f5f" | 14 | LIC_FILES_CHKSUM = "file://COPYING;md5=ea061f8731d5e6a5761dfad951ef5f5f" |
| 15 | 15 | ||
| 16 | SRC_URI = "git://github.com/jemalloc/jemalloc.git;branch=master;protocol=https;tag=${PV} \ | 16 | SRC_URI = "git://github.com/jemalloc/jemalloc.git;branch=master;protocol=https;tag=${PV} \ |
| 17 | file://1a15fe33a48c52bfe26ea83e49f0d317a47da3ea.patch \ | ||
| 17 | file://run-ptest \ | 18 | file://run-ptest \ |
| 18 | " | 19 | " |
| 19 | SRCREV = "81034ce1f1373e37dc865038e1bc8eeecf559ce8" | 20 | SRCREV = "81034ce1f1373e37dc865038e1bc8eeecf559ce8" |
