Hi Bruno,

Bruno Haible <[email protected]> writes:

>> I wonder if it is worth adding the checks for __has_feature,
>> __has_include, etc. in m4/gnulib-common.m4 so that we don't need to
>> repeat the #ifdef's around everywhere, we can just assume it is defined
>> in config.h. Any reason to avoid that?
>
> gnulib-common.m4 is used by all packages, and users have no simple way
> of customizing/overriding what it does. Therefore it is risky to play
> with compiler built-ins like __has_feature there.

True. I guess projects can put it in AH_BOTTOM if they want to use it
without duplicating the code. In Gnulib it isn't repeated too much.

> If you want to minimize the duplication of the test if ASAN is enabled,
> tests/macros.h is a better place, I would say. At least until we have
> a really good reason to move it to gnulib-common.m4.

If it were only in tests/macros.h then the ASAN __getdelim would get
called in non-test code which we don't want.

Pushed the attached patch to fix it. Thanks for catching it.

Collin

>From 9be0da9b06851b5873842f658150a380e02102c8 Mon Sep 17 00:00:00 2001
Message-ID: <9be0da9b06851b5873842f658150a380e02102c8.1760493041.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Tue, 14 Oct 2025 18:30:47 -0700
Subject: [PATCH] getdelim: Avoid the symbol __getdelim with ASAN (regr.
 2025-10-13).

* lib/stdio.in.h (rpl_getdelim)
[__GLIBC__ >= 2 && !__ADDRESS_SANITIZER__]: Don't define to __getdelim
so that ___interceptor_getdelim doesn't override our symbol.
---
 ChangeLog      |  5 +++++
 lib/stdio.in.h | 10 ++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c3dd9cbb7f..c8af7641b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2025-10-14  Collin Funk  <[email protected]>
 
+	getdelim: Avoid the symbol __getdelim with ASAN (regr. 2025-10-13).
+	* lib/stdio.in.h (rpl_getdelim)
+	[__GLIBC__ >= 2 && !__ADDRESS_SANITIZER__]: Don't define to __getdelim
+	so that ___interceptor_getdelim doesn't override our symbol.
+
 	glob: Ensure --enable-cross-guesses is obeyed (regr. yesterday).
 	Reported by Bruno Haible in
 	<https://lists.gnu.org/archive/html/bug-gnulib/2025-10/msg00041.html>.
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index 2c70bc049f..cc6010119d 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -1044,9 +1044,15 @@ _GL_CXXALIASWARN (getchar);
 #   undef getdelim
 #   define getdelim rpl_getdelim
 #  endif
-#  if __GLIBC__ >= 2
+#  ifndef __has_feature
+#   define __has_feature(a) 0
+#  endif
+#  if __GLIBC__ >= 2 && !(defined __SANITIZE_ADDRESS__ \
+                          || __has_feature (address_sanitizer))
 /* Arrange for the inline definition of getline() in <bits/stdio.h>
-   to call our getdelim() override.  */
+   to call our getdelim() override.  Do not use the __getdelim symbol
+   if address sanitizer is in use, otherwise it may be overridden by
+   __interceptor_trampoline___getdelim.  */
 #   define rpl_getdelim __getdelim
 #  endif
 _GL_FUNCDECL_RPL (getdelim, ssize_t,
-- 
2.51.0

Reply via email to