When compiling for AddressSanitizer, prefer the system ucontext or
boost::context co-routine libraries over our custom assembler routines. The
custom routines are not easily annotated with the required AddressSanitizer
__sanitizer_{start,finish}_switch_fiber() functions, while the system
routines should already be so annotated.
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
The non-blocking API has native (assembler) implementations for x86_64,
i386, and (with recent patch) aarch64; these implementations are the most
efficient. For other architectures, a fallback to ucontext is supported.
But ucontext is not the most efficient, and it is not available on all
platforms (it has been deprecated in POSIX). The boost::context library
provides an alternative fallback that is available on more architectures and
should be more efficient than ucontext (if still not quite as fast as the
native support).
This patch adds a CMake option -DWITH_BOOST_CONTEXT=ON that adds
boost::context as a dependency of libmariadb to provide a fallback on
non-natively supported architectures. Boost::context is preferred over
ucontext when both are available.
The option is off by default and must be explicitly enabled by the
user. This avoids introducing a C++ dependency (including dependency
on a C++ compiler and on libstdc++) unless explicitly requested by the
user (libmariadb is otherwise C-only).
Tested-by: Brad Smith <brad@comstyle.com>
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
Implement native my_context for arm64 (aarch64). This is more
efficient than ucontext, and also makes the non-blocking API available
on arm64 platforms that do not have ucontext such as OpenBSD.
Tested-by: Brad Smith <brad@comstyle.com>
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
On macOS, the ucontext functions require _XOPEN_SOURCE to be defined
before including ucontext.h. (Any value is fine, but it's supposed to
be a POSIX-defined number, and 600 seems like the most common choice.)
These functions are required for MYSQL_OPT_NONBLOCK to work on non-x86
platforms, e.g. Apple's M1 chip. This change sets _XOPEN_SOURCE to 600
on Apple platforms during CMake's feature detection and before including
<ucontext.h> in ma_context.h.
Thanks to Evan Miller for reporting this bug and providing the fix.