Re: [PATCH 0/2] mmap: Avoid the sanitizer configure check failure

2024-04-10 Thread H.J. Lu
On Tue, Apr 9, 2024 at 10:39 PM Alan Modra  wrote:
>
> On Tue, Apr 09, 2024 at 07:24:33AM -0700, H.J. Lu wrote:
> > Define GCC_AC_FUNC_MMAP with export ASAN_OPTIONS=detect_leaks=0 to avoid
> > the sanitizer configure check failure.
>
> OK for binutils.  (I just fixed my local copy of autoconf so I
> wouldn't run into this again.)  The proper fix of course is to update
> autotools to something more recent.
>

This is what I am checking in with:

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 
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

Thanks.

-- 
H.J.
From b0c2d5417fc216eeaacf7f2cd34109f438fa9aa7 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" 
Date: Tue, 9 Apr 2024 06:39:21 -0700
Subject: [PATCH] mmap: Avoid the sanitizer configure check failure

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   | 22 ++
 config/no-executables.m4 |  4 ++--
 libiberty/Makefile.in|  1 +
 libiberty/acinclude.m4   |  2 +-
 libiberty/aclocal.m4 |  1 +
 libiberty/configure  |  5 +
 zlib/Makefile.in |  2 +-
 zlib/acinclude.m4|  1 +
 zlib/configure   |  7 ---
 9 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/config/mmap.m4 b/config/mmap.m4
index fba0d9d3657..326b97b91f4 100644
--- a/config/mmap.m4
+++ b/config/mmap.m4
@@ -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 
+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"
+)
diff --git a/config/no-executables.m4 b/config/no-executables.m4
index 6842f84fba3..e8e2537bde5 100644
--- a/config/no-executables.m4
+++ b/config/no-executables.m4
@@ -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
diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
index 85c4b6b6ef8..b77a41c781c 100644
--- a/libiberty/Makefile.in
+++ b/libiberty/Makefile.in
@@ -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 \
diff --git a/libiberty/acinclude.m4 b/libiberty/acinclude.m4
index 9974dcd4ec5..d08e31bc0b5 100644
--- a/libiberty/acinclude.m4
+++ b/libiberty

Re: [PATCH 0/2] mmap: Avoid the sanitizer configure check failure

2024-04-09 Thread Alan Modra
On Tue, Apr 09, 2024 at 07:24:33AM -0700, H.J. Lu wrote:
> Define GCC_AC_FUNC_MMAP with export ASAN_OPTIONS=detect_leaks=0 to avoid
> the sanitizer configure check failure.

OK for binutils.  (I just fixed my local copy of autoconf so I
wouldn't run into this again.)  The proper fix of course is to update
autotools to something more recent.

-- 
Alan Modra
Australia Development Lab, IBM


Re: [PATCH 0/2] mmap: Avoid the sanitizer configure check failure

2024-04-09 Thread H.J. Lu
On Tue, Apr 9, 2024 at 4:08 PM Sam James  wrote:
>
> "H.J. Lu"  writes:
>
> > When -fsanitize=address,undefined is used to build, the mmap configure
> > check failed with
>
> I think Paul fixed this in autoconf commit
> 09b6e78d1592ce10fdc975025d699ee41444aa3f, so we should add a comment
> about that so we can clean this up in future.

Sure . That was in 2016.

> >
> > =
> > ==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.
> >
> > H.J. Lu (2):
> >   mmap: Avoid the sanitizer configure check failure
> >   mmap: Avoid the sanitizer configure check failure
> >
> >  bfd/Makefile.in  |  2 +-
> >  bfd/aclocal.m4   |  1 +
> >  bfd/configure|  5 +
> >  bfd/configure.ac |  2 +-
> >  binutils/Makefile.in |  2 +-
> >  binutils/aclocal.m4  |  1 +
> >  binutils/configure   |  5 +
> >  binutils/configure.ac|  2 +-
> >  config/mmap.m4   | 12 
> >  config/no-executables.m4 |  4 ++--
> >  ld/Makefile.in   |  2 +-
> >  ld/aclocal.m4|  1 +
> >  ld/configure |  5 +
> >  ld/configure.ac  |  2 +-
> >  libctf/Makefile.in   |  2 +-
> >  libctf/aclocal.m4|  1 +
> >  libctf/configure |  5 +
> >  libctf/configure.ac  |  2 +-
> >  libiberty/Makefile.in|  1 +
> >  libiberty/acinclude.m4   |  2 +-
> >  libiberty/aclocal.m4 |  1 +
> >  libiberty/configure  |  5 +
> >  libsframe/Makefile.in|  1 +
> >  libsframe/aclocal.m4 |  1 +
> >  libsframe/configure  |  5 +
> >  libsframe/configure.ac   |  2 +-
> >  zlib/Makefile.in |  2 +-
> >  zlib/acinclude.m4|  1 +
> >  zlib/configure   |  7 ---
> >  29 files changed, 64 insertions(+), 20 deletions(-)



-- 
H.J.


Re: [PATCH 0/2] mmap: Avoid the sanitizer configure check failure

2024-04-09 Thread Sam James
"H.J. Lu"  writes:

> When -fsanitize=address,undefined is used to build, the mmap configure
> check failed with

I think Paul fixed this in autoconf commit
09b6e78d1592ce10fdc975025d699ee41444aa3f, so we should add a comment
about that so we can clean this up in future.

>
> =
> ==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.
>
> H.J. Lu (2):
>   mmap: Avoid the sanitizer configure check failure
>   mmap: Avoid the sanitizer configure check failure
>
>  bfd/Makefile.in  |  2 +-
>  bfd/aclocal.m4   |  1 +
>  bfd/configure|  5 +
>  bfd/configure.ac |  2 +-
>  binutils/Makefile.in |  2 +-
>  binutils/aclocal.m4  |  1 +
>  binutils/configure   |  5 +
>  binutils/configure.ac|  2 +-
>  config/mmap.m4   | 12 
>  config/no-executables.m4 |  4 ++--
>  ld/Makefile.in   |  2 +-
>  ld/aclocal.m4|  1 +
>  ld/configure |  5 +
>  ld/configure.ac  |  2 +-
>  libctf/Makefile.in   |  2 +-
>  libctf/aclocal.m4|  1 +
>  libctf/configure |  5 +
>  libctf/configure.ac  |  2 +-
>  libiberty/Makefile.in|  1 +
>  libiberty/acinclude.m4   |  2 +-
>  libiberty/aclocal.m4 |  1 +
>  libiberty/configure  |  5 +
>  libsframe/Makefile.in|  1 +
>  libsframe/aclocal.m4 |  1 +
>  libsframe/configure  |  5 +
>  libsframe/configure.ac   |  2 +-
>  zlib/Makefile.in |  2 +-
>  zlib/acinclude.m4|  1 +
>  zlib/configure   |  7 ---
>  29 files changed, 64 insertions(+), 20 deletions(-)


signature.asc
Description: PGP signature


[PATCH 0/2] mmap: Avoid the sanitizer configure check failure

2024-04-09 Thread H.J. Lu
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.

H.J. Lu (2):
  mmap: Avoid the sanitizer configure check failure
  mmap: Avoid the sanitizer configure check failure

 bfd/Makefile.in  |  2 +-
 bfd/aclocal.m4   |  1 +
 bfd/configure|  5 +
 bfd/configure.ac |  2 +-
 binutils/Makefile.in |  2 +-
 binutils/aclocal.m4  |  1 +
 binutils/configure   |  5 +
 binutils/configure.ac|  2 +-
 config/mmap.m4   | 12 
 config/no-executables.m4 |  4 ++--
 ld/Makefile.in   |  2 +-
 ld/aclocal.m4|  1 +
 ld/configure |  5 +
 ld/configure.ac  |  2 +-
 libctf/Makefile.in   |  2 +-
 libctf/aclocal.m4|  1 +
 libctf/configure |  5 +
 libctf/configure.ac  |  2 +-
 libiberty/Makefile.in|  1 +
 libiberty/acinclude.m4   |  2 +-
 libiberty/aclocal.m4 |  1 +
 libiberty/configure  |  5 +
 libsframe/Makefile.in|  1 +
 libsframe/aclocal.m4 |  1 +
 libsframe/configure  |  5 +
 libsframe/configure.ac   |  2 +-
 zlib/Makefile.in |  2 +-
 zlib/acinclude.m4|  1 +
 zlib/configure   |  7 ---
 29 files changed, 64 insertions(+), 20 deletions(-)

-- 
2.44.0