https://gcc.gnu.org/g:1b8b53ef75c143cddc114705c97c74d9c8f7a64b

commit r15-2945-g1b8b53ef75c143cddc114705c97c74d9c8f7a64b
Author: Hans-Peter Nilsson <h...@axis.com>
Date:   Tue Aug 13 19:23:43 2024 +0200

    libstdc++-v3: Handle iconv as optional for newlib builds [PR116362]
    
    Support for iconv in newlib seems to have been always
    assumed present by libstdc++-v3, but is default off.
    
    Though, it hasn't been used before recent libstdc++ changes
    that actually call iconv functions.  This now leads to
    failures exposed by running the test-suite, unless the
    newlib being used has been explicitly configured with
    --enable-newlib-iconv.  When failing, there are undefined
    references to iconv, iconv_open or iconv_close for multiple
    tests.
    
    Thankfully there's a macro in newlib.h that we can check to
    detect presence of iconv support for the newlib build that's
    used.
    
    libstdc++-v3:
            PR libstdc++/116362
            * configure.ac: Check newlib configuration whether iconv is enabled.
            * configure: Regenerate.

Diff:
---
 libstdc++-v3/configure    | 26 +++++++++++++++++++++++++-
 libstdc++-v3/configure.ac | 10 +++++++++-
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index fe525308ae2..305675eaa1e 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -28571,7 +28571,31 @@ _ACEOF
 
 
 
-    $as_echo "#define HAVE_ICONV 1" >>confdefs.h
+    # Support for iconv in newlib is configurable.
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <newlib.h>
+int
+main ()
+{
+
+      #ifndef _ICONV_ENABLED
+      #error
+      #endif
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_newlib_iconv_enabled=yes
+else
+  ac_newlib_iconv_enabled=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    if test "$ac_newlib_iconv_enabled" = yes; then
+      $as_echo "#define HAVE_ICONV 1" >>confdefs.h
+
+    fi
 
     $as_echo "#define HAVE_MEMALIGN 1" >>confdefs.h
 
diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac
index ccb24a82be7..4049f54bd5a 100644
--- a/libstdc++-v3/configure.ac
+++ b/libstdc++-v3/configure.ac
@@ -376,7 +376,15 @@ dnl # rather than hardcoding that information.
       frexpl hypotl ldexpl log10l logl modfl powl sinhl sinl sqrtl
       tanhl tanl])
 
-    AC_DEFINE(HAVE_ICONV)
+    # Support for iconv in newlib is configurable.
+    AC_TRY_COMPILE([#include <newlib.h>], [
+      #ifndef _ICONV_ENABLED
+      #error
+      #endif], [ac_newlib_iconv_enabled=yes], [ac_newlib_iconv_enabled=no])
+    if test "$ac_newlib_iconv_enabled" = yes; then
+      AC_DEFINE(HAVE_ICONV)
+    fi
+
     AC_DEFINE(HAVE_MEMALIGN)
 
     case "${target}" in

Reply via email to