Skip to content

Commit

Permalink
Limit the default setup sanitizer to x86_64
Browse files Browse the repository at this point in the history
  • Loading branch information
michalbiesek committed Jul 19, 2023
1 parent 8c0d1b4 commit 6eb81af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
24 changes: 22 additions & 2 deletions os/linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ SCOPE_VER:="$(shell git --no-pager describe --abbrev=12 --dirty=+ --always --tag
LIBRARY_CFLAGS=-fPIC -g -Wall -Wno-nonnull -Wno-deprecated-declarations -Werror=implicit-function-declaration -Werror=override-init -Wstrict-prototypes -I contrib/ls-hpack $(if $(DEBUG),-DDEBUG) -DSCOPE_VER=\"$(SCOPE_VER)\"
LOADER_CFLAGS=-fPIC -g -Wall -Wno-nonnull -Wno-deprecated-declarations -Werror=implicit-function-declaration -Werror=override-init -Wno-format-security -Wno-format-truncation -Wstrict-prototypes -I contrib/ls-hpack $(if $(DEBUG),-DDEBUG) -DSCOPE_VER=\"$(SCOPE_VER)\"
TEST_CFLAGS=-g -Wall -Wno-nonnull -O0 -coverage -Wno-format-security -Wno-format-truncation -DSCOPE_VER=\"$(SCOPE_VER)\"
TEST_FSAN_CFLAGS=-fsanitize=address
YAML_DEFINES=-DYAML_VERSION_MAJOR="0" -DYAML_VERSION_MINOR="2" -DYAML_VERSION_PATCH="2" -DYAML_VERSION_STRING="\"0.2.2\""
CJSON_DEFINES=-DENABLE_LOCALES
YAML_SRC=$(wildcard contrib/libyaml/src/*.c)
Expand All @@ -24,7 +23,6 @@ TEST_AR=$(MUSL_AR) ${COREDUMPER_AR} ${UNWIND_AR} $(YAML_AR) $(JSON_AR) $(PCRE2_A
#TEST_LIB=contrib/build/cmocka/src/libcmocka.dylib
TEST_LIB=contrib/build/cmocka/src/libcmocka.so
TEST_LD_FLAGS=-Lcontrib/build/cmocka/src -lcmocka -ldl -lresolv -lrt -lpthread -lz
TEST_FSAN_LD_FLAGS=-Wl,--wrap=scopelibc_malloc -Wl,--wrap=scopelibc_free -Wl,--wrap=scopelibc_calloc -Wl,--wrap=scopelibc_realloc
LIBRARY_INCLUDES=-I./src
LOADER_INCLUDES=-I./src/loader
CMOCKA_INCLUDES=-I./contrib/cmocka/include -I contrib/ls-hpack
Expand All @@ -43,6 +41,24 @@ LIBSCOPE=lib/$(OS)/$(ARCH)/libscope.so
LIBLOADER=lib/$(OS)/$(ARCH)/libloader.a
SCOPEDYN=bin/$(OS)/$(ARCH)/scopedyn

# Currently we enable the address sanitizer by default on x86_64
# TODO: enable it on aarch64 as well
# in the gcc version > 9 we observe unexpected behavior regarding address sanitizer
#
ifeq ($(ARCH),x86_64)
FSAN=true
else
FSAN?=false
endif

ifeq ($(FSAN),true)
TEST_FSAN_CFLAGS=-fsanitize=address
TEST_FSAN_LD_FLAGS=-Wl,--wrap=scopelibc_malloc -Wl,--wrap=scopelibc_free -Wl,--wrap=scopelibc_calloc -Wl,--wrap=scopelibc_realloc
else
TEST_FSAN_CFLAGS=""
TEST_FSAN_LD_FLAGS=""
endif

include os/linux/$(ARCH).mk


Expand Down Expand Up @@ -99,7 +115,11 @@ $(SCOPEDYN): src/loader/scopedyn.c src/loader/attach.c src/loader/loaderutils.c

########## Tests ##########
libtestfsan: $(LIBRARY_C_FILES) $(LIBRARY_TEST_C_FILES) $(YAML_AR) $(JSON_AR) $(TEST_LIB)
ifeq ($(FSAN),true)
@echo "$${CI:+::group::}Building Library Tests with memory sanitizer"
else
@echo "$${CI:+::group::}Building Library Tests without memory sanitizer"
endif
$(CC) -c $(TEST_CFLAGS) $(TEST_FSAN_CFLAGS) $(LIBRARY_C_FILES) $(LIBRARY_INCLUDES) $(LIBRARY_TEST_C_FILES) $(INCLUDES) $(CMOCKA_INCLUDES) $(OS_C_FILES)
$(CC) $(TEST_CFLAGS) $(TEST_FSAN_CFLAGS) -o test/$(OS)/vdsotest vdsotest.o scopestdlib.o dbg.o test.o $(TEST_AR) $(TEST_LD_FLAGS) $(TEST_FSAN_LD_FLAGS)
$(CC) $(TEST_CFLAGS) $(TEST_FSAN_CFLAGS) -o test/$(OS)/ipctest ipctest.o ipc.o ipc_resp.o cfgutils.o cfg.o mtc.o log.o evtformat.o ctl.o transport.o backoff.o mtcformat.o strset.o com.o scopestdlib.o dbg.o circbuf.o linklist.o fn.o utils.o os.o test.o report.o evtutils.o strsearch.o httpagg.o httpmatch.o state.o httpstate.o metriccapture.o plattime.o scopeelf.o $(TEST_AR) $(TEST_LD_FLAGS) $(TEST_FSAN_LD_FLAGS) -Wl,--wrap=jsonConfigurationObject -Wl,--wrap=doAndReplaceConfig
Expand Down
9 changes: 8 additions & 1 deletion test/unit/library/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
* Following part of code is required to use memory sanitizers during unit tests
* To correct instrument code we redirect allocations from our internal
* library to allocator from standard library.
* See details in:
* The instrumentation is enabled by default on x86_64.
*
* make FSAN=1 libtest
*
* Allows to instrumentation ona aarch64
*
See details in:
* https://github.com/google/sanitizers/wiki/AddressSanitizerIncompatiblity
*
*
* The memory leak instrumentation is done by "-fsanitize=address"
*/

Expand Down

0 comments on commit 6eb81af

Please sign in to comment.