]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
mmap: Avoid the sanitizer configure check failure
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 9 Apr 2024 13:39:21 +0000 (06:39 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 10 Apr 2024 10:57:02 +0000 (03:57 -0700)
When -fsanitize=address,undefined is used to build, the mmap configure
check failed with

=================================================================
==231796==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7cdd3d0defdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x5750c7f6d72b in main /home/alan/build/gas-san/all/bfd/conftest.c:239

Direct leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7cdd3d0defdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x5750c7f6d2e1 in main /home/alan/build/gas-san/all/bfd/conftest.c:190

SUMMARY: AddressSanitizer: 8192 byte(s) leaked in 2 allocation(s).

Define GCC_AC_FUNC_MMAP with export ASAN_OPTIONS=detect_leaks=0 to avoid
the sanitizer configure check failure.

config/

* mmap.m4 (GCC_AC_FUNC_MMAP): New.
* no-executables.m4 (AC_FUNC_MMAP): Renamed to GCC_AC_FUNC_MMAP.
Change AC_FUNC_MMAP to GCC_AC_FUNC_MMAP.

libiberty/

* Makefile.in (aclocal_deps): Add $(srcdir)/../config/mmap.m4.
* acinclude.m4: Change AC_FUNC_MMAP to GCC_AC_FUNC_MMAP.
* aclocal.m4: Regenerated.
* configure: Likewise.

zlib/

* acinclude.m4: Include ../config/mmap.m4.
* Makefile.in: Regenerated.
* configure: Likewise.

config/mmap.m4
config/no-executables.m4
libiberty/Makefile.in
libiberty/acinclude.m4
libiberty/aclocal.m4
libiberty/configure
zlib/Makefile.in
zlib/acinclude.m4
zlib/configure

index fba0d9d36573cf7ab725ae0267bd57720a211bb3..326b97b91f4f5d87ecdf3c1b0673f6ac88af877a 100644 (file)
@@ -95,3 +95,25 @@ if test $gcc_cv_func_mmap_anon = yes; then
            [Define if mmap with MAP_ANON(YMOUS) works.])
 fi
 ])
+
+dnl
+dnl Avoid the sanitizer run-time memory leak failure in the mmap configure
+dnl test.  This should be removed when autoconf with commit:
+dnl
+dnl commit 09b6e78d1592ce10fdc975025d699ee41444aa3f
+dnl Author: Paul Eggert <eggert@cs.ucla.edu>
+dnl Date:   Fri Feb 5 21:06:20 2016 -0800
+dnl Fix memory leak in AC_FUNC_MMAP
+dnl
+dnl * lib/autoconf/functions.m4 (AC_FUNC_MMAP): Fix memory leak
+dnl in test case, found by configuring with gcc -fsanitize=address.
+dnl
+dnl is in use.
+dnl
+AC_DEFUN([GCC_AC_FUNC_MMAP],
+  save_ASAN_OPTIONS="$ASAN_OPTIONS"
+  ASAN_OPTIONS=detect_leaks=0
+  export ASAN_OPTIONS
+  m4_defn([AC_FUNC_MMAP])
+  ASAN_OPTIONS="$save_ASAN_OPTIONS"
+)
index 6842f84fba3268bc20d4f1860f67ea9c4f6947b2..e8e2537bde5b42dfc252d35714b55420b5dfd22b 100644 (file)
@@ -49,14 +49,14 @@ m4_defn([AC_LINK_IFELSE]))
 
 dnl This is a shame.  We have to provide a default for some link tests,
 dnl similar to the default for run tests.
-m4_define([AC_FUNC_MMAP],
+m4_define([GCC_AC_FUNC_MMAP],
 if test x$gcc_no_link = xyes; then
   if test "x${ac_cv_func_mmap_fixed_mapped+set}" != xset; then
     ac_cv_func_mmap_fixed_mapped=no
   fi
 fi
 if test "x${ac_cv_func_mmap_fixed_mapped}" != xno; then
-  m4_defn([AC_FUNC_MMAP])
+  m4_defn([GCC_AC_FUNC_MMAP])
 fi)
 
 m4_divert_pop()dnl
index 85c4b6b6ef89b8fd9aca7a7e05bd38e39eb8de30..b77a41c781c9952662dc0f8b83d000500730faa8 100644 (file)
@@ -508,6 +508,7 @@ aclocal_deps = \
        $(srcdir)/../config/cet.m4 \
        $(srcdir)/../config/enable.m4 \
        $(srcdir)/../config/gcc-plugin.m4 \
+       $(srcdir)/../config/mmap.m4 \
        $(srcdir)/../config/no-executables.m4 \
        $(srcdir)/../config/override.m4 \
        $(srcdir)/../config/picflag.m4 \
index 9974dcd4ec54b56726ca25b147f37453fc1347b9..d08e31bc0b5cf23a6b30b714ba0b818b3e249b77 100644 (file)
@@ -19,7 +19,7 @@ dnl On some versions of SunOS4 at least, strncmp reads a word at a time
 dnl but erroneously reads past the end of strings.  This can cause
 dnl a SEGV in some cases.
 AC_DEFUN([libiberty_AC_FUNC_STRNCMP],
-[AC_REQUIRE([AC_FUNC_MMAP])
+[AC_REQUIRE([GCC_AC_FUNC_MMAP])
 AC_CACHE_CHECK([for working strncmp], ac_cv_func_strncmp_works,
 [AC_TRY_RUN([
 /* Test by Jim Wilson and Kaveh Ghazi.
index 364fb6bc3b46baf7453b611105b87baeefaa45e9..9678b0acabaf83b5e5407bd0f4c0f393175e913e 100644 (file)
@@ -17,6 +17,7 @@ m4_include([../config/cet.m4])
 m4_include([../config/enable.m4])
 m4_include([../config/gcc-plugin.m4])
 m4_include([../config/hwcaps.m4])
+m4_include([../config/mmap.m4])
 m4_include([../config/no-executables.m4])
 m4_include([../config/override.m4])
 m4_include([../config/picflag.m4])
index 5c69fee56c1075ec40be77d02734268af5bd333c..18e98b84bb5cf391f083d7f20d7453687bb580ba 100755 (executable)
@@ -7724,6 +7724,9 @@ if test x$gcc_no_link = xyes; then
   fi
 fi
 if test "x${ac_cv_func_mmap_fixed_mapped}" != xno; then
+  save_ASAN_OPTIONS="$ASAN_OPTIONS"
+  ASAN_OPTIONS=detect_leaks=0
+  export ASAN_OPTIONS
 
 for ac_func in getpagesize
 do :
@@ -7902,6 +7905,8 @@ $as_echo "#define HAVE_MMAP 1" >>confdefs.h
 fi
 rm -f conftest.mmap conftest.txt
 
+  ASAN_OPTIONS="$save_ASAN_OPTIONS"
+
 fi
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working strncmp" >&5
index dd8a21deba14afb21fa43f808a1f010063dbf4f2..951260ac4c5b9ef08175d5a73c12def534a70b9e 100644 (file)
@@ -98,7 +98,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
        $(top_srcdir)/../config/override.m4 \
        $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
        $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
-       $(top_srcdir)/acinclude.m4 \
+       $(top_srcdir)/acinclude.m4 $(top_srcdir)/../config/mmap.m4 \
        $(top_srcdir)/../config/no-executables.m4 \
        $(top_srcdir)/../libtool.m4 $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
index 9a5f5485716a5f17b16356b128be5637f5212ec6..3b8be00d7022f5df2ff275d750182f72f4f31a14 100644 (file)
@@ -1,3 +1,4 @@
+sinclude(../config/mmap.m4)
 sinclude(../config/no-executables.m4)
 sinclude(../libtool.m4)
 dnl The lines below arrange for aclocal not to bring libtool.m4
index 2d551360683cf2b892a89e9d3979f763e965d3ad..0e8a28a09a89df6a64318f9e857cf8f831d816ae 100755 (executable)
@@ -11245,12 +11245,6 @@ if test -n "$with_cross_host"; then
    # We ignore --with-system-zlib in this case.
    target_all=libzgcj.la
 else
-   if test x$gcc_no_link = xyes; then
-  if test "x${ac_cv_func_mmap_fixed_mapped+set}" != xset; then
-    ac_cv_func_mmap_fixed_mapped=no
-  fi
-fi
-if test "x${ac_cv_func_mmap_fixed_mapped}" != xno; then
 
 
 
@@ -11452,7 +11446,6 @@ $as_echo "#define HAVE_MMAP 1" >>confdefs.h
 fi
 rm -f conftest.mmap conftest.txt
 
-fi
    for ac_func in memcpy strerror
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`