libstdc++: Override detection of flockfile support in newlib [PR123406]

Message ID 20260107115116.1822207-1-jwakely@redhat.com
State New
Headers
Series libstdc++: Override detection of flockfile support in newlib [PR123406] |

Commit Message

Jonathan Wakely Jan. 7, 2026, 11:49 a.m. UTC
  As explained in the PR, flockfile and funlockfile are always declared by
newlib and there's no easy way to detect whether they're actually
defined. Ensure that ac_stdio_locking=no gets set for non-cygwin newlib
targets.

libstdc++-v3/ChangeLog:

	PR libstdc++/123406
	* acinclude.m4 (GLIBCXX_CHECK_STDIO_LOCKING): Override detection
	of flockfile for non-cygwin newlib targets.
	* configure: Regenerate.
---

Tested x86_64-linux, where this doesn't change the generated c++config.h
file.

Built on cris-elf to verify that the _GLIBCXX_USE_STDIO_LOCKING macro is
no longer defined in c++config.h.

 libstdc++-v3/acinclude.m4 | 9 ++++++++-
 libstdc++-v3/configure    | 7 +++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
  

Comments

Tomasz Kaminski Jan. 7, 2026, 1:52 p.m. UTC | #1
On Wed, Jan 7, 2026 at 12:52 PM Jonathan Wakely <jwakely@redhat.com> wrote:

> As explained in the PR, flockfile and funlockfile are always declared by

newlib and there's no easy way to detect whether they're actually
> defined. Ensure that ac_stdio_locking=no gets set for non-cygwin newlib
> targets.
>
> libstdc++-v3/ChangeLog:
>
>         PR libstdc++/123406
>         * acinclude.m4 (GLIBCXX_CHECK_STDIO_LOCKING): Override detection
>         of flockfile for non-cygwin newlib targets.
>         * configure: Regenerate.
> ---
>
> Tested x86_64-linux, where this doesn't change the generated c++config.h
> file.
>
LGTM. Thanks for fixing it.

>
> Built on cris-elf to verify that the _GLIBCXX_USE_STDIO_LOCKING macro is
> no longer defined in c++config.h.
>
>  libstdc++-v3/acinclude.m4 | 9 ++++++++-
>  libstdc++-v3/configure    | 7 +++++++
>  2 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
> index 103515c000f4..e6723edf880e 100644
> --- a/libstdc++-v3/acinclude.m4
> +++ b/libstdc++-v3/acinclude.m4
> @@ -5822,13 +5822,20 @@ AC_LANG_SAVE
>    AC_MSG_CHECKING([whether flockfile and putc_unlocked are defined in
> <stdio.h>])
>    AC_TRY_COMPILE([
>    #include <stdio.h>
> +  #if __has_include(<newlib.h>)
> +  # ifdef __CYGWIN__
> +    // Cygwin has working flockfile
> +  # else
> +  #  error No usable flockfile on most newlib targets
> +  # endif
> +  #endif
>    ],[
>      FILE* f = ::fopen("", "");
>      ::flockfile(f);
>      ::putc_unlocked(' ', f);
>      ::funlockfile(f);
>      ::fclose(f);
> -  ], [ac_stdio_locking=yes], [ac_stdio_locking=no])
> +  ],[ac_stdio_locking=yes],[ac_stdio_locking=no])
>    AC_MSG_RESULT($ac_stdio_locking)
>
>    if test "$ac_stdio_locking" = yes; then
> diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
> index 0469cbe0f59c..3d825a69fa2e 100755
> --- a/libstdc++-v3/configure
> +++ b/libstdc++-v3/configure
> @@ -55051,6 +55051,13 @@ $as_echo_n "checking whether flockfile and
> putc_unlocked are defined in <stdio.h
>  /* end confdefs.h.  */
>
>    #include <stdio.h>
> +  #if __has_include(<newlib.h>)
> +  # ifdef __CYGWIN__
> +    // Cygwin has working flockfile
> +  # else
> +  #  error No usable flockfile on most newlib targets
> +  # endif
> +  #endif
>
>  int
>  main ()
> --
> 2.52.0
>
>
  
Hans-Peter Nilsson Jan. 7, 2026, 4:17 p.m. UTC | #2
> From: Jonathan Wakely <jwakely@redhat.com>
> Date: Wed,  7 Jan 2026 11:49:15 +0000

> libstdc++-v3/ChangeLog:
> 
> 	PR libstdc++/123406
> 	* acinclude.m4 (GLIBCXX_CHECK_STDIO_LOCKING): Override detection
> 	of flockfile for non-cygwin newlib targets.
> 	* configure: Regenerate.
> ---
> 
> Tested x86_64-linux, where this doesn't change the generated c++config.h
> file.
> 
> Built on cris-elf to verify that the _GLIBCXX_USE_STDIO_LOCKING macro is
> no longer defined in c++config.h.

Thanks, this indeed fixes PR123406.  Tested against
r16-6493-ge77ba7ef8c75 for cris-elf.  IIUC there's some
"Tested-by:" git-footer I could add that'd fit, but we don't
use it so I don't bother to look up the correct speling.

brgds, H-P
  

Patch

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 103515c000f4..e6723edf880e 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -5822,13 +5822,20 @@  AC_LANG_SAVE
   AC_MSG_CHECKING([whether flockfile and putc_unlocked are defined in <stdio.h>])
   AC_TRY_COMPILE([
   #include <stdio.h>
+  #if __has_include(<newlib.h>)
+  # ifdef __CYGWIN__
+    // Cygwin has working flockfile
+  # else
+  #  error No usable flockfile on most newlib targets
+  # endif
+  #endif
   ],[
     FILE* f = ::fopen("", "");
     ::flockfile(f);
     ::putc_unlocked(' ', f);
     ::funlockfile(f);
     ::fclose(f);
-  ], [ac_stdio_locking=yes], [ac_stdio_locking=no])
+  ],[ac_stdio_locking=yes],[ac_stdio_locking=no])
   AC_MSG_RESULT($ac_stdio_locking)
 
   if test "$ac_stdio_locking" = yes; then
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 0469cbe0f59c..3d825a69fa2e 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -55051,6 +55051,13 @@  $as_echo_n "checking whether flockfile and putc_unlocked are defined in <stdio.h
 /* end confdefs.h.  */
 
   #include <stdio.h>
+  #if __has_include(<newlib.h>)
+  # ifdef __CYGWIN__
+    // Cygwin has working flockfile
+  # else
+  #  error No usable flockfile on most newlib targets
+  # endif
+  #endif
 
 int
 main ()