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: v16.2.11~358^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b6b1b1eb04cb7d01c110c0ea98792223ee188fe4;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 (cherry picked from commit d0858dbfb4b76a6e3d0b6001316e0f08703f3a26) --- diff --git a/cmake/modules/CephChecks.cmake b/cmake/modules/CephChecks.cmake index 6a9483f1a75..6101426673d 100644 --- a/cmake/modules/CephChecks.cmake +++ b/cmake/modules/CephChecks.cmake @@ -144,6 +144,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 155f9df6d1c..8ca934ab0b2 100644 --- a/src/include/config-h.in.cmake +++ b/src/include/config-h.in.cmake @@ -271,6 +271,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 8ee2f940171..88dad8f6bd1 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) \ extern __typeof (_##fn##_base) _##fn##_base __attribute__((__symver__ (#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)