From 15844a12f91182a0dc193824f32a2c32410fe2c6 Mon Sep 17 00:00:00 2001 From: Jaromil Date: Fri, 4 Oct 2024 19:48:38 +0200 Subject: [PATCH] fix: new linux-asan target to debug memory leaks --- GNUmakefile | 16 +++++++++++++++- build/init.mk | 2 +- build/linux.mk | 8 +++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index bf3863b..7adcf84 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -17,6 +17,10 @@ help: @echo "โœจ Welcome to the CJIT build system" @awk 'BEGIN {FS = ":.*##"; printf "๐Ÿ›Ÿ Usage: make \033[36m\033[0m\n๐Ÿ‘‡ List of targets:\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5)} ' GNUmakefile + +_: ## +------: ## __ Production targets + musl-linux: ## ๐Ÿ—ฟ Build a fully static cjit using musl-libc on Linux $(MAKE) -f build/musl.mk @@ -26,10 +30,20 @@ linux-x86: ## ๐Ÿง Build a dynamically linked cjit using libs found on Linux x86 win-wsl: ## ๐ŸชŸ Build cjit.exe for WIN64 on an Ubuntu WSL VM using gcc-mingw-w64 $(MAKE) -f build/win-wsl.mk -check: ## ๐Ÿ”ฌ Run all tests with the currently built target +_: ## +------: ## __ Debugging targets + +linux-asan: ## ๐Ÿ”ฌ Build using the address sanitizer to detect memory leaks + $(MAKE) -f build/linux.mk ASAN=1 + +_: ## +------: ## __ Testing targets + +check: ## ๐Ÿงช Run all tests using the currently built binary ./cjit $(if $(wildcard ./cjit),,$(error CJIT is not yet built)) ./cjit test/hello.c +_: ## clean: ## ๐Ÿงน Clean the source from all built objects $(MAKE) -f build/deps.mk clean @rm -f cjit diff --git a/build/init.mk b/build/init.mk index 599c5f0..7006fc4 100644 --- a/build/init.mk +++ b/build/init.mk @@ -28,7 +28,7 @@ ldadd := lib/tinycc/libtcc.a embed_libtcc1 := lib/tinycc/libtcc1.a -tinycc_config ?= --cc=${cc} --extra-cflags="${cflags}" +tinycc_config ?= --cc=${cc} --extra-cflags="${cflags}" --extra-ldflags="${ldflags}" ifdef DEBUG tinycc_config += --debug endif diff --git a/build/linux.mk b/build/linux.mk index d065e9c..2a6b9f8 100644 --- a/build/linux.mk +++ b/build/linux.mk @@ -4,10 +4,16 @@ cc := gcc cflags += -DLIBC_GNU -D_GNU_SOURCE -DREPL_SUPPORTED ldadd+=lib/tinycc/libtcc.a +ifdef ASAN + cflags += -O0 -ggdb -DDEBUG=1 -fno-omit-frame-pointer -fsanitize=address + ldflags += -fsanitize=address +# tinycc_config += --extra-ldflags="${ldflags}" +endif + all: deps cjit cjit: ${SOURCES} - $(cc) $(cflags) -o $@ $(SOURCES) ${ldadd} + $(cc) $(cflags) -o $@ $(SOURCES) ${ldflags} ${ldadd} deps: lib/tinycc/libtcc.a