From c6df8cc4f7cdbff2bf86d40be3ee1e9daae6c9b6 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sun, 17 Apr 2022 16:33:39 +0100 Subject: 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 --- tools/configure | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/configure b/tools/configure index ac657e38c9..12b45bf890 100755 --- a/tools/configure +++ b/tools/configure @@ -270,6 +270,12 @@ simcc () { LDOPTS="$LDOPTS -fsanitize=address -lasan" 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, # but cleaning this up is a lot of work. GCCOPTS="$GCCOPTS -Wno-unused-result" @@ -479,6 +485,9 @@ EOF if [ "$ARG_ADDR_SAN" = "1" ] ; then ARG_THREAD_SUPPORT=1 fi + if [ "$ARG_UBSAN" = "1" ] ; then + ARG_THREAD_SUPPORT=1 + fi thread_support= if [ -z "$ARG_THREAD_SUPPORT" ] || [ "$ARG_THREAD_SUPPORT" = "0" ]; then @@ -1429,6 +1438,7 @@ ARG_PREFIX="$PREFIX" ARG_THREAD_SUPPORT= ARG_32BIT= ARG_ADDR_SAN= +ARG_UBSAN= err= for arg in "$@"; do case "$arg" in @@ -1452,6 +1462,7 @@ for arg in "$@"; do --no-sdl-threads) ARG_THREAD_SUPPORT=0;; --with-address-sanitizer) ARG_ADDR_SAN=1;; + --with-ubsan) ARG_UBSAN=1;; --prefix=*) ARG_PREFIX=`echo "$arg" | cut -d = -f 2`;; --compiler-prefix=*) ARG_COMPILER_PREFIX=`echo "$arg" | cut -d = -f 2`;; --help) help;; -- cgit v1.2.3