aboutsummaryrefslogtreecommitdiffhomepage
path: root/freebsd/files/sbrk.patch
blob: 66b94aae245e9fe9ddffbaaaa7a75b513413c62c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
From 62177d06bd9d31242e67995d4e33a755a3447ca2 Mon Sep 17 00:00:00 2001
From: Robin Haberkorn <rhaberkorn@fmsbw.de>
Date: Tue, 19 May 2026 21:21:52 +0400
Subject: [PATCH] check for sbrk() even on UNIX

* Turns out that not all UNIXes support sbrk().
  FreeBSD arm64 and riscv ports don't implement sbrk().
  It's also apparently not in POSIX - so other systems might also
  be affected.
  This needs to be passed on to dlmalloc.
* We now use DLMALLOC_CPPFLAGS instead of conditionals to pass
  on flags to dlmalloc.
* Should be backported to the FreeBSD v2.5.2 package
  to fix Poudriere fallout.
---
 configure.ac                 | 9 ++++++++-
 contrib/dlmalloc/Makefile.am | 7 ++-----
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/configure.ac b/configure.ac
index b5cac0b..43b4d1b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,10 +18,10 @@ AC_CANONICAL_BUILD
 AC_CANONICAL_HOST
 
 AX_CHECK_ENABLE_DEBUG
-AM_CONDITIONAL(DEBUG, [test x$ax_enable_debug != xno])
 if [[ x$ax_enable_debug = xno ]]; then
 	# glib does not look at NDEBUG
 	AC_DEFINE(G_DISABLE_ASSERT, 1, [Disable g_assert()])
+	DLMALLOC_CPPFLAGS="$DLMALLOC_CPPFLAGS -DINSECURE=1"
 fi
 
 # Use the user provided CXXFLAGS for Scintilla as well.
@@ -224,6 +224,13 @@ case $host in
 	;;
 esac
 
+# Optional UNIX libc functions.
+# FreeBSD arm64 and riscv are missing sbrk(), which can be used by dlmalloc.
+AC_CHECK_FUNCS([sbrk], , [
+	DLMALLOC_CPPFLAGS="$DLMALLOC_CPPFLAGS -DHAVE_MORECORE=0"
+])
+AC_SUBST(DLMALLOC_CPPFLAGS)
+
 #
 # Config options
 #
diff --git a/contrib/dlmalloc/Makefile.am b/contrib/dlmalloc/Makefile.am
index 223ed13..73232d7 100644
--- a/contrib/dlmalloc/Makefile.am
+++ b/contrib/dlmalloc/Makefile.am
@@ -1,6 +1,6 @@
 # Source: http://gee.cs.oswego.edu/dl/html/malloc.html
 #
-# FIXME: On FreeBSD, we might implement a compatible mremap() based on the BSD mremap() and pass
+# FIXME: On NetBSD, we might implement a compatible mremap() based on the NetBSD mremap() and pass
 # in -DHAVE_MREMAP=1 -DMREMAP=mremap_bsd. We'll have to add a declaration to malloc.c or
 # use -include mremap_bsd.h in CPPFLAGS.
 #
@@ -8,10 +8,7 @@
 # for increased portability. There is also AC_LIBOBJ, but it's usually for defining sources of
 # replacement libraries.
 
-AM_CPPFLAGS = -DNO_MALLINFO=1 -DNO_MALLOC_STATS=1 -DUSE_LOCKS=1 -DUSE_DL_PREFIX
-if !DEBUG
-AM_CPPFLAGS += -DINSECURE=1
-endif
+AM_CPPFLAGS = @DLMALLOC_CPPFLAGS@ -DNO_MALLINFO=1 -DNO_MALLOC_STATS=1 -DUSE_LOCKS=1 -DUSE_DL_PREFIX
 
 # FIXME: This optimization is still broken as of GCC v9.3.0.
 # This is a known GCC bug, triggered by memset() in calloc().
-- 
2.53.0