From: Kefu Chai Date: Tue, 27 Apr 2021 03:15:32 +0000 (+0800) Subject: librados/librados_c: check .symver support using cmake X-Git-Tag: v17.1.0~2082^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d0858dbfb4b76a6e3d0b6001316e0f08703f3a26;p=ceph.git librados/librados_c: check .symver support using cmake the __asm__(".asmver ..") is a support provided by the compiler, so would be better to detect it by either checking the compiler identifer or just try it out. in this change, instead of checking the building platform, we check this feature using check_c_source_compiles(). in future, we could support versioned symbols using function attriubte or symbol tables or version-script. on platform where symbol versioning is not supported, we might need to go with a different approach. Signed-off-by: Kefu Chai --- diff --git a/cmake/modules/CephChecks.cmake b/cmake/modules/CephChecks.cmake index 376362363f4..baf9d1f87c7 100644 --- a/cmake/modules/CephChecks.cmake +++ b/cmake/modules/CephChecks.cmake @@ -145,6 +145,21 @@ else(NOT CMAKE_CROSSCOMPILING) message(STATUS "Assuming unaligned access is supported") endif(NOT CMAKE_CROSSCOMPILING) +set(version_script_source "v1 { }; v2 { } v1;") +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/version_script.txt "${version_script_source}") +cmake_push_check_state(RESET) +set(CMAKE_REQUIRED_FLAGS -Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/version_script.txt) +check_c_source_compiles(" +void func_v1() {} +__asm__(\".symver func_v1, func@v1\"); +void func_v2() {} +__asm__(\".symver func_v2, func@v2\"); + +int main() {}" + HAVE_ASM_SYMVER) +file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/version_script.txt) +cmake_pop_check_state() + # should use LINK_OPTIONS instead of LINK_LIBRARIES, if we can use cmake v3.14+ try_compile(HAVE_LINK_VERSION_SCRIPT ${CMAKE_CURRENT_BINARY_DIR} diff --git a/src/include/config-h.in.cmake b/src/include/config-h.in.cmake index 66eecda948b..993f41730fd 100644 --- a/src/include/config-h.in.cmake +++ b/src/include/config-h.in.cmake @@ -277,6 +277,9 @@ /* Define if the C compiler supports __PRETTY_FUNCTION__ */ #cmakedefine HAVE_PRETTY_FUNC +/* Define if the C compiler supports __asm__(".symver ..") */ +#cmakedefine HAVE_ASM_SYMVER + /* Have eventfd extension. */ #cmakedefine HAVE_EVENTFD diff --git a/src/librados/librados_c.cc b/src/librados/librados_c.cc index 76014beee71..ae4a0e9dbb5 100644 --- a/src/librados/librados_c.cc +++ b/src/librados/librados_c.cc @@ -3,6 +3,7 @@ #include +#include "acconfig.h" #include "common/config.h" #include "common/errno.h" #include "common/ceph_argparse.h" @@ -42,7 +43,7 @@ #define tracepoint(...) #endif -#ifndef _WIN32 +#ifdef HAVE_ASM_SYMVER #define LIBRADOS_C_API_BASE(fn) \ asm(".symver _" #fn "_base, " #fn "@") #define LIBRADOS_C_API_BASE_DEFAULT(fn) \ @@ -53,9 +54,6 @@ #define LIBRADOS_C_API_BASE_F(fn) _ ## fn ## _base #define LIBRADOS_C_API_DEFAULT_F(fn) _ ## fn #else -// symver cannot be used on Windows. We'll only be able -// to support one version, unless we use a different -// versioning approach. #define LIBRADOS_C_API_BASE(fn) #define LIBRADOS_C_API_BASE_DEFAULT(fn) #define LIBRADOS_C_API_DEFAULT(fn, ver)