2014-11-04 09:58:40 +00:00
|
|
|
#!/bin/sh
|
2018-03-14 02:08:29 +00:00
|
|
|
# ASAN="address leak memory undefined"
|
|
|
|
ASAN=${ASAN:="address"}
|
2015-09-02 14:01:53 +00:00
|
|
|
|
2015-10-23 01:23:12 +00:00
|
|
|
printf "\033[32m"
|
2015-09-02 14:01:53 +00:00
|
|
|
echo "========================================================================="
|
2015-10-23 01:23:12 +00:00
|
|
|
printf "\033[33m"
|
2015-09-02 14:01:53 +00:00
|
|
|
echo "ASAN build script can be configured with the ASAN environment variable."
|
|
|
|
echo "Use one of the following words to specify which build flags to use:"
|
|
|
|
echo " - address - set by default, detect overflows"
|
|
|
|
echo " - leak - find memory leaks"
|
|
|
|
echo " - memory - detect uninitialized reads"
|
|
|
|
echo " - undefined - undefined behaviour"
|
|
|
|
echo " - ..."
|
|
|
|
echo "For more information:"
|
|
|
|
echo " http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation"
|
|
|
|
echo "For example:"
|
|
|
|
echo " $ ASAN='leak memory address' sys/asan.sh"
|
|
|
|
echo "Current value:"
|
|
|
|
echo " ASAN=${ASAN}"
|
2015-10-23 01:23:12 +00:00
|
|
|
printf "\033[32m"
|
2015-09-02 14:01:53 +00:00
|
|
|
echo "========================================================================="
|
2015-10-23 01:23:12 +00:00
|
|
|
printf "\033[0m"
|
2015-09-02 14:01:53 +00:00
|
|
|
sleep 1
|
|
|
|
|
|
|
|
for a in $ASAN ; do
|
|
|
|
export CFLAGS="${CFLAGS} -fsanitize=$a"
|
|
|
|
done
|
2017-12-18 11:35:48 +00:00
|
|
|
if [ "`uname`" != Darwin ]; then
|
|
|
|
export CFLAGS="${CFLAGS} -lasan"
|
|
|
|
export LDFLAGS="-lasan"
|
|
|
|
fi
|
2015-09-02 14:01:53 +00:00
|
|
|
|
2014-11-06 21:30:24 +00:00
|
|
|
echo 'int main(){return 0;}' > .a.c
|
|
|
|
[ -z "${CC}" ] && CC=gcc
|
|
|
|
${CC} ${CFLAGS} ${LDFLAGS} -o .a.out .a.c
|
|
|
|
RET=$?
|
2014-11-17 11:27:35 +00:00
|
|
|
rm -f .a.out .a.c
|
2015-09-02 14:01:53 +00:00
|
|
|
if [ "$RET" != 0 ]; then
|
2015-05-06 21:24:29 +00:00
|
|
|
echo "Your compiler doesn't support ASAN."
|
2014-11-06 21:30:24 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2015-04-29 08:41:18 +00:00
|
|
|
exec sys/install.sh $*
|