Skip to content

Commit

Permalink
fix: new linux-asan target to debug memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jaromil committed Oct 4, 2024
1 parent e26229a commit 15844a1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
16 changes: 15 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ help:
@echo "✨ Welcome to the CJIT build system"
@awk 'BEGIN {FS = ":.*##"; printf "🛟 Usage: make \033[36m<target>\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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build/init.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion build/linux.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 15844a1

Please sign in to comment.