symbol-visibility
authorSimon Quigley <tsimonq2@debian.org>
Sat, 13 Nov 2021 20:48:59 +0000 (20:48 +0000)
committerGianfranco Costamagna <locutusofborg@debian.org>
Sat, 13 Nov 2021 20:48:59 +0000 (20:48 +0000)
commit df9206778fe9ff1bdd56d975c29c43dfe1e66de7
Author: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
Date:   Fri Nov 23 15:26:53 2018 +1100

    Export only YAML_CPP_API-tagged symbols on Linux.

    This marks classes tagged with YAML_CPP_API with visibility("default"), to
    explicitly export them, and then makes the default visibility "hidden" via
    -fvisibility=hidden.

    This reduces the number of exported symbols by more than 50%, which has
    a small application start-up time and memory useage benefit. It also
    makes it more feasible to audit the set of exported symbols in automated
    ABI compatibility systems.

Gbp-Pq: Name symbol-visibility.patch

CMakeLists.txt
include/yaml-cpp/dll.h

index b230b9e6de2cbbcbe5440aff2edd5f5627b577d5..78f5221661d6a9230defbd0d49a61bdb995ca585 100644 (file)
@@ -43,6 +43,14 @@ set(build-windows-dll $<AND:$<BOOL:${CMAKE_HOST_WIN32}>,${build-shared}>)
 set(not-msvc $<NOT:$<CXX_COMPILER_ID:MSVC>>)
 set(msvc-shared_rt $<BOOL:${YAML_MSVC_SHARED_RT}>)
 
+if(CMAKE_SYSTEM_NAME MATCHES "Linux")
+   set(CMAKE_CXX_VISIBILITY_PRESET hidden)
+   if (POLICY CMP0063)
+       cmake_policy(SET CMP0063 NEW)
+   endif()
+   add_definitions(-DYAML_CPP_USE_VISIBILITY)
+endif()
+
 if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
   set(CMAKE_MSVC_RUNTIME_LIBRARY
     MultiThreaded$<$<CONFIG:Debug>:Debug>$<${msvc-shared_rt}:DLL>)
index a32c06b2e308aa0512137ba763ff5f7247ae1b18..5b8c9058ed69cd6ee0f2cb010eb28c2f7615c208 100644 (file)
 #define YAML_CPP_API __declspec(dllimport)
 #endif  // yaml_cpp_EXPORTS
 #else   // YAML_CPP_DLL
+#ifdef YAML_CPP_USE_VISIBILITY
+#define YAML_CPP_API __attribute__ ((visibility("default")))
+#else
 #define YAML_CPP_API
+#endif // YAML_CPP_USE_VISIBILITY
 #endif  // YAML_CPP_DLL
 
 #endif  // DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66