tests: make SANITIZE=address imply TEST_NO_MALLOC_CHECK

As the address sanitizer checks for a superset of the issues detected
by setting MALLOC_CHECK_ (which tries to detect things like double
frees and off-by-one errors) there is no need to set the latter when
compiling with -fsanitize=address.

This fixes a regression introduced by 131b94a10a ("test-lib.sh: Use
GLIBC_TUNABLES instead of MALLOC_CHECK_ on glibc >= 2.34", 2022-03-04)
which causes all the tests to fail with the message

    ASan runtime does not come first in initial library list;
    you should either link runtime to your application or
    manually preload it with LD_PRELOAD.

when git is compiled with SANITIZE=address on systems with glibc >=
2.34. I have tested SANITIZE=leak and SANITIZE=undefined and they do
not suffer from this regression so the fix in this patch should be
sufficient.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Phillip Wood 2022-04-09 12:28:37 +00:00 коммит произвёл Junio C Hamano
Родитель baedc59543
Коммит 067109a5e7
2 изменённых файлов: 7 добавлений и 3 удалений

Просмотреть файл

@ -1221,8 +1221,9 @@ PTHREAD_CFLAGS =
SPARSE_FLAGS ?= -std=gnu99 SPARSE_FLAGS ?= -std=gnu99
SP_EXTRA_FLAGS = -Wno-universal-initializer SP_EXTRA_FLAGS = -Wno-universal-initializer
# For informing GIT-BUILD-OPTIONS of the SANITIZE=leak target # For informing GIT-BUILD-OPTIONS of the SANITIZE=leak,address targets
SANITIZE_LEAK = SANITIZE_LEAK =
SANITIZE_ADDRESS =
# For the 'coccicheck' target; setting SPATCH_BATCH_SIZE higher will # For the 'coccicheck' target; setting SPATCH_BATCH_SIZE higher will
# usually result in less CPU usage at the cost of higher peak memory. # usually result in less CPU usage at the cost of higher peak memory.
@ -1272,6 +1273,7 @@ SANITIZE_LEAK = YesCompiledWithIt
endif endif
ifneq ($(filter address,$(SANITIZERS)),) ifneq ($(filter address,$(SANITIZERS)),)
NO_REGEX = NeededForASAN NO_REGEX = NeededForASAN
SANITIZE_ADDRESS = YesCompiledWithIt
endif endif
endif endif
@ -2853,6 +2855,7 @@ GIT-BUILD-OPTIONS: FORCE
@echo PAGER_ENV=\''$(subst ','\'',$(subst ','\'',$(PAGER_ENV)))'\' >>$@+ @echo PAGER_ENV=\''$(subst ','\'',$(subst ','\'',$(PAGER_ENV)))'\' >>$@+
@echo DC_SHA1=\''$(subst ','\'',$(subst ','\'',$(DC_SHA1)))'\' >>$@+ @echo DC_SHA1=\''$(subst ','\'',$(subst ','\'',$(DC_SHA1)))'\' >>$@+
@echo SANITIZE_LEAK=\''$(subst ','\'',$(subst ','\'',$(SANITIZE_LEAK)))'\' >>$@+ @echo SANITIZE_LEAK=\''$(subst ','\'',$(subst ','\'',$(SANITIZE_LEAK)))'\' >>$@+
@echo SANITIZE_ADDRESS=\''$(subst ','\'',$(subst ','\'',$(SANITIZE_ADDRESS)))'\' >>$@+
@echo X=\'$(X)\' >>$@+ @echo X=\'$(X)\' >>$@+
ifdef TEST_OUTPUT_DIRECTORY ifdef TEST_OUTPUT_DIRECTORY
@echo TEST_OUTPUT_DIRECTORY=\''$(subst ','\'',$(subst ','\'',$(TEST_OUTPUT_DIRECTORY)))'\' >>$@+ @echo TEST_OUTPUT_DIRECTORY=\''$(subst ','\'',$(subst ','\'',$(TEST_OUTPUT_DIRECTORY)))'\' >>$@+

Просмотреть файл

@ -503,9 +503,10 @@ case $GIT_TEST_FSYNC in
;; ;;
esac esac
# Add libc MALLOC and MALLOC_PERTURB test # Add libc MALLOC and MALLOC_PERTURB test only if we are not executing
# only if we are not executing the test with valgrind # the test with valgrind and have not compiled with SANITIZE=address.
if test -n "$valgrind" || if test -n "$valgrind" ||
test -n "$SANITIZE_ADDRESS" ||
test -n "$TEST_NO_MALLOC_CHECK" test -n "$TEST_NO_MALLOC_CHECK"
then then
setup_malloc_check () { setup_malloc_check () {