Add --enable-ubsan

This adds --enable-ubsan to gdb's configure.  By default it is enabled
in development mode, and disabled otherwise.  This passes both
-fsanitize=undefined and -fno-sanitize-recover=undefined to
compilations, so that undefined behavior violations will be sure to
cause test failures.

gdb/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

	* README: Mention --enable-ubsan.
	* NEWS: Mention --enable-ubsan.
	* acinclude.m4: Include sanitize.m4.
	* configure: Rebuild.
	* configure.ac: Call AM_GDB_UBSAN.
	* sanitize.m4: New file.

gdb/doc/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (Configure Options): Document --enable-ubsan.
This commit is contained in:
Tom Tromey
2018-08-18 15:32:46 -06:00
parent 1dffa580e7
commit f35d5adea1
9 changed files with 193 additions and 0 deletions

105
gdb/configure vendored
View File

@@ -886,6 +886,7 @@ with_system_gdbinit
enable_werror
enable_build_warnings
enable_gdb_build_warnings
enable_ubsan
with_lzma
with_liblzma_prefix
with_tcl
@@ -1556,6 +1557,7 @@ Optional Features:
--enable-gdb-build-warnings
enable GDB specific build-time compiler warnings if
gcc is used
--enable-ubsan enable undefined behavior sanitizer (auto/yes/no)
--enable-sim link gdb with simulator
--enable-gdbserver automatically build gdbserver (yes/no/auto, default
is auto)
@@ -2448,6 +2450,52 @@ $as_echo "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
} # ac_fn_c_check_decl
# ac_fn_cxx_try_link LINENO
# -------------------------
# Try to link conftest.$ac_ext, and return whether this succeeded.
ac_fn_cxx_try_link ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
rm -f conftest.$ac_objext conftest$ac_exeext
if { { ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_link") 2>conftest.err
ac_status=$?
if test -s conftest.err; then
grep -v '^ *+' conftest.err >conftest.er1
cat conftest.er1 >&5
mv -f conftest.er1 conftest.err
fi
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; } && {
test -z "$ac_cxx_werror_flag" ||
test ! -s conftest.err
} && test -s conftest$ac_exeext && {
test "$cross_compiling" = yes ||
test -x conftest$ac_exeext
}; then :
ac_retval=0
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_retval=1
fi
# Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
# created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
# interfere with the next link command; also delete a directory that is
# left behind by Apple's compiler. We do this before executing the actions.
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
as_fn_set_status $ac_retval
} # ac_fn_cxx_try_link
cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
@@ -15561,6 +15609,63 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
# Check whether --enable-ubsan was given.
if test "${enable_ubsan+set}" = set; then :
enableval=$enable_ubsan;
else
enable_ubsan=auto
fi
if test "x$enable_ubsan" = xauto; then
if $development; then
enable_ubsan=yes
fi
fi
ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
if test "x$enable_ubsan" = xyes; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -fsanitize=undefined is accepted" >&5
$as_echo_n "checking whether -fsanitize=undefined is accepted... " >&6; }
saved_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -fsanitize=undefined -fno-sanitize-recover=undefined"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_link "$LINENO"; then :
enable_ubsan=yes
else
enable_ubsan=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
CXXFLAGS="$saved_CXXFLAGS"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_ubsan" >&5
$as_echo "$enable_ubsan" >&6; }
if test "x$enable_ubsan" = xyes; then
WARN_CFLAGS="$WARN_CFLAGS -fsanitize=undefined -fno-sanitize-recover=undefined"
CONFIG_LDFLAGS="$CONFIG_LDFLAGS -fsanitize=undefined"
fi
fi
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
# In the Cygwin environment, we need some additional flags.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for cygwin" >&5
$as_echo_n "checking for cygwin... " >&6; }