Bug #105562 Bundled libevent: EVENT__HAVE_WORKING_KQUEUE not defined with Xcode 12 or later
Submitted: 14 Nov 2021 9:21 Modified: 17 Dec 2021 21:00
Reporter: Christopher Chavez (OCA) Email Updates:
Status: Closed Impact on me:
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:8.0.27 OS:MacOS
Assigned to: CPU Architecture:Any

[14 Nov 2021 9:21] Christopher Chavez
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 - 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]
/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
[15 Nov 2021 13:52] MySQL Verification Team
Hi Mr. Chavez,

Thank you for your bug report.

We support fully MySQL server 8.0 on ARM macOS. There are packages that are already available on our site dev.mysql.com.

Hence, all you have to do is to download them. 

We have also built MySQL 8.0, by ourselves , on ARM macOS and we had no problems what so ever. We used the flags that work and do not use those that do not yet work on ARM macOS. Hence , this is not our issue at all ....... We support those flags that work. Regarding others, you can file your bug with Apple or CLang provider.

[15 Nov 2021 13:56] MySQL Verification Team

Just for your notice we only support CMake 3.21.3 and XCode 13.1.
[19 Nov 2021 18:53] Christopher Chavez
Thank you for verifying this report, and for pointing out the availability of official binaries.

However, contrary to the “Unsupported” designation, the configure behavior in this report *does* occur when using Xcode 13.1. I merely say “Xcode 12 or later” in my report for completeness, though I was also never under the impression that only Xcode 13.1 would be supported, as the 8.0.27 release notes ( https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-27.html#mysqld-8-0-27-compiling ) and the current reference manual ( https://dev.mysql.com/doc/refman/8.0/en/source-installation-prerequisites.html ) both state that the minimum compiler version required on macOS is “Xcode 10”.

Still, unless someone knowledgable about MySQL’s usage of libevent can say that EVENT__HAVE_WORKING_KQUEUE makes a significant difference to MySQL on macOS, this report can be dismissed.
[13 Dec 2021 12:47] MySQL Verification Team
This is now verified bug, so your questions will be addressed ......
[17 Dec 2021 21:00] Stefan Hinz
Posted by developer:
Fixed in 8.0.29 and 5.7.38.
Compiler flags changed, no changelog entry required.