]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librados/librados_c: check .symver support using cmake 41033/head
authorKefu Chai <kchai@redhat.com>
Tue, 27 Apr 2021 03:15:32 +0000 (11:15 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 2 May 2021 00:16:12 +0000 (08:16 +0800)
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 <kchai@redhat.com>
cmake/modules/CephChecks.cmake
src/include/config-h.in.cmake
src/librados/librados_c.cc

index 376362363f48fc8faecc6f4817def4c5073cbd86..baf9d1f87c72a0e2e62527d72b3058b0c07ddd6c 100644 (file)
@@ -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}
index 66eecda948b63ac3f3a02f618213354b1943c168..993f41730fd532437d1d98aaf1e7ad2b04d00671 100644 (file)
 /* 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
 
index 76014beee715ec9cfda2da3901eb9c5768ec93ec..ae4a0e9dbb50557b7fdffb5e522347fa31d8514c 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <limits.h>
 
+#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)