summaryrefslogtreecommitdiff
path: root/configure.ac
diff options
context:
space:
mode:
authorIlya Leoshkevich <iii@linux.ibm.com>2023-02-13 17:45:51 +0100
committerMark Wielaard <mark@klomp.org>2023-02-14 15:19:31 +0100
commit3fa98a6f29b0f370e32549ead7eb897c839af980 (patch)
treec82118e31596700bb899928349908c365e15bd11 /configure.ac
parenta4fafb7722c9950dacd5689f1ce8e31f8fa94ed5 (diff)
downloadelfutils-3fa98a6f29b0f370e32549ead7eb897c839af980.tar.gz
configure: Add --enable-sanitize-memory
Add support for clang Memory Sanitizer [1], which detects the usage of uninitialized values. While elfutils itself is already checked with valgrind, checking code that depends on elfutils requires elfutils to be built with MSan. MSan is not linked into shared libraries, and is linked into executables statically. Therefore, unlike the other sanitizers, MSan needs to be configured fairly early, since we need to drop -D_FORTIFY_SOURCE [2], -Wl,-z,defs and --no-undefined. Disable a few tests that run for more than 5 minutes due to test files being statically linked with MSan. [1] https://clang.llvm.org/docs/MemorySanitizer.html [2] https://github.com/google/sanitizers/issues/247 Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac24
1 files changed, 24 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 4efb2a9c..18951947 100644
--- a/configure.ac
+++ b/configure.ac
@@ -155,6 +155,29 @@ AC_SUBST([fpie_CFLAGS])
dso_LDFLAGS="-shared"
+NO_UNDEFINED=-Wl,--no-undefined
+AC_ARG_ENABLE([sanitize-memory],
+ AS_HELP_STRING([--enable-sanitize-memory],
+ [Use clang memory sanitizer]),
+ [use_msan=$enableval], [use_msan=no])
+if test "$use_msan" = yes; then
+ old_CFLAGS="$CFLAGS"
+ old_CXXFLAGS="$CXXFLAGS"
+ old_LDFLAGS="$LDFLAGS"
+ # -fsanitize=memory is not compatible with -D_FORTIFY_SOURCE, -Wl,-z,defs and --no-undefined
+ CFLAGS="$CFLAGS -fsanitize=memory -fsanitize-memory-track-origins -D_FORTIFY_SOURCE=0"
+ CXXFLAGS="$CXXFLAGS -fsanitize=memory -fsanitize-memory-track-origins -D_FORTIFY_SOURCE=0"
+ LDFLAGS="-shared"
+ AC_LINK_IFELSE([AC_LANG_SOURCE([int main (int argc, char **argv) { return 0; }])], use_msan=yes, use_msan=no)
+ AS_IF([test "x$use_msan" == xyes],
+ ac_cv_zdefs=no NO_UNDEFINED=,
+ AC_MSG_WARN([clang memory sanitizer not available])
+ CFLAGS="$old_CFLAGS" CXXFLAGS="$old_CXXFLAGS")
+ LDFLAGS="$old_LDFLAGS"
+fi
+AC_SUBST(NO_UNDEFINED)
+AM_CONDITIONAL(USE_MEMORY_SANITIZER, test "$use_msan" = yes)
+
ZDEFS_LDFLAGS="-Wl,-z,defs"
AC_CACHE_CHECK([whether gcc supports $ZDEFS_LDFLAGS], ac_cv_zdefs, [dnl
save_LDFLAGS="$LDFLAGS"
@@ -894,6 +917,7 @@ AC_MSG_NOTICE([
run all tests under valgrind : ${use_valgrind}
gcc undefined behaviour sanitizer : ${use_undefined}
gcc address sanitizer : ${use_address}
+ clang memory sanitizer : ${use_msan}
use rpath in tests : ${tests_use_rpath}
test biarch : ${utrace_cv_cc_biarch}
])