configure: Add support for compiling the simulator with UBSan

By passing --with-ubsan to tools/configure, you can now build the
simulator with UBSan to catch undefined behavior at runtime.

Change-Id: I054cd46ca59587dd544efbd7bdf6d27a040a4891
This commit is contained in:
Aidan MacDonald 2022-04-17 16:33:39 +01:00
parent 6f5af8e53c
commit c6df8cc4f7

11
tools/configure vendored
View file

@ -270,6 +270,12 @@ simcc () {
LDOPTS="$LDOPTS -fsanitize=address -lasan" LDOPTS="$LDOPTS -fsanitize=address -lasan"
fi fi
if [ "$ARG_UBSAN" = "1" ] ; then
echo "Using UBSan"
GCCOPTS="$GCCOPTS -fsanitize=undefined -fPIC"
LDOPTS="$LDOPTS -fsanitize=undefined"
fi
# Some linux setups like to warn about unused results. They are correct, # Some linux setups like to warn about unused results. They are correct,
# but cleaning this up is a lot of work. # but cleaning this up is a lot of work.
GCCOPTS="$GCCOPTS -Wno-unused-result" GCCOPTS="$GCCOPTS -Wno-unused-result"
@ -479,6 +485,9 @@ EOF
if [ "$ARG_ADDR_SAN" = "1" ] ; then if [ "$ARG_ADDR_SAN" = "1" ] ; then
ARG_THREAD_SUPPORT=1 ARG_THREAD_SUPPORT=1
fi fi
if [ "$ARG_UBSAN" = "1" ] ; then
ARG_THREAD_SUPPORT=1
fi
thread_support= thread_support=
if [ -z "$ARG_THREAD_SUPPORT" ] || [ "$ARG_THREAD_SUPPORT" = "0" ]; then if [ -z "$ARG_THREAD_SUPPORT" ] || [ "$ARG_THREAD_SUPPORT" = "0" ]; then
@ -1429,6 +1438,7 @@ ARG_PREFIX="$PREFIX"
ARG_THREAD_SUPPORT= ARG_THREAD_SUPPORT=
ARG_32BIT= ARG_32BIT=
ARG_ADDR_SAN= ARG_ADDR_SAN=
ARG_UBSAN=
err= err=
for arg in "$@"; do for arg in "$@"; do
case "$arg" in case "$arg" in
@ -1452,6 +1462,7 @@ for arg in "$@"; do
--no-sdl-threads) --no-sdl-threads)
ARG_THREAD_SUPPORT=0;; ARG_THREAD_SUPPORT=0;;
--with-address-sanitizer) ARG_ADDR_SAN=1;; --with-address-sanitizer) ARG_ADDR_SAN=1;;
--with-ubsan) ARG_UBSAN=1;;
--prefix=*) ARG_PREFIX=`echo "$arg" | cut -d = -f 2`;; --prefix=*) ARG_PREFIX=`echo "$arg" | cut -d = -f 2`;;
--compiler-prefix=*) ARG_COMPILER_PREFIX=`echo "$arg" | cut -d = -f 2`;; --compiler-prefix=*) ARG_COMPILER_PREFIX=`echo "$arg" | cut -d = -f 2`;;
--help) help;; --help) help;;