commit 3aa3d09131f904760208dd4dd980c51d3018e16e
parent a5103b3d75e0cd738d7ad2c59311c9218b3e083d
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Thu, 17 Sep 2026 07:31:21 -0400
build: run debug and test targets under AddressSanitizer
The debug allocator's poisoning only pays off when the program is
instrumented, so debug and test builds now pass -sanitize:address. The SAN
variable lets a build drop it when a third-party library misbehaves under
the sanitizer.
Diffstat:
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,11 +1,15 @@
# sonar build
#
-# make debug build -> build/debug/sonar.exe
-# make release optimised build -> build/release/sonar.exe
-# make test run the ntfs tests -> build/test/ntfs.exe
+# make debug build with AddressSanitizer -> build/debug/sonar.exe
+# make release optimised build -> build/release/sonar.exe
+# make test run the ntfs tests under ASan -> build/test/ntfs.exe
# make check type-check both modes without producing a binary
# make clean remove build/
#
+# Debug and test builds carry -sanitize:address. The debug allocator poisons its
+# guard bytes and freed blocks, so instrumented reads past the end or after free trap
+# at the faulting instruction. Pass SAN= to build without it (e.g. make debug SAN=).
+#
# GNU Make runs recipes through sh even on Windows (scoop's make finds sh.exe), so
# the recipes use POSIX commands. Odin does not create output directories, hence the
# order-only directory prerequisites.
@@ -13,6 +17,7 @@
ODIN ?= odin
BUILD := build
FLAGS := -vet -strict-style
+SAN ?= -sanitize:address
EXE := $(if $(filter Windows_NT,$(OS)),.exe,)
SRC := $(wildcard *.odin) $(wildcard ntfs/*.odin) $(wildcard debug/*.odin)
@@ -26,13 +31,13 @@ debug: $(BUILD)/debug/sonar$(EXE)
release: $(BUILD)/release/sonar$(EXE)
$(BUILD)/debug/sonar$(EXE): $(SRC) | $(BUILD)/debug
- $(ODIN) build . -debug $(FLAGS) -out:$@
+ $(ODIN) build . -debug $(SAN) $(FLAGS) -out:$@
$(BUILD)/release/sonar$(EXE): $(SRC) | $(BUILD)/release
$(ODIN) build . -o:speed $(FLAGS) -out:$@
test: | $(BUILD)/test
- $(ODIN) test ntfs $(FLAGS) -out:$(BUILD)/test/ntfs$(EXE)
+ $(ODIN) test ntfs -debug $(SAN) $(FLAGS) -out:$(BUILD)/test/ntfs$(EXE)
check:
$(ODIN) check . $(FLAGS)