]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libssp: Fix gets-chk.c compilation on Solaris
authorRainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Tue, 6 Feb 2024 10:45:45 +0000 (11:45 +0100)
committerRainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Tue, 6 Feb 2024 10:45:45 +0000 (11:45 +0100)
The recent warning patches broke the libssp build on Solaris:

/vol/gcc/src/hg/master/local/libssp/gets-chk.c: In function '__gets_chk':
/vol/gcc/src/hg/master/local/libssp/gets-chk.c:67:12: error: implicit
declaration of function 'gets'; did you mean 'getw'?
[-Wimplicit-function-declaration]
   67 |     return gets (s);
      |            ^~~~
      |            getw
/vol/gcc/src/hg/master/local/libssp/gets-chk.c:67:12: error: returning
'int' from a function with return type 'char *' makes pointer from integer
without a cast [-Wint-conversion]
   67 |     return gets (s);
      |            ^~~~~~~~
/vol/gcc/src/hg/master/local/libssp/gets-chk.c:74:12: error: returning
'int' from a function with return type 'char *' makes pointer from integer
without a cast [-Wint-conversion]
   74 |     return gets (s);
      |            ^~~~~~~~

The guard around the gets declaration in gets-chk.c is

      || (defined __cplusplus && __cplusplus <= 201103L))
extern char *gets (char *);

where __USE_ISOC11 is glibc-only, while Solaris <iso/stdio_iso.h> declares
gets like

extern char     *gets(char *) __ATTR_DEPRECATED;

Instead of using a target-specific macro, this patch just uses the
canonical autoconf test.

Tested on i386-pc-solaris2.11, sparc-sun-solaris2.11,
x86_64-pc-linux-gnu, x86_64-apple-darwin23.3.0, and amd64-freebsd14.0.

2023-12-07  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

libssp:
* configure.ac (AC_CHECK_DECLS): Check for gets.
* configure, config.h.in: Regenerate.
* gets-chk.c (gets): Guard declaration with !HAVE_DECL_GETS.

libssp/config.h.in
libssp/configure
libssp/configure.ac
libssp/gets-chk.c

index 2815ce7c4d58c0330af68ba8d1f55afdf8717199..60315e0f4ed3dc8082124b5385357917d08966f4 100644 (file)
@@ -3,6 +3,10 @@
 /* Define to 1 if you have the <alloca.h> header file. */
 #undef HAVE_ALLOCA_H
 
+/* Define to 1 if you have the declaration of `gets', and to 0 if you don't.
+   */
+#undef HAVE_DECL_GETS
+
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H
 
index a31b69f306e1f5a552d74092ef6d7d8d9122fd22..0052e03650d1bb0523cf18a269f308ede7233b28 100755 (executable)
@@ -1885,6 +1885,52 @@ $as_echo "$ac_res" >&6; }
   eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
 
 } # ac_fn_c_check_func
+
+# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
+# ---------------------------------------------
+# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
+# accordingly.
+ac_fn_c_check_decl ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  as_decl_name=`echo $2|sed 's/ *(.*//'`
+  as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
+$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+#ifndef $as_decl_name
+#ifdef __cplusplus
+  (void) $as_decl_use;
+#else
+  (void) $as_decl_name;
+#endif
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_decl
 cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
@@ -4841,6 +4887,17 @@ fi
 done
 
 fi
+ac_fn_c_check_decl "$LINENO" "gets" "ac_cv_have_decl_gets" "$ac_includes_default"
+if test "x$ac_cv_have_decl_gets" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_GETS $ac_have_decl
+_ACEOF
+
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether vsnprintf is usable" >&5
 $as_echo_n "checking whether vsnprintf is usable... " >&6; }
@@ -11107,7 +11164,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11110 "configure"
+#line 11167 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11213,7 +11270,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11216 "configure"
+#line 11273 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
index 90778e2355d31b2428b85ab050bb7aa3c8d3a879..5c5698fa3a2d0043abc65b2783b9d25343949bff 100644 (file)
@@ -128,6 +128,7 @@ if test x$gcc_no_link = xyes; then
 else
   AC_CHECK_FUNCS(memmove mempcpy strncpy strncat)
 fi
+AC_CHECK_DECLS([gets])
 
 AC_MSG_CHECKING([whether vsnprintf is usable])
 AC_RUN_IFELSE([AC_LANG_PROGRAM([
index 1d49958796e4670555de310aee1cc7b59a0510c8..3abd99782b065eb6ab0a7d027c4d1e2622cd62f3 100644 (file)
@@ -51,8 +51,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 # include <string.h>
 #endif
 
-#if !(!defined __USE_ISOC11                            \
-      || (defined __cplusplus && __cplusplus <= 201103L))
+#if !HAVE_DECL_GETS
 extern char *gets (char *);
 #endif