|
9 | 9 |
|
10 | 10 | # Compiler selection — override via: make CC=gcc CXX=g++ |
11 | 11 | # 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 |
13 | 13 | # CI scripts pass CC/CXX explicitly; don't rely on defaults here |
14 | 14 |
|
15 | 15 | # Target architecture (macOS): build.sh/test.sh export ARCHFLAGS="-arch <arch>" |
16 | 16 | # (see scripts/env.sh). Fold it into the compiler drivers with `override` so it |
17 | 17 | # reaches EVERY compile and link recipe — including the vendored objects below |
18 | 18 | # 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, |
20 | 20 | # leaving CC/CXX unchanged there. |
21 | 21 | override CC := $(CC) $(ARCHFLAGS) |
22 | 22 | override CXX := $(CXX) $(ARCHFLAGS) |
@@ -109,19 +109,24 @@ MIMALLOC_WRAP_FLAGS := |
109 | 109 | ifeq ($(IS_MINGW),yes) |
110 | 110 | MIMALLOC_WRAP_FLAGS := $(foreach sym,$(MIMALLOC_WRAP_SYMS),-Wl,--wrap=$(sym)) |
111 | 111 | 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): |
113 | 113 | # allocations already reach mimalloc here, but the profiler needs the same |
114 | 114 | # observation point as Windows or the platform comparison is not like-for-like. |
115 | 115 | # 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) |
117 | 117 | MIMALLOC_WRAP_SYMS_POSIX := malloc calloc realloc free strdup |
118 | 118 | MIMALLOC_WRAP_FLAGS_POSIX := |
119 | | -ifeq ($(IS_LINUX),yes) |
| 119 | +ifeq ($(IS_POSIX_WRAP),yes) |
120 | 120 | MIMALLOC_WRAP_FLAGS_POSIX := $(foreach sym,$(MIMALLOC_WRAP_SYMS_POSIX),-Wl,--wrap=$(sym)) |
121 | 121 | endif |
122 | 122 | ifeq ($(IS_MINGW),yes) |
123 | 123 | WIN32_LIBS := -lws2_32 -lpsapi -lshell32 -ladvapi32 -Wl,--allow-multiple-definition -Wl,--stack,8388608 -static |
124 | 124 | 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 |
125 | 130 |
|
126 | 131 | # STATIC=1 produces a fully static binary (for Alpine/musl portable builds) |
127 | 132 | ifeq ($(STATIC),1) |
@@ -230,18 +235,20 @@ endif # ELF_BUILD |
230 | 235 | endif # PRODUCTION_HARDENING |
231 | 236 |
|
232 | 237 | # 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, |
234 | 239 | # and redirecting malloc into mimalloc underneath ASan's own interception mixes |
235 | 240 | # two allocators on the same pointers. Windows keeps its wrap flags everywhere, |
236 | 241 | # 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) |
240 | 245 |
|
241 | 246 | # ── Source files ───────────────────────────────────────────────── |
242 | 247 |
|
243 | 248 | FOUNDATION_SRCS = \ |
244 | 249 | src/foundation/mem_override_win.c \ |
| 250 | + src/foundation/mem_override_posix.c \ |
| 251 | + src/foundation/mem_profile.c \ |
245 | 252 | src/foundation/arena.c \ |
246 | 253 | src/foundation/hash_table.c \ |
247 | 254 | src/foundation/str_intern.c \ |
@@ -430,7 +437,7 @@ UI_SRCS = \ |
430 | 437 | # mimalloc (vendored, global allocator override) |
431 | 438 | # |
432 | 439 | # 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 |
434 | 441 | # object is linked first so its strong malloc/free symbols win. We do NOT |
435 | 442 | # define MI_MALLOC_OVERRIDE here: that would compile alloc-override.c's |
436 | 443 | # forwarding definitions (malloc/free/posix_memalign/...) which, on macOS's |
|
0 commit comments