From 5e57c9bd3e0356ead33642139fcacb224bfe88e5 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 3 Mar 2023 12:16:14 -0500 Subject: [PATCH 1/2] */*.m4: update main() signatures. The next generation of C compilers is going to enforce the C standard more strictly: https://wiki.gentoo.org/wiki/Modern_C_porting One warning that will soon become an error is -Wstrict-prototypes. This is relatively easy to catch in most code (it will fail to compile), but inside of autoconf tests it can go unnoticed because many feature-test compilations fail by design. For example, $ export CFLAGS="$CFLAGS -Werror=strict-prototypes" $ ./configure ... checking if iconv supports errno... no configure: error: iconv does not support errno (this is on a system where iconv *does* support errno). If errno support were optional, that test would have "silently" disabled it. The underlying issue here, from config.log, is conftest.c:211:5: error: function declaration isn't a prototype [-Werror=strict-prototypes] 211 | int main() { This commit goes through all of our autoconf tests, replacing main() with main(void). Up to equivalent types and variable renamings, that's one of the two valid signatures, and satisfies the compiler (gcc-12 in this case). Fixes GH-10751 --- TSRM/threads.m4 | 2 +- Zend/Zend.m4 | 4 ++-- build/php.m4 | 24 ++++++++++++------------ ext/iconv/config.m4 | 6 +++--- ext/opcache/config.m4 | 6 +++--- ext/standard/config.m4 | 12 ++++++------ sapi/fpm/config.m4 | 10 +++++----- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/TSRM/threads.m4 b/TSRM/threads.m4 index dc5719bbec056..c42b328dd6651 100644 --- a/TSRM/threads.m4 +++ b/TSRM/threads.m4 @@ -73,7 +73,7 @@ void *thread_routine(void *data) { return data; } -int main() { +int main(void) { pthread_t thd; pthread_mutexattr_t mattr; int data = 1; diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index a1450e4f13396..c86aaaa4a7eb5 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -162,7 +162,7 @@ int stack_grows_downwards(uintptr_t arg) { return (uintptr_t)&local < arg; } -int main() { +int main(void) { int local; f = stack_grows_downwards; @@ -250,7 +250,7 @@ typedef union _mm_align_test { #define ZEND_MM_ALIGNMENT (sizeof(mm_align_test)) #endif -int main() +int main(void) { size_t i = ZEND_MM_ALIGNMENT; int zeros = 0; diff --git a/build/php.m4 b/build/php.m4 index 4457af1d5e472..e11a00c3bcb16 100644 --- a/build/php.m4 +++ b/build/php.m4 @@ -1034,7 +1034,7 @@ AC_DEFUN([_PHP_CHECK_SIZEOF], [ #endif $3 -int main() +int main(void) { FILE *fp = fopen("conftestval", "w"); if (!fp) return(1); @@ -1102,7 +1102,7 @@ AC_CACHE_CHECK(for type of reentrant time-related functions, ac_cv_time_r_type,[ AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include -int main() { +int main(void) { char buf[27]; struct tm t; time_t old = 0; @@ -1118,7 +1118,7 @@ return (1); ],[ AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include -int main() { +int main(void) { struct tm t, *s; time_t old = 0; char buf[27], *p; @@ -1159,7 +1159,7 @@ AC_DEFUN([PHP_DOES_PWRITE_WORK],[ #include #include $1 - int main() { + int main(void) { int fd = open("conftest_in", O_WRONLY|O_CREAT, 0600); if (fd < 0) return 1; @@ -1193,7 +1193,7 @@ AC_DEFUN([PHP_DOES_PREAD_WORK],[ #include #include $1 - int main() { + int main(void) { char buf[3]; int fd = open("conftest_in", O_RDONLY); if (fd < 0) return 1; @@ -1405,7 +1405,7 @@ struct s int i; char c[1]; }; -int main() +int main(void) { struct s *s = malloc(sizeof(struct s) + 3); s->i = 3; @@ -1463,7 +1463,7 @@ int seeker(void *cookie, off64_t *position, int whence) cookie_io_functions_t funcs = {reader, writer, seeker, closer}; -int main() { +int main(void) { struct cookiedata g = { 0 }; FILE *fp = fopencookie(&g, "r", funcs); @@ -1590,7 +1590,7 @@ AC_DEFUN([PHP_CHECK_FUNC_LIB],[ if test "$found" = "yes"; then ac_libs=$LIBS LIBS="$LIBS -l$2" - AC_RUN_IFELSE([AC_LANG_SOURCE([[int main() { return (0); }]])],[found=yes],[found=no],[ + AC_RUN_IFELSE([AC_LANG_SOURCE([[int main(void) { return (0); }]])],[found=yes],[found=no],[ dnl Cross compilation. found=yes ]) @@ -1644,7 +1644,7 @@ AC_DEFUN([PHP_TEST_BUILD], [ AC_LINK_IFELSE([AC_LANG_SOURCE([[ $5 char $1(); - int main() { + int main(void) { $1(); return 0; } @@ -2296,7 +2296,7 @@ AC_DEFUN([PHP_TEST_WRITE_STDOUT],[ #define TEXT "This is the test message -- " -int main() +int main(void) { int n; @@ -2818,7 +2818,7 @@ AC_DEFUN([PHP_CHECK_AVX512_SUPPORTS], [ AC_LINK_IFELSE([AC_LANG_SOURCE([[ #include - int main() { + int main(void) { __m512i mask = _mm512_set1_epi32(0x1); char out[32]; _mm512_storeu_si512(out, _mm512_shuffle_epi8(mask, mask)); @@ -2846,7 +2846,7 @@ AC_DEFUN([PHP_CHECK_AVX512_VBMI_SUPPORTS], [ CFLAGS="-mavx512f -mavx512cd -mavx512vl -mavx512dq -mavx512bw -mavx512vbmi $CFLAGS" AC_LINK_IFELSE([AC_LANG_SOURCE([[ #include - int main() { + int main(void) { __m512i mask = _mm512_set1_epi32(0x1); char out[32]; _mm512_storeu_si512(out, _mm512_permutexvar_epi8(mask, mask)); diff --git a/ext/iconv/config.m4 b/ext/iconv/config.m4 index ac57c81e7d472..5d408de8331d9 100644 --- a/ext/iconv/config.m4 +++ b/ext/iconv/config.m4 @@ -30,7 +30,7 @@ if test "$PHP_ICONV" != "no"; then AC_MSG_CHECKING([if using GNU libiconv]) AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include -int main() { +int main(void) { printf("%d", _libiconv_version); return 0; } @@ -90,7 +90,7 @@ int main() { #include #include -int main() { +int main(void) { iconv_t cd; cd = iconv_open( "*blahblah*", "*blahblahblah*" ); if (cd == (iconv_t)(-1)) { @@ -117,7 +117,7 @@ int main() { #include #include -int main() { +int main(void) { iconv_t cd = iconv_open( "UTF-8//IGNORE", "UTF-8" ); if(cd == (iconv_t)-1) { return 1; diff --git a/ext/opcache/config.m4 b/ext/opcache/config.m4 index 7e681bb112815..444ded9976ac1 100644 --- a/ext/opcache/config.m4 +++ b/ext/opcache/config.m4 @@ -116,7 +116,7 @@ if test "$PHP_OPCACHE" != "no"; then #include #include -int main() { +int main(void) { pid_t pid; int status; int ipc_id; @@ -195,7 +195,7 @@ int main() { # define MAP_FAILED ((void*)-1) #endif -int main() { +int main(void) { pid_t pid; int status; char *shm; @@ -257,7 +257,7 @@ int main() { # define MAP_FAILED ((void*)-1) #endif -int main() { +int main(void) { pid_t pid; int status; int fd; diff --git a/ext/standard/config.m4 b/ext/standard/config.m4 index 87f41b25eb9d5..984dfcd8a256e 100644 --- a/ext/standard/config.m4 +++ b/ext/standard/config.m4 @@ -81,7 +81,7 @@ if test "$PHP_EXTERNAL_LIBCRYPT" != "no"; then #include #include -int main() { +int main(void) { #if HAVE_CRYPT char *encrypted = crypt("rasmuslerdorf","rl"); return !encrypted || strcmp(encrypted,"rl.3StKT.4T8M"); @@ -111,7 +111,7 @@ int main() { #include #include -int main() { +int main(void) { #if HAVE_CRYPT char *encrypted = crypt("rasmuslerdorf","_J9..rasm"); return !encrypted || strcmp(encrypted,"_J9..rasmBYk8r9AiWNc"); @@ -141,7 +141,7 @@ int main() { #include #include -int main() { +int main(void) { #if HAVE_CRYPT char salt[15], answer[40]; char *encrypted; @@ -181,7 +181,7 @@ int main() { #include #include -int main() { +int main(void) { #if HAVE_CRYPT char salt[30], answer[70]; char *encrypted; @@ -218,7 +218,7 @@ int main() { #include #include -int main() { +int main(void) { #if HAVE_CRYPT char salt[21], answer[21+86]; char *encrypted; @@ -254,7 +254,7 @@ int main() { #include #include -int main() { +int main(void) { #if HAVE_CRYPT char salt[21], answer[21+43]; char *encrypted; diff --git a/sapi/fpm/config.m4 b/sapi/fpm/config.m4 index ab85be7ca09aa..77dc32c56a908 100644 --- a/sapi/fpm/config.m4 +++ b/sapi/fpm/config.m4 @@ -66,7 +66,7 @@ AC_DEFUN([AC_FPM_CLOCK], #include #include - int main() + int main(void) { kern_return_t ret; clock_serv_t aClock; mach_timespec_t aTime; ret = host_get_clock_service(mach_host_self(), REALTIME_CLOCK, &aClock); @@ -134,7 +134,7 @@ AC_DEFUN([AC_FPM_TRACE], #define PTRACE_PEEKDATA PT_READ_D #endif - int main() + int main(void) { long v1 = (unsigned int) -1; /* copy will fail if sizeof(long) == 8 and we've got "int ptrace()" */ long v2; @@ -239,7 +239,7 @@ AC_DEFUN([AC_FPM_TRACE], #include #include #include - int main() + int main(void) { long v1 = (unsigned int) -1, v2 = 0; char buf[128]; @@ -578,7 +578,7 @@ if test "$PHP_FPM" != "no"; then AC_CHECK_HEADERS([sys/acl.h]) AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include - int main() + int main(void) { acl_t acl; acl_entry_t user, group; @@ -597,7 +597,7 @@ if test "$PHP_FPM" != "no"; then AC_MSG_RESULT([yes]) ],[ AC_RUN_IFELSE([AC_LANG_SOURCE([[#include - int main() + int main(void) { acl_t acl; acl_entry_t user, group; From 560d030008e0924828daefeee9683434a357a05e Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 3 Mar 2023 12:28:37 -0500 Subject: [PATCH 2/2] ext/iconv/config.m4: add missing stdio.h include. The next generation of C compilers is going to enforce the C standard more strictly: https://wiki.gentoo.org/wiki/Modern_C_porting One warning that will eventually become an error is -Wimplicit-function-declaration. This is relatively easy to catch in most code (it will fail to compile), but inside of autoconf tests it can go unnoticed because many feature-test compilations fail by design. For example, AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], [[iconv_ccs_init(NULL, NULL);]])]... is designed to fail if iconv_ccs_init() is not in iconv.h. On the other hand, AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include int main() { printf("%d", _libiconv_version); return 0; } should pass if _libiconv_version is defined. If the user has -Werror=implicit-function-declaration in his CFLAGS, however, it will not: $ export CFLAGS="$CFLAGS -Werror=implicit-function-declaration" $ ./configure ... checking if using GNU libiconv... no This is because the stdio.h header that defines printf() is missing: conftest.c:240:3: error: implicit declaration of function 'printf' [-Werror=implicit-function-declaration] 240 | printf("%d", _libiconv_version); | ^~~~~~ conftest.c:239:1: note: include '' or provide a declaration of 'printf' This commit adds the include, correcting the test with any compiler that balks at implicit function definitions. Closes GH-10751 --- ext/iconv/config.m4 | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/iconv/config.m4 b/ext/iconv/config.m4 index 5d408de8331d9..3cf400fe96231 100644 --- a/ext/iconv/config.m4 +++ b/ext/iconv/config.m4 @@ -30,6 +30,7 @@ if test "$PHP_ICONV" != "no"; then AC_MSG_CHECKING([if using GNU libiconv]) AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include +#include int main(void) { printf("%d", _libiconv_version); return 0;