Skip to content

Commit 757e987

Browse files
committed
Merge branch 'jk/build-with-asan'
The build procedure has been improved to allow building and testing Git with address sanitizer more easily. * jk/build-with-asan: Makefile: disable unaligned loads with UBSan Makefile: turn off -fomit-frame-pointer with sanitizers Makefile: add helper for compiling with -fsanitize test-lib: turn on ASan abort_on_error by default test-lib: set ASAN_OPTIONS variable before we run git
2 parents c9c63ee + 566cf0b commit 757e987

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,14 @@ ifdef DEVELOPER
10221022
CFLAGS += $(DEVELOPER_CFLAGS)
10231023
endif
10241024

1025+
ifdef SANITIZE
1026+
BASIC_CFLAGS += -fsanitize=$(SANITIZE) -fno-sanitize-recover=$(SANITIZE)
1027+
BASIC_CFLAGS += -fno-omit-frame-pointer
1028+
ifeq ($(SANITIZE),undefined)
1029+
BASIC_CFLAGS += -DNO_UNALIGNED_LOADS
1030+
endif
1031+
endif
1032+
10251033
ifndef sysconfdir
10261034
ifeq ($(prefix),/usr)
10271035
sysconfdir = /etc

t/test-lib.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ then
3636
fi
3737
GIT_BUILD_DIR="$TEST_DIRECTORY"/..
3838

39+
# If we were built with ASAN, it may complain about leaks
40+
# of program-lifetime variables. Disable it by default to lower
41+
# the noise level. This needs to happen at the start of the script,
42+
# before we even do our "did we build git yet" check (since we don't
43+
# want that one to complain to stderr).
44+
: ${ASAN_OPTIONS=detect_leaks=0:abort_on_error=1}
45+
export ASAN_OPTIONS
46+
3947
################################################################
4048
# It appears that people try to run tests without building...
4149
"$GIT_BUILD_DIR/git" >/dev/null
@@ -148,9 +156,6 @@ else
148156
}
149157
fi
150158

151-
: ${ASAN_OPTIONS=detect_leaks=0}
152-
export ASAN_OPTIONS
153-
154159
# Protect ourselves from common misconfiguration to export
155160
# CDPATH into the environment
156161
unset CDPATH

0 commit comments

Comments
 (0)