From patchwork Mon Mar 27 17:59:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 1761883 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=LUoLvgPK; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PlgZF47b5z1yXq for ; Tue, 28 Mar 2023 04:59:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 810C03858C30 for ; Mon, 27 Mar 2023 17:59:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 810C03858C30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679939983; bh=C+qOOBX0+d9VjIy65Cd9nWkohT9LShSI6Vnj3HWayZQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=LUoLvgPK/A++roHwwwnFFix1P95BKzwC+HCRX68oVa97UnbgOnkqosoY8wlwqATua gwaJgknOKLf8H4En+LteGeuQTL79YczCacUDpEUqaMEKlhRaqFnr+5fCd8udSE7CAD NqJiqLTRumAWJcE3Ubj8d0O97iB2W9QixZ5qZc10= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id 1299F3858D3C; Mon, 27 Mar 2023 17:59:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1299F3858D3C Received: from stargazer.. (unknown [IPv6:240e:358:1127:e100:dc73:854d:832e:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 538AF66333; Mon, 27 Mar 2023 13:59:16 -0400 (EDT) To: gcc-patches@gcc.gnu.org Cc: Jan Dubiec , Andrew Pinski , Xi Ruoyao Subject: [PATCH] fixincludes: Declare memmem if it's not declared in system headers [PR109293] Date: Tue, 28 Mar 2023 01:59:08 +0800 Message-Id: <20230327175908.424052-1-xry111@xry111.site> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, LIKELY_SPAM_FROM, SPF_HELO_PASS, SPF_PASS, TXREP, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Xi Ruoyao via Gcc-patches From: Xi Ruoyao Reply-To: Xi Ruoyao Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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. Ok for trunk? 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. --- fixincludes/config.h.in | 4 ++++ fixincludes/configure | 10 ++++++++++ fixincludes/configure.ac | 2 +- fixincludes/system.h | 4 ++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/fixincludes/config.h.in b/fixincludes/config.h.in index 69a67f5f116..0fd21b721b9 100644 --- a/fixincludes/config.h.in +++ b/fixincludes/config.h.in @@ -78,6 +78,10 @@ don't. */ #undef HAVE_DECL_GETC_UNLOCKED +/* 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. */ #undef HAVE_DECL_PUTCHAR_UNLOCKED diff --git a/fixincludes/configure b/fixincludes/configure index b3bca666a4d..bdcc41f6ddc 100755 --- a/fixincludes/configure +++ b/fixincludes/configure @@ -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 : diff --git a/fixincludes/configure.ac b/fixincludes/configure.ac index 14813b910f1..ef2227e3c93 100644 --- a/fixincludes/configure.ac +++ b/fixincludes/configure.ac @@ -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. diff --git a/fixincludes/system.h b/fixincludes/system.h index dca5d57b2e3..687fb2e2025 100644 --- a/fixincludes/system.h +++ b/fixincludes/system.h @@ -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 #endif