]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fixincludes: Declare memmem if it's not declared in system headers [PR109293]
authorXi Ruoyao <xry111@xry111.site>
Mon, 27 Mar 2023 17:48:02 +0000 (01:48 +0800)
committerXi Ruoyao <xry111@xry111.site>
Tue, 28 Mar 2023 09:58:13 +0000 (17:58 +0800)
memmem is not POSIX so the system may lack it.  Then libiberty will
provide an implementation, but it's a "supplemental function" and not
declared in libiberty.h.  We need to declare the prototype to use it
then.

See libiberty doc at
https://gcc.gnu.org/onlinedocs/libiberty/Supplemental-Functions.html.

Tested by bootstrapping GCC in the following container environments on
x86_64-linux-gnu:

1. "Vanilla" system with memmem in Glibc.
2. memmem removed from string.h.
3. memmem removed from both string.h and libc.so.

For 3, also verified that memmem from libiberty is linked into fixincl
executable.

Note that the backport does not contain a complete regeneration of
configure and config.h.in (attempting such regeneration resulted in all
the USED_FOR_TARGET conditional disappearing; this already happened in
trunk at r13-2200).

fixincludes/ChangeLog:

PR other/109293
* configure.ac (AC_CHECK_DECLS): Add memmem.
* configure: Regenerate.
* config.h.in: Regenerate.
* system.h (memmem): Declare if HAVE_DECL_MEMMEM is zero.

(cherry picked from commit 21c74b6ea41d21ef96813b34bfa55c51a82d6c99)

fixincludes/config.h.in
fixincludes/configure
fixincludes/configure.ac
fixincludes/system.h

index 3f6cf1e574eb2b25c89fd396ea4a458041ea5684..9792fdb2419b57e86e0a4ddb077b0f3ac0d499f3 100644 (file)
 #endif
 
 
+/* Define to 1 if you have the declaration of `memmem', and to 0 if you don't.
+   */
+#undef HAVE_DECL_MEMMEM
+
 /* Define to 1 if you have the declaration of `putchar_unlocked', and to 0 if
    you don't. */
 #ifndef USED_FOR_TARGET
index 6e2d67b655b2f0c1914550e0b2e3b97f8391eef0..0d5cd6967cadcd8c97cdbe793e5bd2175946f573 100755 (executable)
@@ -5043,6 +5043,16 @@ fi
 cat >>confdefs.h <<_ACEOF
 #define HAVE_DECL_VASPRINTF $ac_have_decl
 _ACEOF
+ac_fn_c_check_decl "$LINENO" "memmem" "ac_cv_have_decl_memmem" "$ac_includes_default"
+if test "x$ac_cv_have_decl_memmem" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_MEMMEM $ac_have_decl
+_ACEOF
 
 ac_fn_c_check_decl "$LINENO" "clearerr_unlocked" "ac_cv_have_decl_clearerr_unlocked" "$ac_includes_default"
 if test "x$ac_cv_have_decl_clearerr_unlocked" = xyes; then :
index 14813b910f196a7adc7f185a55d02195c021351f..ef2227e3c9385fabd2073cd9a53fed99047b2f38 100644 (file)
@@ -88,7 +88,7 @@ define(fixincludes_UNLOCKED_FUNCS, clearerr_unlocked feof_unlocked dnl
   fread_unlocked fwrite_unlocked getchar_unlocked getc_unlocked dnl
   putchar_unlocked putc_unlocked)
 AC_CHECK_FUNCS(fixincludes_UNLOCKED_FUNCS)
-AC_CHECK_DECLS([abort, asprintf, basename(char *), errno, vasprintf])
+AC_CHECK_DECLS([abort, asprintf, basename(char *), errno, vasprintf, memmem])
 AC_CHECK_DECLS(m4_split(m4_normalize(fixincludes_UNLOCKED_FUNCS)))
 
 # Checks for typedefs, structures, and compiler characteristics.
index dca5d57b2e321aa03b05667d65b45adbcf73d8c1..687fb2e2025d6f62a9c1d44527ea1524b56504da 100644 (file)
@@ -209,6 +209,10 @@ extern int errno;
 extern void abort (void);
 #endif
 
+#if defined (HAVE_DECL_MEMMEM) && !HAVE_DECL_MEMMEM
+extern void *memmem (const void *, size_t, const void *, size_t);
+#endif
+
 #if HAVE_SYS_STAT_H
 # include <sys/stat.h>
 #endif