Skip to content

Commit 623b67b

Browse files
committed
fix(build): add FreeBSD support to Makefile.cbm with posix wrap, mem_profile and -lexecinfo
1 parent 4567b3b commit 623b67b

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

‎Makefile.cbm‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
# Compiler selection — override via: make CC=gcc CXX=g++
1111
# macOS: cc (Apple Clang) — universal binary with ASan support
12-
# Linux: gcc/g++ — system default with full sanitizer support
12+
# Linux/FreeBSD: gcc/clang — system default with full sanitizer support
1313
# CI scripts pass CC/CXX explicitly; don't rely on defaults here
1414

1515
# Target architecture (macOS): build.sh/test.sh export ARCHFLAGS="-arch <arch>"
1616
# (see scripts/env.sh). Fold it into the compiler drivers with `override` so it
1717
# reaches EVERY compile and link recipe — including the vendored objects below
1818
# that use their own *_CFLAGS — and so it survives a command-line `CC=` override.
19-
# ARCHFLAGS is empty on Linux/Windows and for native direct `make` invocations,
19+
# ARCHFLAGS is empty on Linux/FreeBSD/Windows and for native direct `make` invocations,
2020
# leaving CC/CXX unchanged there.
2121
override CC := $(CC) $(ARCHFLAGS)
2222
override CXX := $(CXX) $(ARCHFLAGS)
@@ -109,19 +109,24 @@ MIMALLOC_WRAP_FLAGS :=
109109
ifeq ($(IS_MINGW),yes)
110110
MIMALLOC_WRAP_FLAGS := $(foreach sym,$(MIMALLOC_WRAP_SYMS),-Wl,--wrap=$(sym))
111111
endif
112-
# Linux wraps a smaller set for MEASUREMENT only (see mem_override_posix.c):
112+
# Linux and FreeBSD wrap a smaller set for MEASUREMENT only (see mem_override_posix.c):
113113
# allocations already reach mimalloc here, but the profiler needs the same
114114
# observation point as Windows or the platform comparison is not like-for-like.
115115
# macOS ld has no --wrap, so it stays census-only.
116-
IS_LINUX := $(shell uname -s 2>/dev/null | grep -q Linux && echo yes || echo no)
116+
IS_POSIX_WRAP := $(shell uname -s 2>/dev/null | grep -qE 'Linux|FreeBSD' && echo yes || echo no)
117117
MIMALLOC_WRAP_SYMS_POSIX := malloc calloc realloc free strdup
118118
MIMALLOC_WRAP_FLAGS_POSIX :=
119-
ifeq ($(IS_LINUX),yes)
119+
ifeq ($(IS_POSIX_WRAP),yes)
120120
MIMALLOC_WRAP_FLAGS_POSIX := $(foreach sym,$(MIMALLOC_WRAP_SYMS_POSIX),-Wl,--wrap=$(sym))
121121
endif
122122
ifeq ($(IS_MINGW),yes)
123123
WIN32_LIBS := -lws2_32 -lpsapi -lshell32 -ladvapi32 -Wl,--allow-multiple-definition -Wl,--stack,8388608 -static
124124
endif
125+
IS_FREEBSD := $(shell uname -s 2>/dev/null | grep -q 'FreeBSD' && echo yes || echo no)
126+
EXECINFO_LIBS :=
127+
ifeq ($(IS_FREEBSD),yes)
128+
EXECINFO_LIBS := -lexecinfo
129+
endif
125130

126131
# STATIC=1 produces a fully static binary (for Alpine/musl portable builds)
127132
ifeq ($(STATIC),1)
@@ -230,18 +235,20 @@ endif # ELF_BUILD
230235
endif # PRODUCTION_HARDENING
231236

232237
# The POSIX wrap shim exists only so the profiler can observe allocations. It
233-
# must never reach a sanitized build: the Linux/macOS test builds are CRT+ASan,
238+
# must never reach a sanitized build: the Linux/macOS/FreeBSD test builds are CRT+ASan,
234239
# and redirecting malloc into mimalloc underneath ASan's own interception mixes
235240
# two allocators on the same pointers. Windows keeps its wrap flags everywhere,
236241
# because there the shim is what makes mimalloc own the allocations at all.
237-
LDFLAGS = $(HARDEN_LDFLAGS) -lm -lstdc++ -lpthread -lz $(WIN32_LIBS) $(STATIC_FLAGS) $(MIMALLOC_WRAP_FLAGS)
238-
LDFLAGS_TEST = -lm -lstdc++ -lpthread -lz $(SANITIZE) $(WIN32_LIBS) $(MIMALLOC_WRAP_FLAGS)
239-
LDFLAGS_TSAN = -lm -lstdc++ -lpthread -lz $(TSAN_SANITIZE) $(WIN32_LIBS) $(MIMALLOC_WRAP_FLAGS)
242+
LDFLAGS = $(HARDEN_LDFLAGS) -lm -lstdc++ -lpthread -lz $(WIN32_LIBS) $(EXECINFO_LIBS) $(STATIC_FLAGS) $(MIMALLOC_WRAP_FLAGS) $(MIMALLOC_WRAP_FLAGS_POSIX)
243+
LDFLAGS_TEST = -lm -lstdc++ -lpthread -lz $(EXECINFO_LIBS) $(SANITIZE) $(WIN32_LIBS) $(MIMALLOC_WRAP_FLAGS)
244+
LDFLAGS_TSAN = -lm -lstdc++ -lpthread -lz $(EXECINFO_LIBS) $(TSAN_SANITIZE) $(WIN32_LIBS) $(MIMALLOC_WRAP_FLAGS)
240245

241246
# ── Source files ─────────────────────────────────────────────────
242247

243248
FOUNDATION_SRCS = \
244249
src/foundation/mem_override_win.c \
250+
src/foundation/mem_override_posix.c \
251+
src/foundation/mem_profile.c \
245252
src/foundation/arena.c \
246253
src/foundation/hash_table.c \
247254
src/foundation/str_intern.c \
@@ -430,7 +437,7 @@ UI_SRCS = \
430437
# mimalloc (vendored, global allocator override)
431438
#
432439
# Override strategy is platform-specific:
433-
# * Unix (macOS/Linux): rely on static-link-order override — the prod mimalloc
440+
# * Unix (macOS/Linux/FreeBSD): rely on static-link-order override — the prod mimalloc
434441
# object is linked first so its strong malloc/free symbols win. We do NOT
435442
# define MI_MALLOC_OVERRIDE here: that would compile alloc-override.c's
436443
# forwarding definitions (malloc/free/posix_memalign/...) which, on macOS's

0 commit comments

Comments
 (0)