summaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-devtools
diff options
context:
space:
mode:
authorMarkus Volk <f_l_k@t-online.de>2026-05-30 09:18:30 +0200
committerKhem Raj <khem.raj@oss.qualcomm.com>2026-06-07 18:21:32 -0700
commitb2206db6d791264539f29d01370ca61d2a847673 (patch)
treeed6cb0ae3fda16c382e19bad9a654f97fdf96ba5 /meta-oe/recipes-devtools
parentfe8e466c68f21669356bd895c0b7d1545689af93 (diff)
downloadmeta-openembedded-b2206db6d791264539f29d01370ca61d2a847673.tar.gz
jemalloc: add backport patch to fix build with gcc 16
This patch replaces std::__throw_bad_alloc call with standard C++ Signed-off-by: Markus Volk <f_l_k@t-online.de> Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
Diffstat (limited to 'meta-oe/recipes-devtools')
-rw-r--r--meta-oe/recipes-devtools/jemalloc/files/1a15fe33a48c52bfe26ea83e49f0d317a47da3ea.patch158
-rw-r--r--meta-oe/recipes-devtools/jemalloc/jemalloc_5.3.1.bb1
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 @@
1From 1a15fe33a48c52bfe26ea83e49f0d317a47da3ea Mon Sep 17 00:00:00 2001
2From: lexprfuncall <cshapiro@meta.com>
3Date: Mon, 27 Apr 2026 11:50:27 -0700
4Subject: [PATCH] Replace std::__throw_bad_alloc call with standard C++ (#2900)
5
6* Replace std::__throw_bad_alloc call with standard C++
7
8Since December of 2025, std::__throw_bad_alloc is no longer visible
9through #include <new> causing jemalloc build failures with gcc 16.
10As far as I can tell, all std::__throw_bad_alloc did was arrange to
11raise a std::bad_alloc exception if exceptions are enabled. I am not
12sure whether its usage was truly meaningful in jemalloc since the call
13is wrapped in a try catch and any usage of try catch is considered an
14error when compiling with -fno-exceptions on gcc, at least.
15
16This change adds a check to configure.ac that determines whether
17exceptions are enabled by compiling a simple try catch that raises a
18std::bad_alloc exception. If that test succeeds, the macro
19JEMALLOC_HAVE_CXX_EXCEPTIONS is defined, and jemalloc will raise an
20exception. Otherwise, we call std::terminate() to abort.
21
22This was tested on FreeBSD with the gcc16 port with and without exceptions
23enabled.
24
25* Replace std::set_new_handler calls with std::get_new_handler
26
27Previously, std::set_new_handler was used as a workaround for
28compilers with only partial support for C++11. Now that C++14 is a
29requirement to enable C++ support, we can assume std::get_new_handler
30is available.
31
32Upstream-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
40diff --git a/Makefile.in b/Makefile.in
41index 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 :=
58diff --git a/configure.ac b/configure.ac
59index 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])
93diff --git a/include/jemalloc/internal/jemalloc_internal_defs.h.in b/include/jemalloc/internal/jemalloc_internal_defs.h.in
94index 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
107diff --git a/src/jemalloc_cpp.cpp b/src/jemalloc_cpp.cpp
108index 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"
14LIC_FILES_CHKSUM = "file://COPYING;md5=ea061f8731d5e6a5761dfad951ef5f5f" 14LIC_FILES_CHKSUM = "file://COPYING;md5=ea061f8731d5e6a5761dfad951ef5f5f"
15 15
16SRC_URI = "git://github.com/jemalloc/jemalloc.git;branch=master;protocol=https;tag=${PV} \ 16SRC_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 "
19SRCREV = "81034ce1f1373e37dc865038e1bc8eeecf559ce8" 20SRCREV = "81034ce1f1373e37dc865038e1bc8eeecf559ce8"