2014-11-04 17:58:40 +08:00
|
|
|
#!/bin/sh
|
2019-11-05 07:33:35 +08:00
|
|
|
# SANITIZE="address leak memory undefined"
|
|
|
|
# SANITIZE="address signed-integer-overflow" # Faster build
|
2022-01-22 00:03:59 +08:00
|
|
|
# default:
|
2022-02-08 04:11:49 +08:00
|
|
|
SANITIZE=${SANITIZE:="address undefined signed-integer-overflow"}
|
|
|
|
# SANITIZE=${SANITIZE:="thread"}
|
2015-09-02 22:01:53 +08:00
|
|
|
|
2015-10-23 09:23:12 +08:00
|
|
|
printf "\033[32m"
|
2015-09-02 22:01:53 +08:00
|
|
|
echo "========================================================================="
|
2015-10-23 09:23:12 +08:00
|
|
|
printf "\033[33m"
|
2019-11-05 07:33:35 +08:00
|
|
|
echo "Sanitize build script can be configured with the SANITIZE environment variable."
|
|
|
|
echo "Use one of the following words to specify which sanitizers to use:"
|
|
|
|
echo " - address - detect memory errors"
|
2021-04-20 08:28:42 +08:00
|
|
|
echo " - thread - detect thread racing issues"
|
2015-09-02 22:01:53 +08:00
|
|
|
echo " - leak - find memory leaks"
|
|
|
|
echo " - memory - detect uninitialized reads"
|
2019-11-05 07:33:35 +08:00
|
|
|
echo " - undefined - find undefined behaviour"
|
2015-09-02 22:01:53 +08:00
|
|
|
echo " - ..."
|
|
|
|
echo "For more information:"
|
|
|
|
echo " http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation"
|
|
|
|
echo "For example:"
|
2019-11-05 07:33:35 +08:00
|
|
|
echo " $ SANITIZE='leak memory address' sys/sanitize.sh"
|
2015-09-02 22:01:53 +08:00
|
|
|
echo "Current value:"
|
2019-11-05 07:33:35 +08:00
|
|
|
echo " SANITIZE=${SANITIZE}"
|
2015-10-23 09:23:12 +08:00
|
|
|
printf "\033[32m"
|
2015-09-02 22:01:53 +08:00
|
|
|
echo "========================================================================="
|
2015-10-23 09:23:12 +08:00
|
|
|
printf "\033[0m"
|
2015-09-02 22:01:53 +08:00
|
|
|
sleep 1
|
|
|
|
|
2021-01-13 17:23:21 +08:00
|
|
|
# memory leaks are detected by default, can only be disabled via env var
|
|
|
|
HAVE_LEAKS=1
|
2019-11-05 07:33:35 +08:00
|
|
|
for a in $SANITIZE ; do
|
2015-09-02 22:01:53 +08:00
|
|
|
export CFLAGS="${CFLAGS} -fsanitize=$a"
|
2021-01-13 17:23:21 +08:00
|
|
|
if [ "$a" = leak ]; then
|
|
|
|
HAVE_LEAKS=0
|
|
|
|
fi
|
2015-09-02 22:01:53 +08:00
|
|
|
done
|
2021-01-13 17:23:21 +08:00
|
|
|
if [ "${HAVE_LEAKS}" = 0 ]; then
|
|
|
|
export ASAN_OPTIONS=detect_leaks=0
|
|
|
|
fi
|
2017-12-18 19:35:48 +08:00
|
|
|
if [ "`uname`" != Darwin ]; then
|
2019-11-05 07:33:35 +08:00
|
|
|
for a in $SANITIZE ; do
|
2019-10-28 23:09:11 +08:00
|
|
|
export LDFLAGS="${LDFLAGS} -fsanitize=$a"
|
|
|
|
done
|
2017-12-18 19:35:48 +08:00
|
|
|
fi
|
2015-09-02 22:01:53 +08:00
|
|
|
|
2014-11-07 05:30:24 +08:00
|
|
|
echo 'int main(){return 0;}' > .a.c
|
|
|
|
[ -z "${CC}" ] && CC=gcc
|
|
|
|
${CC} ${CFLAGS} ${LDFLAGS} -o .a.out .a.c
|
|
|
|
RET=$?
|
2014-11-17 19:27:35 +08:00
|
|
|
rm -f .a.out .a.c
|
2015-09-02 22:01:53 +08:00
|
|
|
if [ "$RET" != 0 ]; then
|
2019-11-05 07:33:35 +08:00
|
|
|
echo "Your compiler doesn't support a sanitizer in SANITIZE."
|
2014-11-07 05:30:24 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
2018-09-22 16:50:34 +08:00
|
|
|
|
|
|
|
SCRIPT=install.sh
|
|
|
|
if [ "$1" = "-u" ]; then
|
|
|
|
shift
|
|
|
|
SCRIPT=user.sh
|
|
|
|
fi
|
2023-03-14 22:29:53 +08:00
|
|
|
exec sys/${SCRIPT} $* --with-check-level=0
|