https://gcc.gnu.org/g:f3d07779fdb729c7ee81b8e764921becf8ecf1d0

commit r15-8907-gf3d07779fdb729c7ee81b8e764921becf8ecf1d0
Author: Iain Sandoe <i...@sandoe.co.uk>
Date:   Wed Mar 12 15:04:31 2025 +0000

    libiberty: Append <libgen.h> to AC_CHECK_DECLS [PR119218].
    
    Darwin and Solaris, at least, provide basename() in libc, but only
    declare it in <libgen.h>.  That library is not one of the set in
    AC_INCLUDES_DEFAULT and so we fail the config test and fall back
    to the libiberty-provided version.  In itself, this is not an
    issue; however, if we include <libgen.h> and libiberty.h in the same
    TU we do then get a decl conflict.
    
            PR other/119218
    
    libiberty/ChangeLog:
    
            * config.in: Regenerate.
            * configure: Regenerate.
            * configure.ac: Append <libgen.h> to AC_INCLUDES_DEFAULT
            when checking for the 'basename' decl.
    
    Signed-off-by: Iain Sandoe <i...@sandoe.co.uk>

Diff:
---
 libiberty/config.in    |  3 +++
 libiberty/configure    | 12 +++++++++---
 libiberty/configure.ac |  9 +++++++--
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/libiberty/config.in b/libiberty/config.in
index 1b1f2b09a8ab..b055150961c5 100644
--- a/libiberty/config.in
+++ b/libiberty/config.in
@@ -153,6 +153,9 @@
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
+/* Define to 1 if you have the <libgen.h> header file. */
+#undef HAVE_LIBGEN_H
+
 /* Define to 1 if you have the <limits.h> header file. */
 #undef HAVE_LIMITS_H
 
diff --git a/libiberty/configure b/libiberty/configure
index 38856a07e5f0..347719c62623 100755
--- a/libiberty/configure
+++ b/libiberty/configure
@@ -5745,7 +5745,7 @@ host_makefile_frag=${frag}
 # It's OK to check for header files.  Although the compiler may not be
 # able to link anything, it had better be able to at least compile
 # something.
-for ac_header in sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h 
unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h 
fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h 
sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h stdio_ext.h process.h 
sys/prctl.h spawn.h
+for ac_header in sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h 
unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h 
fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h 
sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h stdio_ext.h process.h 
sys/prctl.h spawn.h libgen.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_preproc "$LINENO" "$ac_header" "$as_ac_Header"
@@ -7389,7 +7389,12 @@ fi
 done
 
   as_ac_Symbol=`$as_echo "ac_cv_have_decl_basename(char *)" | $as_tr_sh`
-ac_fn_c_check_decl "$LINENO" "basename(char *)" "$as_ac_Symbol" 
"$ac_includes_default"
+ac_fn_c_check_decl "$LINENO" "basename(char *)" "$as_ac_Symbol" "
+$ac_includes_default
+#ifdef HAVE_LIBGEN_H
+# include <libgen.h>
+#endif
+"
 if eval test \"x\$"$as_ac_Symbol"\" = x"yes"; then :
   ac_have_decl=1
 else
@@ -7399,7 +7404,8 @@ fi
 cat >>confdefs.h <<_ACEOF
 #define HAVE_DECL_BASENAME $ac_have_decl
 _ACEOF
-ac_fn_c_check_decl "$LINENO" "ffs" "ac_cv_have_decl_ffs" "$ac_includes_default"
+
+  ac_fn_c_check_decl "$LINENO" "ffs" "ac_cv_have_decl_ffs" 
"$ac_includes_default"
 if test "x$ac_cv_have_decl_ffs" = xyes; then :
   ac_have_decl=1
 else
diff --git a/libiberty/configure.ac b/libiberty/configure.ac
index c27e08e14288..5bad0f936920 100644
--- a/libiberty/configure.ac
+++ b/libiberty/configure.ac
@@ -291,7 +291,7 @@ AC_SUBST_FILE(host_makefile_frag)
 # It's OK to check for header files.  Although the compiler may not be
 # able to link anything, it had better be able to at least compile
 # something.
-AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h 
unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h 
fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h 
sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h stdio_ext.h process.h 
sys/prctl.h spawn.h)
+AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h 
unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h 
fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h 
sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h stdio_ext.h process.h 
sys/prctl.h spawn.h libgen.h)
 AC_HEADER_SYS_WAIT
 AC_HEADER_TIME
 
@@ -723,7 +723,12 @@ if test -z "${setobjs}"; then
     [AC_MSG_RESULT([no])])
 
   AC_CHECK_FUNCS($checkfuncs)
-  AC_CHECK_DECLS([basename(char *), ffs, asprintf, vasprintf, snprintf, 
vsnprintf])
+  AC_CHECK_DECLS([basename(char *)], [], [], [
+AC_INCLUDES_DEFAULT
+#ifdef HAVE_LIBGEN_H
+# include <libgen.h>
+#endif])
+  AC_CHECK_DECLS([ffs, asprintf, vasprintf, snprintf, vsnprintf])
   AC_CHECK_DECLS([calloc, getenv, getopt, malloc, realloc])
   case "${host}" in
       *-*-darwin*) ;; # Darwin's sbrk implementation is deprecated.

Reply via email to