This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/bundle_linker_script in repository https://gitbox.apache.org/repos/asf/celix.git
commit 6b7a80e0104f022b58a969e078cfde3de0cf6c46 Author: Pepijn Noltes <pnol...@apache.org> AuthorDate: Sun Apr 30 23:06:23 2023 +0200 Default hide symbols for bundle (activator) libs --- bundles/logging/log_helper/CMakeLists.txt | 1 + cmake/cmake_celix/BundlePackaging.cmake | 78 +++------------------- cmake/cmake_celix/Generic.cmake | 57 ++++++++++++++++ documents/bundles.md | 16 ++--- documents/cmake_commands/README.md | 50 +++++++------- .../readme_c_examples/CMakeLists.txt | 6 +- libs/framework/include/celix_bundle_activator.h | 16 +++-- 7 files changed, 113 insertions(+), 111 deletions(-) diff --git a/bundles/logging/log_helper/CMakeLists.txt b/bundles/logging/log_helper/CMakeLists.txt index 2014a8e4..c180014c 100644 --- a/bundles/logging/log_helper/CMakeLists.txt +++ b/bundles/logging/log_helper/CMakeLists.txt @@ -39,6 +39,7 @@ install(TARGETS log_helper EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMP INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/log_helper) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/log_helper COMPONENT logging) +celix_target_hide_symbols(log_helper) celix_deprecated_utils_headers(log_helper) celix_deprecated_framework_headers(log_helper) diff --git a/cmake/cmake_celix/BundlePackaging.cmake b/cmake/cmake_celix/BundlePackaging.cmake index 19e7cfd1..ee6d7864 100644 --- a/cmake/cmake_celix/BundlePackaging.cmake +++ b/cmake/cmake_celix/BundlePackaging.cmake @@ -122,6 +122,7 @@ add_celix_bundle(<bundle_target_name> [FILENAME bundle_filename] [PRIVATE_LIBRARIES private_lib1 private_lib2 ...] [HEADERS "header1: header1_value" "header2: header2_value" ...] + [DO_NOT_CONFIGURE_SYMBOL_VISIBILITY] ) ``` @@ -136,6 +137,7 @@ add_celix_bundle(<bundle_target_name> [FILENAME bundle_filename] [PRIVATE_LIBRARIES private_lib1 private_lib2 ...] [HEADERS "header1: header1_value" "header2: header2_value" ...] + [DO_NOT_CONFIGURE_SYMBOL_VISIBILITY] ) ``` @@ -150,6 +152,7 @@ add_celix_bundle(<bundle_target_name> [FILENAME bundle_filename] [PRIVATE_LIBRARIES private_lib1 private_lib2 ...] [HEADERS "header1: header1_value" "header2: header2_value" ...] + [DO_NOT_CONFIGURE_SYMBOL_VISIBILITY] ) ``` @@ -173,12 +176,13 @@ Optional arguments are: - FILENAME: The filename of the bundle file, without extension. Default is <bundle_target_name>. Together with the BUILD_TYPE, this will result in a filename like "bundle_target_name_Debug.zip - PRIVATE_LIBRARIES: private libraries to be included in the bundle. Specified libraries are added to the "Private-Library" manifest statement and added in the root of the bundle. libraries can be cmake library targets or absolute paths to existing libraries. - HEADERS: Additional headers values that are appended to the bundle manifest. +- DO_NOT_CONFIGURE_SYMBOL_VISIBILITY: By default the bundle library will be build with symbol visibility configuration preset set to hidden. This can be disabled by providing this option. ]] function(add_celix_bundle) list(GET ARGN 0 BUNDLE_TARGET_NAME) list(REMOVE_AT ARGN 0) - set(OPTIONS NO_ACTIVATOR) + set(OPTIONS NO_ACTIVATOR DO_NOT_CONFIGURE_SYMBOL_VISIBILITY) set(ONE_VAL_ARGS VERSION ACTIVATOR SYMBOLIC_NAME NAME DESCRIPTION FILENAME GROUP) set(MULTI_VAL_ARGS SOURCES PRIVATE_LIBRARIES EXPORT_LIBRARIES IMPORT_LIBRARIES HEADERS) cmake_parse_arguments(BUNDLE "${OPTIONS}" "${ONE_VAL_ARGS}" "${MULTI_VAL_ARGS}" ${ARGN}) @@ -360,6 +364,10 @@ function(add_celix_bundle) else() set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN") endif() + + if (NOT BUNDLE_DO_NOT_CONFIGURE_SYMBOL_VISIBILITY) + celix_target_hide_symbols(${BUNDLE_TARGET_NAME}) + endif () elseif(BUNDLE_NO_ACTIVATOR) #do nothing else() #ACTIVATOR @@ -944,74 +952,6 @@ function(celix_get_bundle_file) endif () endfunction () -#[[ -Configure the symbol visibility preset of the bundle library to hidden. - -This is done by setting the target properties C_VISIBILITY_PRESET to hidden, the CXX_VISIBILITY_PRESET to hidden and -VISIBILITY_INLINES_HIDDEN to ON. - -```CMake -celix_bundle_hide_symbols(<bundle_target> [RELEASE] [DEBUG] [RELWITHDEBINFO] [MINSIZEREL]) -``` - -Optional arguments are: -- RELEASE: hide symbols for the release build type -- DEBUG: hide symbols for the debug build type -- RELWITHDEBINFO: hide symbols for the relwithdebinfo build type -- MINSIZEREL: hide symbols for the minsizerel build type - -If no optional arguments are provided, the symbols are hidden for all build types. - -Example: -```CMake -celix_bundle_hide_symbols(my_bundle RELEASE MINSIZEREL) -``` -]] -function(celix_bundle_hide_symbols) - list(GET ARGN 0 BUNDLE_TARGET) - list(REMOVE_AT ARGN 0) - - set(OPTIONS RELEASE DEBUG RELWITHDEBINFO MINSIZEREL) - cmake_parse_arguments(HIDE_SYMBOLS "${OPTIONS}" "" "" ${ARGN}) - - set(BUILD_TYPE "") - if (CMAKE_BUILD_TYPE) - string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE) - endif () - - set(HIDE_SYMBOLS FALSE) - if (NOT HIDE_SYMBOLS_RELEASE AND NOT HIDE_SYMBOLS_DEBUG AND NOT HIDE_SYMBOLS_RELWITHDEBINFO AND NOT HIDE_SYMBOLS_MINSIZEREL) - set(HIDE_SYMBOLS TRUE) - elseif (HIDE_SYMBOLS_RELEASE AND BUILD_TYPE STREQUAL "RELEASE") - set(HIDE_SYMBOLS TRUE) - elseif (HIDE_SYMBOLS_DEBUG AND BUILD_TYPE STREQUAL "DEBUG") - set(HIDE_SYMBOLS TRUE) - elseif (HIDE_SYMBOLS_RELWITHDEBINFO AND BUILD_TYPE STREQUAL "RELWITHDEBINFO") - set(HIDE_SYMBOLS TRUE) - elseif (HIDE_SYMBOLS_MINSIZEREL AND BUILD_TYPE STREQUAL "MINSIZEREL") - set(HIDE_SYMBOLS TRUE) - endif () - - if (HIDE_SYMBOLS) - set_target_properties(${BUNDLE_TARGET} - PROPERTIES - C_VISIBILITY_PRESET hidden - CXX_VISIBILITY_PRESET hidden - VISIBILITY_INLINES_HIDDEN ON) -# if("${CMAKE_C_COMPILER_ID}" MATCHES "Clang") -# target_link_options(${BUNDLE_TARGET} PRIVATE "LINKER:-exported_symbols_list,${CELIX_CMAKE_DIRECTORY}/templates/make_only_activator_symbols_global.list") -# set_target_properties(${BUNDLE_TARGET} -# PROPERTIES -# C_VISIBILITY_PRESET hidden -# CXX_VISIBILITY_PRESET hidden) -# elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") -# target_link_options(${BUNDLE_TARGET} PRIVATE "LINKER:--version-script=${CELIX_CMAKE_DIRECTORY}/templates/make_only_activator_symbols_global.map") -# else () -# message(WARNING "Cannot hide symbols for bundle ${BUNDLE_TARGET}, unsupported linker") -# endif () - endif () -endfunction() - function(install_bundle) message(DEPRECATION "install_bundle is deprecated, use install_celix_bundle instead.") install_celix_bundle(${ARGN}) diff --git a/cmake/cmake_celix/Generic.cmake b/cmake/cmake_celix/Generic.cmake index 6f51e258..0dff334d 100644 --- a/cmake/cmake_celix/Generic.cmake +++ b/cmake/cmake_celix/Generic.cmake @@ -248,3 +248,60 @@ function(celix_target_bundle_set_definition) target_compile_definitions(${TARGET_NAME} PRIVATE ${BUNDLE_SET_NAME}=\"${BUNDLES}\") endfunction() + +#[[ +Configure the symbol visibility preset of the provided target to hidden. + +This is done by setting the target properties C_VISIBILITY_PRESET to hidden, the CXX_VISIBILITY_PRESET to hidden and +VISIBILITY_INLINES_HIDDEN to ON. + +```CMake +celix_target_hide_symbols(<cmake_target> [RELEASE] [DEBUG] [RELWITHDEBINFO] [MINSIZEREL]) +``` + +Optional arguments are: +- RELEASE: hide symbols for the release build type +- DEBUG: hide symbols for the debug build type +- RELWITHDEBINFO: hide symbols for the relwithdebinfo build type +- MINSIZEREL: hide symbols for the minsizerel build type + +If no optional arguments are provided, the symbols are hidden for all build types. + +Example: +```CMake +celix_target_hide_symbols(my_bundle RELEASE MINSIZEREL) +``` +]] +function(celix_target_hide_symbols) + list(GET ARGN 0 BUNDLE_TARGET) + list(REMOVE_AT ARGN 0) + + set(OPTIONS RELEASE DEBUG RELWITHDEBINFO MINSIZEREL) + cmake_parse_arguments(HIDE_SYMBOLS "${OPTIONS}" "" "" ${ARGN}) + + set(BUILD_TYPE "") + if (CMAKE_BUILD_TYPE) + string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE) + endif () + + set(HIDE_SYMBOLS FALSE) + if (NOT HIDE_SYMBOLS_RELEASE AND NOT HIDE_SYMBOLS_DEBUG AND NOT HIDE_SYMBOLS_RELWITHDEBINFO AND NOT HIDE_SYMBOLS_MINSIZEREL) + set(HIDE_SYMBOLS TRUE) + elseif (HIDE_SYMBOLS_RELEASE AND BUILD_TYPE STREQUAL "RELEASE") + set(HIDE_SYMBOLS TRUE) + elseif (HIDE_SYMBOLS_DEBUG AND BUILD_TYPE STREQUAL "DEBUG") + set(HIDE_SYMBOLS TRUE) + elseif (HIDE_SYMBOLS_RELWITHDEBINFO AND BUILD_TYPE STREQUAL "RELWITHDEBINFO") + set(HIDE_SYMBOLS TRUE) + elseif (HIDE_SYMBOLS_MINSIZEREL AND BUILD_TYPE STREQUAL "MINSIZEREL") + set(HIDE_SYMBOLS TRUE) + endif () + + if (HIDE_SYMBOLS) + set_target_properties(${BUNDLE_TARGET} + PROPERTIES + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN ON) + endif () +endfunction() \ No newline at end of file diff --git a/documents/bundles.md b/documents/bundles.md index 6ad1b36c..393df83e 100644 --- a/documents/bundles.md +++ b/documents/bundles.md @@ -241,6 +241,7 @@ In Apache Celix symbols are kept private by loading bundle libraries locally (`d ## Symbol visibility for bundles Bundles cannot directly access the symbols of another bundle and therefore the symbols of the bundle activator library can be hidden with exception of the bundle activator create, start, stop and destroy functions. +The celix_bundle_activator.h header file ensures that the bundle activator symbols are exported. The benefits of hiding symbols for a bundle are: - Smaller bundle libraries; @@ -255,23 +256,16 @@ For C++ this is only the case if the provided services is based on a C++ header- the case, because C service structs does not result in any symbols. By default, the symbol visibility preset of the bundle activator library is configured to hidden. -This can be changed by providing the`DO_NOT_CONFIGURE_SYMBOL_VISIBILTY` option in the `add_celix_bundle` CMake +This can be changed by providing the`DO_NOT_CONFIGURE_SYMBOL_VISIBILITY` option in the `add_celix_bundle` CMake function call. -TODO -The default symbol visibility configuration for bundles can be changed by setting -the `CELIX_CONFIGURE_BUNDLE_SYMBOL_VISIBILITY_TO_HIDDEN` CMake variable. The default value is `ON`. -TODO - -The celix_bundle_activator.h header file ensures that the bundle activator symbols are exported. - -### Hiding symbols with celix_bundle_hide_symbols example +### Example of disabling hiding of symbols for a bundle ```CMake -add_celix_bundle(my_bundle_hide_symbols +add_celix_bundle(my_bundle_do_not_hide_symbols VERSION 1.0.0 SOURCES src/my_bundle_activator.c + DO_NOT_CONFIGURE_SYMBOL_VISIBILITY ) -celix_bundle_hide_symbols(my_bundle_hide_symbols) ``` ## Installing bundles diff --git a/documents/cmake_commands/README.md b/documents/cmake_commands/README.md index b55d1513..140bc1a4 100644 --- a/documents/cmake_commands/README.md +++ b/documents/cmake_commands/README.md @@ -41,6 +41,7 @@ add_celix_bundle(<bundle_target_name> [FILENAME bundle_filename] [PRIVATE_LIBRARIES private_lib1 private_lib2 ...] [HEADERS "header1: header1_value" "header2: header2_value" ...] + [DO_NOT_CONFIGURE_SYMBOL_VISIBILITY] ) ``` @@ -55,6 +56,7 @@ add_celix_bundle(<bundle_target_name> [FILENAME bundle_filename] [PRIVATE_LIBRARIES private_lib1 private_lib2 ...] [HEADERS "header1: header1_value" "header2: header2_value" ...] + [DO_NOT_CONFIGURE_SYMBOL_VISIBILITY] ) ``` @@ -69,6 +71,7 @@ add_celix_bundle(<bundle_target_name> [FILENAME bundle_filename] [PRIVATE_LIBRARIES private_lib1 private_lib2 ...] [HEADERS "header1: header1_value" "header2: header2_value" ...] + [DO_NOT_CONFIGURE_SYMBOL_VISIBILITY] ) ``` @@ -92,6 +95,7 @@ Optional arguments are: - FILENAME: The filename of the bundle file, without extension. Default is <bundle_target_name>. Together with the BUILD_TYPE, this will result in a filename like "bundle_target_name_Debug.zip - PRIVATE_LIBRARIES: private libraries to be included in the bundle. Specified libraries are added to the "Private-Library" manifest statement and added in the root of the bundle. libraries can be cmake library targets or absolute paths to existing libraries. - HEADERS: Additional headers values that are appended to the bundle manifest. +- DO_NOT_CONFIGURE_SYMBOL_VISIBILITY: By default the bundle library will be build with symbol visibility configuration preset set to hidden. This can be disabled by providing this option. ## celix_bundle_private_libs Add libraries to a bundle. @@ -275,29 +279,6 @@ Example: celix_get_bundle_file(Celix::shell SHELL_BUNDLE_FILE) ``` -## celix_bundle_hide_symbols -Configure the symbol visibility preset of the bundle library to hidden. - -This is done by setting the target properties C_VISIBILITY_PRESET to hidden, the CXX_VISIBILITY_PRESET to hidden and -VISIBILITY_INLINES_HIDDEN to ON. - -```CMake -celix_bundle_hide_symbols(<bundle_target> [RELEASE] [DEBUG] [RELWITHDEBINFO] [MINSIZEREL]) -``` - -Optional arguments are: -- RELEASE: hide symbols for the release build type -- DEBUG: hide symbols for the debug build type -- RELWITHDEBINFO: hide symbols for the relwithdebinfo build type -- MINSIZEREL: hide symbols for the minsizerel build type - -If no optional arguments are provided, the symbols are hidden for all build types. - -Example: -```CMake -celix_bundle_hide_symbols(my_bundle RELEASE MINSIZEREL) -``` - ## install_celix_bundle Install bundle when 'make install' is executed. @@ -708,3 +689,26 @@ The bundle set can be installed using the Celix framework util function `celix_f or `celix::installBundleSet` (C++). Adding a compile-definition with a set of bundles can be useful for testing purpose. + +## celix_target_hide_symbols +Configure the symbol visibility preset of the provided target to hidden. + +This is done by setting the target properties C_VISIBILITY_PRESET to hidden, the CXX_VISIBILITY_PRESET to hidden and +VISIBILITY_INLINES_HIDDEN to ON. + +```CMake +celix_target_hide_symbols(<cmake_target> [RELEASE] [DEBUG] [RELWITHDEBINFO] [MINSIZEREL]) +``` + +Optional arguments are: +- RELEASE: hide symbols for the release build type +- DEBUG: hide symbols for the debug build type +- RELWITHDEBINFO: hide symbols for the relwithdebinfo build type +- MINSIZEREL: hide symbols for the minsizerel build type + +If no optional arguments are provided, the symbols are hidden for all build types. + +Example: +```CMake +celix_target_hide_symbols(my_bundle RELEASE MINSIZEREL) +``` \ No newline at end of file diff --git a/examples/celix-examples/readme_c_examples/CMakeLists.txt b/examples/celix-examples/readme_c_examples/CMakeLists.txt index d8c08ec3..6ea7c06d 100644 --- a/examples/celix-examples/readme_c_examples/CMakeLists.txt +++ b/examples/celix-examples/readme_c_examples/CMakeLists.txt @@ -25,11 +25,11 @@ add_celix_bundle(my_bundle SOURCES src/my_bundle_activator.c ) -add_celix_bundle(my_bundle_hide_symbols +add_celix_bundle(my_bundle_do_not_hide_symbols VERSION 1.0.0 SOURCES src/my_bundle_activator.c + DO_NOT_CONFIGURE_SYMBOL_VISIBILITY ) -celix_bundle_hide_symbols(my_bundle_hide_symbols) #With `make all`, `make celix-containers` or `make my_container` this Celix container executable will be created at: # ${CMAKE_BINARY_DIR}/deploy/my_container/my_container @@ -39,7 +39,7 @@ add_celix_container(my_container Celix::shell Celix::shell_tui my_bundle - my_bundle_hide_symbols + my_bundle_do_not_hide_symbols ) add_celix_bundle(my_shell_command_provider_bundle diff --git a/libs/framework/include/celix_bundle_activator.h b/libs/framework/include/celix_bundle_activator.h index efa9ff75..d90c6baa 100644 --- a/libs/framework/include/celix_bundle_activator.h +++ b/libs/framework/include/celix_bundle_activator.h @@ -27,7 +27,13 @@ #include "celix_dm_component.h" #include "celix_dm_service_dependency.h" #include "celix_constants.h" -#include "celix_framework_export.h" + +#if defined(__linux__) || defined(__APPLE__) +//always export bundle activator symbols +#define CELIX_BUNDLE_ACTIVATOR_EXPORT __attribute__((visibility("default"))) +#else +#define CELIX_BUNDLE_ACTIVATOR_EXPORT +#endif #ifdef __cplusplus extern "C" { @@ -48,7 +54,7 @@ extern "C" { * - Any other status code will mark the bundle as stopped and the framework will remove this * bundle's listeners, unregister all services, and release all services used by this bundle. */ -CELIX_FRAMEWORK_EXPORT celix_status_t celix_bundleActivator_create(celix_bundle_context_t *ctx, void **userData); +CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_create(celix_bundle_context_t *ctx, void **userData); /** * @brief Called when this bundle is started so the Framework can perform the bundle-specific activities necessary @@ -67,7 +73,7 @@ CELIX_FRAMEWORK_EXPORT celix_status_t celix_bundleActivator_create(celix_bundle_ * - Any other status code will mark the bundle as stopped and the framework will remove this * bundle's listeners, unregister all services, and release all services used by this bundle. */ -CELIX_FRAMEWORK_EXPORT celix_status_t celix_bundleActivator_start(void *userData, celix_bundle_context_t *ctx); +CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_start(void *userData, celix_bundle_context_t *ctx); /** * @brief Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary @@ -88,7 +94,7 @@ CELIX_FRAMEWORK_EXPORT celix_status_t celix_bundleActivator_start(void *userData * - Any other status code will mark the bundle as stopped and the framework will remove this * bundle's listeners, unregister all services, and release all services used by this bundle. */ -CELIX_FRAMEWORK_EXPORT celix_status_t celix_bundleActivator_stop(void *userData, celix_bundle_context_t *ctx); +CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_stop(void *userData, celix_bundle_context_t *ctx); /** * @brief Called when this bundle is stopped so the bundle can destroy the instance of its activator. @@ -106,7 +112,7 @@ CELIX_FRAMEWORK_EXPORT celix_status_t celix_bundleActivator_stop(void *userData, * - Any other status code will mark the bundle as stopped and the framework will remove this * bundle's listeners, unregister all services, and release all services used by this bundle. */ -CELIX_FRAMEWORK_EXPORT celix_status_t celix_bundleActivator_destroy(void *userData, celix_bundle_context_t* ctx); +CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_destroy(void *userData, celix_bundle_context_t* ctx); /** * @brief This macro generates the required bundle activator functions for C.