On 05/19/2017 08:02 AM, Bruno Haible wrote:
the problem comes from the 'closeout' module: When main() is finished, it closes fd 1 and 2, and the libasan then cannot perform the output it wants to do.
Yes, closeout should not close stderr when addresses are being sanitized. I installed the attached patch to work around the problem. Perhaps a better fix could be made (e.g., close_stdout could conditionally call AddressSanitizer's leak_check_at_exit before closing stderr), but this workaround should suffice for now.
2) test-u8-casecoll It fails because HAVE_ICONV is not defined - because the test program in m4/iconv.m4 fails due to an iconv_t leak / memory leak. What is the best practice here? Should -fsanitize=address only be activated after configure has run? Or should all configure run tests be changed so that they free all allocated memory?
The latter is surely too much work for not enough benefit. In general, a 'configure'-time test should focus on one individual feature, and not attempt to test a combination of features, as there are too many combinations. This is partly why we advise people not to run 'configure' with -Werror, as that tests not only the desired features but also whether the 'configure'-time test pacifies picky compilers. Similarly, we should advise people not to run 'configure' with sanitization options like memory-leak detection that affect valid (albeit inefficient) test programs.
However, it should be OK to configure with -fsanitize=address if the ASAN_OPTIONS environment variable suppresses checks for valid-albeit-inefficent behavior. For example, ASAN_OPTIONS='detect_leaks=0' may suffice. (I haven't checked this.)
>From db389c44582a7e5b3aab9669cf3256d842a9d64c Mon Sep 17 00:00:00 2001 From: Paul Eggert <egg...@cs.ucla.edu> Date: Fri, 19 May 2017 08:52:38 -0700 Subject: [PATCH] =?UTF-8?q?closeout:=20don=E2=80=99t=20close=20stderr=20wh?= =?UTF-8?q?en=20sanitizing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * NEWS: Document this. * lib/closeout.c (__has_feature): New macro, if not already defined. (SANITIZE_ADDRESS): New constant. (close_stdout): Donât close stderr if sanitizing addresses. --- ChangeLog | 8 ++++++++ NEWS | 4 ++++ lib/closeout.c | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3dce45e..4794685 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2017-05-19 Paul Eggert <egg...@cs.ucla.edu> + + closeout: donât close stderr when sanitizing + * NEWS: Document this. + * lib/closeout.c (__has_feature): New macro, if not already defined. + (SANITIZE_ADDRESS): New constant. + (close_stdout): Donât close stderr if sanitizing addresses. + 2017-05-19 Bruno Haible <br...@clisp.org> get-rusage-data tests: Avoid failure on Linux/glibc. diff --git a/NEWS b/NEWS index bd40347..b75ca01 100644 --- a/NEWS +++ b/NEWS @@ -42,6 +42,10 @@ User visible incompatible changes Date Modules Changes +2017-05-19 closeout close_stdout longer closes stderr when addresses + are being sanitized, as the sanitizer outputs to + stderr afterwards. + 2017-02-16 binary-io On MS-DOS and OS/2, set_binary_mode now fails on ttys, and sets errno == EINVAL. diff --git a/lib/closeout.c b/lib/closeout.c index a23388f..2a3f791 100644 --- a/lib/closeout.c +++ b/lib/closeout.c @@ -33,6 +33,16 @@ #include "exitfail.h" #include "quotearg.h" +#ifndef __has_feature +# define __has_feature(a) false +#endif + +#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) +enum { SANITIZE_ADDRESS = true }; +#else +enum { SANITIZE_ADDRESS = false }; +#endif + static const char *file_name; /* Set the file name to be reported in the event an error is detected @@ -119,6 +129,8 @@ close_stdout (void) _exit (exit_failure); } - if (close_stream (stderr) != 0) - _exit (exit_failure); + /* Close stderr only if not sanitizing, as sanitizers may report to + stderr after this function returns. */ + if (!SANITIZE_ADDRESS && close_stream (stderr) != 0) + _exit (exit_failure); } -- 2.9.4