[COMMIT seastar master] Merge 'build: detect glibc features using CMake ' from Kefu Chai

150 views
Skip to first unread message

Commit Bot

<bot@cloudius-systems.com>
unread,
Sep 28, 2023, 10:01:10 AM9/28/23
to seastar-dev@googlegroups.com, Avi Kivity
From: Avi Kivity <a...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>
Branch: master

Merge 'build: detect glibc features using CMake ' from Kefu Chai

in this series, instead of checking `__GLIBC__` macro for some glibc specific behavior, we check the behavior directly using CMake. this should improve the maintainability.

Closes scylladb/seastar#1852

* github.com:scylladb/seastar:
build: detect glibc features using CMake
build: extract bits checking libc into CheckLibc.cmake

---
diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1021,17 +1021,7 @@ if (Seastar_DEBUG_SHARED_PTR IN_LIST True_STRING_VALUES OR
SEASTAR_DEBUG_SHARED_PTR)
endif ()

-include (CheckCXXSourceCompiles)
-file (READ ${CMAKE_CURRENT_LIST_DIR}/cmake/code_tests/stdout_test.cc _stdout_test_code)
-check_cxx_source_compiles ("${_stdout_test_code}" Stdout_Can_Be_Used_As_Identifier)
-if (Stdout_Can_Be_Used_As_Identifier)
- # "stdout" is defined as a macro by the C++ standard, so we cannot assume
- # that the macro is always expanded into an identifier which can be re-used
- # to name a enumerator in the declaration of an enumeration.
- target_compile_definitions (seastar
- PUBLIC
- SEASTAR_LOGGER_TYPE_STDOUT)
-endif ()
+include (CheckLibc)

set (Seastar_STACK_GUARD_MODES "Debug" "Sanitize" "Dev")
if ((Seastar_STACK_GUARDS STREQUAL "ON") OR
diff --git a/cmake/CheckLibc.cmake b/cmake/CheckLibc.cmake
--- a/cmake/CheckLibc.cmake
+++ b/cmake/CheckLibc.cmake
@@ -0,0 +1,31 @@
+# check for the bits in different standard C library implementations we
+# care about
+
+include (CheckCXXSourceCompiles)
+file (READ ${CMAKE_CURRENT_LIST_DIR}/code_tests/stdout_test.cc _stdout_test_code)
+check_cxx_source_compiles ("${_stdout_test_code}" Stdout_Can_Be_Used_As_Identifier)
+if (Stdout_Can_Be_Used_As_Identifier)
+ # "stdout" is defined as a macro by the C++ standard, so we cannot assume
+ # that the macro is always expanded into an identifier which can be re-used
+ # to name a enumerator in the declaration of an enumeration.
+ target_compile_definitions (seastar
+ PUBLIC
+ SEASTAR_LOGGER_TYPE_STDOUT)
+endif ()
+
+check_cxx_source_compiles ("
+#include <string.h>
+
+int main() {
+ char buf;
+ char* a = strerror_r(1, &buf, 0);
+ static_cast<void>(a);
+}"
+ Strerror_R_Returns_Char_P)
+if (Strerror_R_Returns_Char_P)
+ # define SEASTAR_STRERROR_R_CHAR_P if strerror_r() is GNU-specific version,
+ # which returns a "char*" not "int".
+ target_compile_definitions (seastar
+ PRIVATE
+ SEASTAR_STRERROR_R_CHAR_P)
+endif ()
diff --git a/src/core/linux-aio.cc b/src/core/linux-aio.cc
--- a/src/core/linux-aio.cc
+++ b/src/core/linux-aio.cc
@@ -33,7 +33,6 @@ module;
#include <unistd.h>
#include <sys/syscall.h>
#include <valgrind/valgrind.h>
-#include <features.h>

#ifdef SEASTAR_MODULE
module seastar;
@@ -172,7 +171,7 @@ void setup_aio_context(size_t nr, linux_abi::aio_context_t* io_context) {
auto r = io_setup(nr, io_context);
if (r < 0) {
char buf[1024];
-#ifdef __GLIBC__
+#ifdef SEASTAR_STRERROR_R_CHAR_P
const char *msg = strerror_r(errno, buf, sizeof(buf));
#else
const char *msg = strerror_r(errno, buf, sizeof(buf)) ? "unknown error" : buf;
diff --git a/src/core/memory.cc b/src/core/memory.cc
--- a/src/core/memory.cc
+++ b/src/core/memory.cc
@@ -69,7 +69,6 @@ module;
#include <boost/container/static_vector.hpp>

#include <dlfcn.h>
-#include <features.h>

#ifndef SEASTAR_DEFAULT_ALLOCATOR
#include <new>
@@ -1609,7 +1608,7 @@ configure(std::vector<resource::memory> m, bool mbind,

if (r == -1) {
char err[1000] = {};
-#ifdef __GLIBC__
+#ifdef SEASTAR_STRERROR_R_CHAR_P
const char *msg = strerror_r(errno, err, sizeof(err));
#else
const char *msg = strerror_r(errno, err, sizeof(err)) ? "unknown error" : buf;
Reply all
Reply to author
Forward
0 new messages