Description:
Because of Darwin ARM64 ABI requirements, Xcode clang 12 or later considers implicit function declarations (e.g. due to missing header files) to be an error rather than a warning. Implicit function declarations in feature checks during configure can cause a build to proceed with features erroneously disabled. One such instance is CheckWorkingKqueue.cmake in the bundled libevent 2.1.11, which uses memset() without including string.h, and exit() without including stdlib.h. CMake output will contain:
-- Checking if kqueue works with pipes...
-- Performing Test EVENT__HAVE_WORKING_KQUEUE
-- Performing Test EVENT__HAVE_WORKING_KQUEUE - Failed
and CMakeError.log will contain:
Performing C SOURCE FILE Test EVENT__HAVE_WORKING_KQUEUE failed with the following compile output:
Change Dir: /opt/local/var/macports/build/_opt_local_var_macports_sources_github.com_macports_macports-ports_databases_mysql8/mysql8/work/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make -f Makefile cmTC_74992/fast && /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_74992.dir/build.make CMakeFiles/cmTC_74992.dir/build
Building C object CMakeFiles/cmTC_74992.dir/src.c.o
/usr/bin/clang -DEVENT__HAVE_WORKING_KQUEUE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-omit-frame-pointer -ftls-model=initial-exec -pipe -I/opt/local/libexec/openssl11/include -Os -DNDEBUG -I/opt/local/libexec/openssl11/include -I/opt/local/include -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -Wall -Wextra -Wno-unused-parameter -Wstrict-aliasing -Wstrict-prototypes -fno-strict-aliasing -Wmissing-prototypes -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Waddress -Woverride-init -Wwrite-strings -Wno-unused-function -Wno-error=deprecated-declarations -Wno-unused-function -Qunused-arguments -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -mmacosx-version-min=10.15 -fPIE -MD -MT CMakeFiles/cmTC_74992.dir/src.c.o -MF CMakeFiles/cmTC_74992.dir/src.c.o.d -o CMakeFiles/cmTC_74992.dir/src.c.o -c /opt/local/var/macports/build/_opt_local_var_macports_sources_github.com_macports_macports-ports_databases_mysql8/mysql8/work/build/CMakeFiles/CMakeTmp/src.c
/opt/local/var/macports/build/_opt_local_var_macports_sources_github.com_macports_macports-ports_databases_mysql8/mysql8/work/build/CMakeFiles/CMakeTmp/src.c:20:9: error: implicitly declaring library function 'exit' with type 'void (int) __attribute__((noreturn))' [-Werror,-Wimplicit-function-declaration]
exit(1);
^
/opt/local/var/macports/build/_opt_local_var_macports_sources_github.com_macports_macports-ports_databases_mysql8/mysql8/work/build/CMakeFiles/CMakeTmp/src.c:20:9: note: include the header <stdlib.h> or explicitly provide a declaration for 'exit'
/opt/local/var/macports/build/_opt_local_var_macports_sources_github.com_macports_macports-ports_databases_mysql8/mysql8/work/build/CMakeFiles/CMakeTmp/src.c:30:5: error: implicitly declaring library function 'memset' with type 'void *(void *, int, unsigned long)' [-Werror,-Wimplicit-function-declaration]
memset(&ev, 0, sizeof(ev));
^
/opt/local/var/macports/build/_opt_local_var_macports_sources_github.com_macports_macports-ports_databases_mysql8/mysql8/work/build/CMakeFiles/CMakeTmp/src.c:30:5: note: include the header <string.h> or explicitly provide a declaration for 'memset'
2 errors generated.
make[1]: *** [CMakeFiles/cmTC_74992.dir/src.c.o] Error 1
make: *** [cmTC_74992/fast] Error 2
Note that upstream had intended for EVENT__HAVE_WORKING_KQUEUE to be set unconditionally on Apple platforms and not have to run CheckWorkingKqueue.cmake: https://github.com/libevent/libevent/commit/3aa68a82dcbbea5110e1f4b4b8addfa8df18eace . But MySQL reverted that change to suppress a warning: https://github.com/mysql/mysql-server/commit/c2c3bfa4f2bb5412008737a8b17142c17b8d472a , which leaves EVENT__HAVE_WORKING_KQUEUE to be set/defined only when CheckWorkingKqueue.cmake succeeds, which it currently will not with Xcode 12 and later.
The same will happen using MySQL 5.7.36, although I am aware that 5.7 is now unsupported on macOS.
Even when this libevent feature is disabled, libevent and MySQL will finish compiling.
Caveat: I do not know for certain that MySQL functionality is broken/degraded by this libevent feature being disabled on macOS, but have submitted this report in case it is. If MySQL does not currently depend on or take advantage of this feature, then there may be no need to act on this report right away.
How to repeat:
Configure MySQL 8.0.27 or 5.7.36 with -DWITH_LIBEVENT=bundled using Xcode clang 12 or later (on macOS 10.15 or later, any architecture).
Suggested fix:
Backport this change accepted upstream which adds the missing headers: https://github.com/libevent/libevent/commit/89505f8513b8590e7a7700d481c20562d0726d54