Factor out the common code in lookup_{static,global}_symbol
[external/binutils.git] / gdb / sanitize.m4
1 dnl Sanitization-related configure macro for GDB
2 dnl Copyright (C) 2018-2019 Free Software Foundation, Inc.
3 dnl
4 dnl This file is part of GDB.
5 dnl
6 dnl This program is free software; you can redistribute it and/or modify
7 dnl it under the terms of the GNU General Public License as published by
8 dnl the Free Software Foundation; either version 3 of the License, or
9 dnl (at your option) any later version.
10 dnl
11 dnl This program is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 dnl GNU General Public License for more details.
15 dnl
16 dnl You should have received a copy of the GNU General Public License
17 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 AC_DEFUN([AM_GDB_UBSAN],[
20 AC_ARG_ENABLE(ubsan,
21   AS_HELP_STRING([--enable-ubsan],
22                  [enable undefined behavior sanitizer (auto/yes/no)]),
23   [],enable_ubsan=no)
24 if test "x$enable_ubsan" = xauto; then
25   if $development; then
26     enable_ubsan=yes
27   fi
28 fi
29 AC_LANG_PUSH([C++])
30 if test "x$enable_ubsan" = xyes; then
31   AC_MSG_CHECKING(whether -fsanitize=undefined is accepted)
32   saved_CXXFLAGS="$CXXFLAGS"
33   CXXFLAGS="$CXXFLAGS -fsanitize=undefined -fno-sanitize-recover=undefined"
34   dnl A link check is required because it is possible to install gcc
35   dnl without libubsan, leading to link failures when compiling with
36   dnl -fsanitize=undefined.
37   AC_TRY_LINK([],[],enable_ubsan=yes,enable_ubsan=no)
38   CXXFLAGS="$saved_CXXFLAGS"
39   AC_MSG_RESULT($enable_ubsan)
40   if test "x$enable_ubsan" = xyes; then
41     WARN_CFLAGS="$WARN_CFLAGS -fsanitize=undefined -fno-sanitize-recover=undefined"
42     CONFIG_LDFLAGS="$CONFIG_LDFLAGS -fsanitize=undefined"
43   fi
44 fi
45 AC_LANG_POP([C++])
46 ])