mingw investigation - help needed

2024-07-17 Thread Bruno Haible
Hi,

About a week ago, one of the CI runs on GitHub reported this unit test
failure on 64-bit mingw:

= test-c-strtof-mt.sh.log =
thread2 disturbed by thread1!
../../gltests/test-c-strtof-mt.sh: line 24:  3498 Segmentation fault  
LC_ALL=$LOCALE_FR ${CHECKER} ./test-c-strtof-mt${EXEEXT}
FAIL test-c-strtof-mt.sh (exit status: 1)
===

This indicates there is a MT-safety bug in mingw's strtof() function.

However:

  * I can't reproduce it. I ran
  $ LC_ALL=French_France.1252 ./test-c-strtof-mt 25200
for 7 hours (instead of just 1 second) in a VM of mine — no crash.

  * I also don't see an MT-safety bug in the mingw-w64 code.
strtof, defined in stdio/strtof.c, merely invokes strtod.
strtod, defined in gdtoa/strtodnrp.c, merely invokes __strtodg.
__strtodg, defined in gdtoa/strtodg.c, compiled with USE_LOCALE=1 and
NO_LOCALE_CACHE=1, makes use of localeconv() which uses a static buffer
— but this should not be a problem since the current locale is the same
in all threads (setlocale() is not used by the test program while the
threads are running, and there is no uselocale() on mingw).

Any ideas?

Bruno






Re: announce-gen: Fix copyright year in --version output.

2024-07-17 Thread Simon Josefsson via Gnulib discussion list
Bruno Haible  writes:

> Simon Josefsson wrote:
>> > Maybe, I am misreading but I think using $VERSION makes more sense
>> > according to the GNU Coding Standards [1]:
>> >
>> > This copyright notice only needs to mention the most recent year in
>> > which changes were made—there’s no need to list the years for previous
>> > versions’ changes.
>> 
>> Thanks for digging up the reference.  I wonder if something changed
>> here.  Can someone remind me why we do the 'make update-copyright'
>> dance?
>
> The GNU Maintainers Guide and the GNU Coding Standards have different sections
>   - about the copyright notice in source files
> https://www.gnu.org/prep/maintain/html_node/Copyright-Notices.html
>   - about the --version output of programs
> https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html
>
> Neither is a superset of the other one.
>
> update-copyright deals with the *copyright notices* only, not with the
> --version output.
>
> We run 'make update-copyright' every year, because updating the copyright
> notices lazily is
>   - more tedious,
>   - more error-prone
> than doing it at once.

Thanks -- and the following seems like a relevant quote:

  To update the list of year numbers, add each year in which you have
  made nontrivial changes to the package. (Here we assume you’re using a
  publicly accessible revision control server, so that every revision
  installed is also immediately and automatically published.) When you
  add the new year, it is not required to keep track of which files have
  seen significant changes in the new year and which have not. It is
  recommended and simpler to add the new year to all files in the
  package, and be done with it for the rest of the year.

So in that case I think 'make update-copyright' should bump the
copyright year for these scripts too, and it was a bug that it didn't.
Collin, do you agree?  Deriving the copyright year from the $VERSION
string thus seems wrong.

/Simon


signature.asc
Description: PGP signature


Re: announce-gen: Fix copyright year in --version output.

2024-07-17 Thread Bruno Haible
Hi Simon,

> > The GNU Maintainers Guide and the GNU Coding Standards have different 
> > sections
> >   - about the copyright notice in source files
> > https://www.gnu.org/prep/maintain/html_node/Copyright-Notices.html
> >   - about the --version output of programs
> > https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html
> >
> > Neither is a superset of the other one.
> >
> > update-copyright deals with the *copyright notices* only, not with the
> > --version output.
> >
> > We run 'make update-copyright' every year, because updating the copyright
> > notices lazily is
> >   - more tedious,
> >   - more error-prone
> > than doing it at once.
> 
> Thanks -- and the following seems like a relevant quote:
> 
>   To update the list of year numbers, add each year in which you have
>   made nontrivial changes to the package. (Here we assume you’re using a
>   publicly accessible revision control server, so that every revision
>   installed is also immediately and automatically published.) When you
>   add the new year, it is not required to keep track of which files have
>   seen significant changes in the new year and which have not. It is
>   recommended and simpler to add the new year to all files in the
>   package, and be done with it for the rest of the year.

Yes, this is from the text about copyright notices.

> So in that case I think 'make update-copyright' should bump the
> copyright year for these scripts too

I just explained to you that we need to distinguish
  - copyright notices
and
  - --version output.

Now you get back to the ambiguous term "copyright year" and, based
on that term, claim a bug.

I don't want to hear this ambiguous term "copyright year" again.

> and it was a bug that it didn't.
> Collin, do you agree?

No, it's not a bug: The update-copyright program is documented to
  "Update an FSF copyright year list to include the current year."
and since the --version output has only a single year, not a year list,
it is clear that this program modifies only copyright notices.

You are free to write a program that modifies the --version output.
But it would be wrong, IMO, to stuff it into 'update-copyright', because:

  * Nobody reviews the changes done by 'update-copyright'. Nobody
can nor wants to review 1000 file changes. Therefore it is
mandatory that 'update-copyright' is as simple as possible.

  * A program that modifies the --version output, OTOH, needs to deal
with several programming languages (C, Shell, Python, etc.) and with
various programming styles. Since it has an effect on the program's
behaviour, the changes MUST be reviewable and MUST be testable.

Bruno






doc: List library dependencies

2024-07-17 Thread Bruno Haible
This patch documentation the (recommended and optional) libraries used
by gnulib at runtime.


2024-07-17  Bruno Haible  

doc: List library dependencies.
* DEPENDENCIES: List the library dependencies.

diff --git a/DEPENDENCIES b/DEPENDENCIES
index 2c38edc5ad..ce9cf9fb80 100644
--- a/DEPENDENCIES
+++ b/DEPENDENCIES
@@ -294,6 +294,146 @@ Prerequisites on Windows
   + Download:
 https://cygwin.com/install.html
 
+Libraries
+-
+
+Various modules work best with certain libraries installed. These are runtime
+dependencies that are also build dependencies.
+
+For module 'abort-debug':
+  * libbacktrace
++ Recommended.
+  Needed for producing C stack traces with source file names and
+  line numbers.
++ Homepage:
+  https://github.com/ianlancetaylor/libbacktrace
++ Download:
+  https://github.com/ianlancetaylor/libbacktrace
++ Pre-built package name:
+  - On Debian and Debian-based systems: libgcc-N-dev,
+  - On Red Hat distributions: --.
+  - Other: https://repology.org/project/libbacktrace/versions
+
+For module 'acl':
+  * libacl
++ Recommended on Linux systems.
+  Needed so that the creation of backup files respects the access control
+  lists (ACLs) set on the original files.
++ Homepage:
+  https://savannah.nongnu.org/projects/acl/
++ Download:
+  https://download.savannah.nongnu.org/releases/acl/
++ Pre-built package name:
+  - On Debian and Debian-based systems: libacl1-dev,
+  - On Red Hat distributions: libacl-devel.
+  - Other: https://repology.org/project/acl/versions
+  * libattr
++ Recommended on Linux systems.
+  Needed so that the creation of backup files respects the access control
+  lists (ACLs) set on the original files, with fewer system calls.
++ Homepage:
+  https://savannah.nongnu.org/projects/attr/
++ Download:
+  https://download.savannah.nongnu.org/releases/attr/
++ Pre-built package name:
+  - On Debian and Debian-based systems: libattr1-dev,
+  - On Red Hat distributions: libattr-devel.
+  - Other: https://repology.org/project/attr/versions
+
+For module 'gettext-h':
+  * libintl, part of GNU gettext
++ Not needed on systems with glibc.
+  But highly recommended on all other systems.
+  Needed for localization (translation) of messages to the user's
+  native language.
++ Homepage:
+  https://www.gnu.org/software/gettext/
++ Download:
+  https://ftp.gnu.org/gnu/gettext/
++ Pre-built package name:
+  - On Debian and Debian-based systems: --,
+  - On Red Hat distributions: --.
+  - Other: https://repology.org/project/gettext/versions
++ If it is installed in a nonstandard directory, pass the option
+  --with-libintl-prefix=DIR to 'configure'.
+
+For module 'iconv':
+  * GNU libiconv
++ Not needed on systems with glibc and on NetBSD.
+  But highly recommended on all other systems.
+  Needed for character set conversion of strings from/to Unicode.
++ Homepage:
+  https://www.gnu.org/software/libiconv/
++ Download:
+  https://ftp.gnu.org/gnu/libiconv/
++ Pre-built package name:
+  - On Debian and Debian-based systems: --,
+  - On Red Hat distributions: --.
+  - Other: https://repology.org/project/libiconv/versions
++ If it is installed in a nonstandard directory, pass the option
+  --with-libiconv-prefix=DIR to 'configure'.
++ On mingw, a slim alternative is the 'win-iconv' package version 0.0.8
+  from https://github.com/win-iconv/win-iconv .
+
+For module 'libgmp':
+  * GNU gmp.
++ Recommended.
+  Needed for fast multiprecision computations.
++ Homepage:
+  https://www.gnu.org/software/gmp/
++ Download:
+  https://ftp.gnu.org/gnu/gmp/
++ Pre-built package name:
+  - On Debian and Debian-based systems: libgmp-dev,
+  - On Red Hat distributions: gmp-devel.
+  - Other: https://repology.org/project/gmp/versions
++ If it is installed in a nonstandard directory, pass the option
+  --with-libgmp-prefix to 'configure'.
+
+For module 'readline':
+  * GNU readline
++ Recommended.
+  Needed for interactive editing of textual input.
++ Homepage:
+  https://www.gnu.org/software/readline/
++ Download:
+  https://ftp.gnu.org/gnu/readline/
++ Pre-built package name:
+  - On Debian and Debian-based systems: libreadline-dev,
+  - On Red Hat distributions: readline-devel.
+  - Other: https://repology.org/project/readline/versions
++ If it is installed in a nonstandard directory, pass the option
+  --with-libreadline-prefix=DIR to 'configure'.
+
+For modules 'terminfo' and 'termcap':
+  * GNU ncurses (preferred)
+or libtermcap (discouraged) or a curses library (legacy).
++ Recommended.
+  Needed for fancy input/output in terminal emulators.
++ Homepage:
+  https://www.gnu.org/software/ncurses/
++ Download:
+  http

Re: doc: List library dependencies

2024-07-17 Thread Collin Funk
Hi Bruno,

Bruno Haible  writes:

> This patch documentation the (recommended and optional) libraries used
> by gnulib at runtime.

Looks good, thanks!

When setting up a Cygwin testdir of all modules awhile ago I kept
forgetting libraries so this should help.

Collin



Re: announce-gen: Fix copyright year in --version output.

2024-07-17 Thread Bruno Haible
Collin Funk wrote:
> The announce-gen and useless-if-before-free scripts have had changes
> since their copyright date was updated:

How about deriving the --version output from the copyright notice, for
those programs that consist of a single file and that are not written in C?

Like this:

diff --git a/build-aux/run-test b/build-aux/run-test
index 94ef7fd912..0b13ed4d59 100755
--- a/build-aux/run-test
+++ b/build-aux/run-test
@@ -46,9 +46,12 @@ Send patches and bug reports to ."
 # outputs to stdout the --version message.
 func_version ()
 {
+  # Extract the last year from this file's copyright notice.
+  sed_extract_last_year='s/^.*\([0-9]\{4\}\)[^0-9]*$/\1/'
+  year=`sed -n -e /Copyright/p < "$progname" | sed -e 1q | sed -e 
"$sed_extract_last_year"`
   echo "\
 run-test (GNU gnulib)
-Copyright (C) 2024 Free Software Foundation, Inc.
+Copyright (C) ${year} Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later 
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law."

Advantage: Zero maintenance cost, as we rely on 'update-copyright' for the
copyright notice.

Disadvantage: It's a violation of the boundary between program code and
meta-information.

What do you think? Should we do this?

 Bruno






Re: announce-gen: Fix copyright year in --version output.

2024-07-17 Thread Collin Funk
Bruno Haible  writes:

> How about deriving the --version output from the copyright notice, for
> those programs that consist of a single file and that are not written in C?
[...]
> +  # Extract the last year from this file's copyright notice.
> +  sed_extract_last_year='s/^.*\([0-9]\{4\}\)[^0-9]*$/\1/'
> +  year=`sed -n -e /Copyright/p < "$progname" | sed -e 1q | sed -e 
> "$sed_extract_last_year"`
[...]
>
> Advantage: Zero maintenance cost, as we rely on 'update-copyright' for the
> copyright notice.
>
> Disadvantage: It's a violation of the boundary between program code and
> meta-information.
>
> What do you think? Should we do this?

Seems fine to me unless anyone else disagrees. Would take a few more
lines in Perl though, but not too bad.

As far as I'm aware copyright in the US and EU expires a certain number
of years after the author dies (though perhaps assignment to others, FSF
in this case, complicates that). So I don't think the violation between
program code and meta-information should have a meaningful impact.

Not a lawyer, of course, so my word doesn't mean much.

Collin



new module 'stack-trace'

2024-07-17 Thread Bruno Haible
While the 'abort-debug' module is nice, some users may want to have a
print_stack_trace facility that does not come with an override of abort().

This series of patches implements this.


2024-07-17  Bruno Haible  

stack-trace: Add tests.
* tests/test-stack-trace.c: New file.
* modules/stack-trace-tests: New file.

stack-trace: New module.
* lib/stdlib.in.h (print_stack_trace): Make part of the stack-trace
module.
* lib/stack-trace-impl.h: New file, based on lib/abort-debug.c.
* lib/stack-trace.c: New file, based on lib/abort-debug.c.
* lib/abort-debug.c: Include stack-trace-impl.h. Remove definitions
moved to stack-trace-impl.h.
(print_stack_trace): Remove function.
* m4/stdlib_h.m4 (gl_STDLIB_H_REQUIRE_DEFAULTS): Initialize
GNULIB_STACK_TRACE.
(gl_STDLIB_H_DEFAULTS): Initialize CAN_PRINT_STACK_TRACE.
* m4/stack-trace.m4: New file, based on m4/abort-debug.m4.
* m4/abort-debug.m4 (gl_ABORT_DEBUG_EARLY): Remove macro.
(gl_ABORT_DEBUG): Require gl_STDLIB_H_DEFAULTS, gl_STACK_TRACE_EARLY.
Set REPLACE_ABORT here.
* modules/stdlib (Makefile.am): Substitute GNULIB_STACK_TRACE,
CAN_PRINT_STACK_TRACE.
* modules/stack-trace: New file.
* modules/abort-debug (Depends-on): Add stack-trace. Remove execinfo.
(configure.ac-early): Remove section.
* DEPENDENCIES: Update.

2024-07-17  Bruno Haible  

abort-debug: Export the print_stack_trace function.
* lib/stdlib.in.h (print_stack_trace): Renamed from _gl_pre_abort.
* lib/abort-debug.c (print_stack_trace_to): Renamed from
print_stack_trace.
(print_stack_trace): Renamed from _gl_pre_abort.
(rpl_abort): Update.
* tests/macros.h (ASSERT, ASSERT_NO_STDIO): Update.

>From 5e2115332873c8b802afa5d67a3bff1b5fbba2cd Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Thu, 18 Jul 2024 03:07:30 +0200
Subject: [PATCH 1/3] abort-debug: Export the print_stack_trace function.

* lib/stdlib.in.h (print_stack_trace): Renamed from _gl_pre_abort.
* lib/abort-debug.c (print_stack_trace_to): Renamed from
print_stack_trace.
(print_stack_trace): Renamed from _gl_pre_abort.
(rpl_abort): Update.
* tests/macros.h (ASSERT, ASSERT_NO_STDIO): Update.
---
 ChangeLog | 10 ++
 lib/abort-debug.c | 12 ++--
 lib/stdlib.in.h   |  8 
 tests/macros.h|  4 ++--
 4 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b80ca078d5..7b39f40541 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-07-17  Bruno Haible  
+
+	abort-debug: Export the print_stack_trace function.
+	* lib/stdlib.in.h (print_stack_trace): Renamed from _gl_pre_abort.
+	* lib/abort-debug.c (print_stack_trace_to): Renamed from
+	print_stack_trace.
+	(print_stack_trace): Renamed from _gl_pre_abort.
+	(rpl_abort): Update.
+	* tests/macros.h (ASSERT, ASSERT_NO_STDIO): Update.
+
 2024-07-17  Bruno Haible  
 
 	doc: List library dependencies.
diff --git a/lib/abort-debug.c b/lib/abort-debug.c
index 8252b66def..641fceee2d 100644
--- a/lib/abort-debug.c
+++ b/lib/abort-debug.c
@@ -31,7 +31,7 @@ static inline void
 # if (__GNUC__ >= 3) || (__clang_major__ >= 4)
 __attribute__ ((always_inline))
 # endif
-print_stack_trace (FILE *stream)
+print_stack_trace_to (FILE *stream)
 {
   if (state == NULL)
 state = backtrace_create_state (NULL, 0, NULL, NULL);
@@ -50,7 +50,7 @@ static inline void
 # if (__GNUC__ >= 3) || (__clang_major__ >= 4)
 __attribute__ ((always_inline))
 # endif
-print_stack_trace (FILE *stream)
+print_stack_trace_to (FILE *stream)
 {
   void *buffer[100];
   int max_size = sizeof (buffer) / sizeof (buffer[0]);
@@ -75,23 +75,23 @@ print_stack_trace (FILE *stream)
 #endif
 
 void
-_gl_pre_abort (void)
+print_stack_trace (void)
 {
 #if HAVE_LIBBACKTRACE || HAVE_EXECINFO_H
-  print_stack_trace (stderr);
+  print_stack_trace_to (stderr);
 #endif
 }
 
 /*   rpl_abort ();
is equivalent to
- _gl_pre_abort ();
+ print_stack_trace ();
  original abort (); // i.e. raise (SIGABRT);
  */
 void
 rpl_abort (void)
 {
 #if HAVE_LIBBACKTRACE || HAVE_EXECINFO_H
-  print_stack_trace (stderr);
+  print_stack_trace_to (stderr);
 #endif
   raise (SIGABRT);
 }
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index e42368eef2..82e8dcd258 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -256,11 +256,11 @@ _GL_CXXALIASWARN (abort);
 # endif
 #endif
 #if @GNULIB_ABORT_DEBUG@ && @REPLACE_ABORT@
-_GL_EXTERN_C void _gl_pre_abort (void);
+_GL_EXTERN_C void print_stack_trace (void);
 #else
-# if !GNULIB_defined_gl_pre_abort
-#  define _gl_pre_abort() /* nothing */
-#  define GNULIB_defined_gl_pre_abort 1
+# if !GNULIB_defined_print_stack_trace
+#  define print_stack_trace() /* nothing */
+#  define GNULIB_defined_print_stack_trace 1
 # endif
 #endif
 
diff --git a/tests/macros.h b/tests/macros.h
index 144905e031..3121b21820 

stack-trace: Use libasan as an alternative to libbacktrace

2024-07-17 Thread Bruno Haible
This patch enables stack traces with file names and line numbers in some
situations, e.g. when using clang on Debian-based distros. (In this
situation, -lbacktrace does not work because libbacktrace.a is installed
in a GCC-private directory, but -lasan works because it is installed in
a global location.)


2024-07-17  Bruno Haible  

stack-trace: Use libasan as an alternative to libbacktrace.
* m4/stack-trace.m4 (gl_STACK_TRACE_EARLY): As a second choice, use
libasan.
* lib/stack-trace-impl.h (print_stack_trace_to) [HAVE_LIBASAN]:
Implement using libasan.
* lib/stack-trace.c (print_stack_trace): Test also HAVE_LIBASAN.
* lib/abort-debug.c (rpl_abort): Likewise.

diff --git a/lib/abort-debug.c b/lib/abort-debug.c
index ac5ddf15cd..2457ef07c2 100644
--- a/lib/abort-debug.c
+++ b/lib/abort-debug.c
@@ -31,7 +31,7 @@
 void
 rpl_abort (void)
 {
-#if HAVE_LIBBACKTRACE || HAVE_EXECINFO_H
+#if HAVE_LIBBACKTRACE || HAVE_LIBASAN || HAVE_EXECINFO_H
   print_stack_trace_to (stderr);
 #endif
   raise (SIGABRT);
diff --git a/lib/stack-trace-impl.h b/lib/stack-trace-impl.h
index 018563e4cc..529afad7a6 100644
--- a/lib/stack-trace-impl.h
+++ b/lib/stack-trace-impl.h
@@ -28,11 +28,33 @@ print_stack_trace_to (FILE *stream)
 {
   if (state == NULL)
 state = backtrace_create_state (NULL, 0, NULL, NULL);
-  /* Pass skip=0, to work around 
.  */
   fprintf (stream, "Stack trace:\n");
+  /* Pass skip=0, to work around 
.  */
   backtrace_print (state, 0, stream);
 }
 
+#elif HAVE_LIBASAN
+
+# include 
+
+/* We need only one declaration from .  */
+extern
+# ifdef __cplusplus
+"C"
+# endif
+void __sanitizer_print_stack_trace (void);
+
+/* The only supported stream, in this case, is stderr.  */
+static inline void
+# if (__GNUC__ >= 3) || (__clang_major__ >= 4)
+__attribute__ ((always_inline))
+# endif
+print_stack_trace_to (FILE *stream)
+{
+  fprintf (stream, "Stack trace:\n");
+  __sanitizer_print_stack_trace ();
+}
+
 #elif HAVE_EXECINFO_H
 
 # include 
diff --git a/lib/stack-trace.c b/lib/stack-trace.c
index b4ad37bf78..b08a977064 100644
--- a/lib/stack-trace.c
+++ b/lib/stack-trace.c
@@ -24,7 +24,7 @@
 void
 print_stack_trace (void)
 {
-#if HAVE_LIBBACKTRACE || HAVE_EXECINFO_H
+#if HAVE_LIBBACKTRACE || HAVE_LIBASAN || HAVE_EXECINFO_H
   print_stack_trace_to (stderr);
 #endif
 }
diff --git a/m4/stack-trace.m4 b/m4/stack-trace.m4
index 7184ca7eb2..e102484e0f 100644
--- a/m4/stack-trace.m4
+++ b/m4/stack-trace.m4
@@ -1,5 +1,5 @@
 # stack-trace.m4
-# serial 1
+# serial 2
 dnl Copyright (C) 2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -48,29 +48,56 @@ AC_DEFUN([gl_STACK_TRACE_EARLY]
   CAN_PRINT_STACK_TRACE=1
   LIBS="$LIBS -lbacktrace"
 else
-  dnl The second choice is libexecinfo.
-  dnl It does not produce source file names and line numbers, only 
addresses
-  dnl (which are mostly useless due to ASLR) and _sometimes_ function 
names.
-  AC_REQUIRE([AC_CANONICAL_HOST])
-  case "$host_os" in
-*-gnu* | gnu* | darwin* | freebsd* | dragonfly* | netbsd* | openbsd* | 
solaris*)
-  dnl execinfo might be implemented on this platform.
-  CAN_PRINT_STACK_TRACE=1
-  dnl On *BSD system, link all programs with -lexecinfo. Cf. 
m4/execinfo.m4.
-  case "$host_os" in
-freebsd* | dragonfly* | netbsd* | openbsd*)
-  LIBS="$LIBS -lexecinfo"
-  ;;
-  esac
-  dnl Link all programs in such a way that the stack trace includes the
-  dnl function names. '-rdynamic' is equivalent to 
'-Wl,-export-dynamic'.
-  case "$host_os" in
-*-gnu* | gnu* | openbsd*)
-  LDFLAGS="$LDFLAGS -rdynamic"
-  ;;
-  esac
-  ;;
-  esac
+  dnl The second choice is GCC's libasan, installed as part of GCC.
+  dnl It produces source file names and line numbers, if the binary
+  dnl is compiled with debug information.
+  AC_CACHE_CHECK([for libasan], [gl_cv_lib_asan], [
+gl_saved_LIBS="$LIBS"
+LIBS="$gl_saved_LIBS -lasan"
+AC_LINK_IFELSE(
+  [AC_LANG_PROGRAM(
+ [[extern
+   #ifdef __cplusplus
+   "C"
+   #endif
+   void __sanitizer_print_stack_trace (void);
+ ]],
+ [[__sanitizer_print_stack_trace ();
+ ]])],
+  [gl_cv_lib_asan=yes],
+  [gl_cv_lib_asan=no])
+LIBS="$gl_saved_LIBS"
+  ])
+  if test $gl_cv_lib_asan = yes; then
+AC_DEFINE([HAVE_LIBASAN], [1],
+  [Define if you have the libasan library.])
+CAN_PRINT_STACK_TRACE=1
+LIBS="$LIBS -lasan"
+  else
+dnl The third choice is libexe