This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFA: Fix bootstrap/42798


The problem arises because /usr/include/string.h has a declaration for
basename which depends (indirectly) on the preprocessor conditional _GNU_SOURCE.
On Linux/GNU, g++ sets _GNU_SOURCE as a predefined symbol; gcc doesn't.


Since libiberty.h can be included both by files that are compiled with
_GNU_SOURCE defined and ones where this macro is not defined, libiberty.h
has to cater for both cases.

The attached patch introduces an additional autoconfigured flag to indicate
that basename is available in the _GNU_SOURCE case, and uses it in libiberty.h .


The gcc-in-cxx bootstrap gets much further with this patch, till it eventually comes to a stop because of an unrelated problem in the fortran frontend.

I'm currently doing a non-gcc-in-cxx bootstrap/regression test on
i686-pc-linux-gnu.

include:
	PR bootstrap/42798

	* libiberty.h: Check _GNU_SOURCE to decide wheather to test
	HAVE_GNU_SOURCE_DECL_BASENAME or HAVE_DECL_BASENAME.
libiberty:
	PR bootstrap/42798

	* configure.ac: Add AC_CHECK_GNU_SOURCE_DECLS(basename).
	* aclocal.m4 (AC_CHECK_GNU_SOURCE_DECL): Define.
	(AC_CHECK_GNU_SOURCE_DECLS): Likewise.
	* configure, config.in: Regenerate.

Index: include/libiberty.h
===================================================================
--- include/libiberty.h	(revision 156033)
+++ include/libiberty.h	(working copy)
@@ -101,7 +101,7 @@ extern int writeargv PARAMS ((char **, F
    declaration without arguments.  If it is 0, we checked and failed
    to find the declaration so provide a fully prototyped one.  If it
    is 1, we found it so don't provide any declaration at all.  */
-#if !HAVE_DECL_BASENAME
+#if defined(_GNU_SOURCE) ? HAVE_GNU_SOURCE_DECL_BASENAME : !HAVE_DECL_BASENAME
 #if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) || defined (HAVE_DECL_BASENAME)
 extern char *basename (const char *);
 #else
Index: libiberty/configure.ac
===================================================================
--- libiberty/configure.ac	(revision 156033)
+++ libiberty/configure.ac	(working copy)
@@ -664,6 +664,7 @@ if test -z "${setobjs}"; then
 
   AC_CHECK_FUNCS($checkfuncs)
   AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf])
+  AC_CHECK_GNU_SOURCE_DECLS(basename)
   AC_CHECK_DECLS([calloc, getenv, getopt, malloc, realloc, sbrk])
   AC_CHECK_DECLS([strverscmp])
   libiberty_NEED_DECLARATION(canonicalize_file_name)
Index: libiberty/aclocal.m4
===================================================================
--- libiberty/aclocal.m4	(revision 156033)
+++ libiberty/aclocal.m4	(working copy)
@@ -221,3 +221,42 @@ char (*f) () = $1;
 #endif
 ], [return f != $1;])])
 
+# AC_CHECK_GNU_SOURCE_DECL(SYMBOL,
+#               [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
+#               [INCLUDES = DEFAULT-INCLUDES])
+# -------------------------------------------------------
+# Check whether SYMBOL (a function, variable, or constant) is declared
+#in the presence of the _GNU_SOURCE define.
+AC_DEFUN([AC_CHECK_GNU_SOURCE_DECL],
+[AS_VAR_PUSHDEF([ac_Symbol], [ac_cv_have_gnu_source_decl_$1])dnl
+AC_CACHE_CHECK([whether $1 is declared for _GNU_SOURCE], [ac_Symbol],
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#define _GNU_SOURCE
+AC_INCLUDES_DEFAULT([$4])],
+[#ifndef $1
+  (void) $1;
+#endif
+])],
+                   [AS_VAR_SET([ac_Symbol], [yes])],
+                   [AS_VAR_SET([ac_Symbol], [no])])])
+AS_VAR_IF([ac_Symbol], [yes], [$2], [$3])[]dnl
+AS_VAR_POPDEF([ac_Symbol])dnl
+])# AC_CHECK_DECL
+
+# AC_CHECK_GNU_SOURCE_DECLS(SYMBOLS,
+#                [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
+#                [INCLUDES = DEFAULT-INCLUDES])
+# --------------------------------------------------------
+# Defines HAVE_GNU_SOURCE_DECL_SYMBOL to 1 if declared, 0 otherwise.  See the
+# documentation for a detailed explanation of this difference with
+# other AC_CHECK_*S macros.  SYMBOLS is an m4 list.
+AC_DEFUN([AC_CHECK_GNU_SOURCE_DECLS],
+[m4_foreach([AC_Symbol], [$1],
+  [AC_CHECK_GNU_SOURCE_DECL(AC_Symbol,
+                 [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_GNU_SOURCE_DECL_]AC_Symbol), 1,
+                                     [Define to 1 if you have the declaration
+                                     of `]AC_Symbol[', and to 0 if you don't.])
+$2],
+                 [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_GNU_SOURCE_DECL_]AC_Symbol), 0)
+$3],
+                 [$4])])
+])# AC_GNU_SOURCE_CHECK_DECLS

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]