]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librados/librados_c: check .symver support using cmake
authorKefu Chai <kchai@redhat.com>
Tue, 27 Apr 2021 03:15:32 +0000 (11:15 +0800)
committerKefu Chai <tchaikov@gmail.com>
Wed, 31 Aug 2022 12:36:53 +0000 (20:36 +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>
(cherry picked from commit d0858dbfb4b76a6e3d0b6001316e0f08703f3a26)

cmake/modules/CephChecks.cmake
src/include/config-h.in.cmake
src/librados/librados_c.cc

index 6a9483f1a75c12bb92843d7e96c504cd7ddde3d5..6101426673d2643ff57f2ff0d8f10e4531a5d0fb 100644 (file)
@@ -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}
index 155f9df6d1cb5ea5991e4e2f10e930e95ca2c77e..8ca934ab0b2d8ebdbb58042570f91531c151f66a 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 8ee2f940171468500cf3cf51d78337aaaf2394ef..88dad8f6bd1df6d236884067e4193dcb5f4a8d6a 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)               \
   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)