From ed36936f30525704f71e3b7444c1d25ffe50ab2f Mon Sep 17 00:00:00 2001 From: haozi007 Date: Tue, 12 Sep 2023 10:27:05 +0800 Subject: [PATCH 4/8] support visibility of compiler use visibility for liblcr Signed-off-by: haozi007 --- CMakeLists.txt | 4 +-- src/CMakeLists.txt | 1 + src/runtime/lcrcontainer.h | 68 ++++++++++++++++++++------------------ src/utils/utils_compile.h | 50 ++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 35 deletions(-) create mode 100644 src/utils/utils_compile.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a51ac7d..e00dc96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,8 +117,8 @@ install(FILES ${CMAKE_BINARY_DIR}/conf/lcr.pc DESTINATION ${LIB_INSTALL_DIR_DEFAULT}/pkgconfig PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE WORLD_READ WORLD_EXECUTE) install(FILES ${CMAKE_BINARY_DIR}/conf/libisula.pc DESTINATION ${LIB_INSTALL_DIR_DEFAULT}/pkgconfig PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE WORLD_READ WORLD_EXECUTE) -install(FILES src/runtime/lcrcontainer.h - DESTINATION include/lcr) +install(FILES src/runtime/lcrcontainer.h DESTINATION include/lcr) +install(FILES src/utils/utils_compile.h DESTINATION include/lcr) install(FILES src/third_party/log.h DESTINATION include/isula_libutils) install(FILES src/third_party/go_crc64.h DESTINATION include/isula_libutils) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2bf468f..c423dd7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -124,6 +124,7 @@ target_include_directories(liblcr # set liblcr compile flags set_target_properties(liblcr PROPERTIES PREFIX "") target_link_libraries(liblcr ${check_libs} isula_libutils) +target_compile_options(liblcr PRIVATE -fvisibility=hidden) if (CMAKE_TOOLCHAIN_FILE) target_link_directories(liblcr PUBLIC ${CMAKE_LIBRARY_PATH}) diff --git a/src/runtime/lcrcontainer.h b/src/runtime/lcrcontainer.h index edfc869..6add8c4 100644 --- a/src/runtime/lcrcontainer.h +++ b/src/runtime/lcrcontainer.h @@ -32,13 +32,15 @@ #include #include +#include "utils_compile.h" + #ifdef __cplusplus extern "C" { #endif /* define console log config */ -struct lcr_console_config { +__EXPORT__ struct lcr_console_config { char *log_path; unsigned int log_rotate; char *log_file_size; @@ -47,7 +49,7 @@ struct lcr_console_config { /* * Store lcr container info */ -struct lcr_container_info { +__EXPORT__ struct lcr_container_info { /* Name of container. */ char *name; /* State of container. */ @@ -62,7 +64,7 @@ struct lcr_container_info { bool running; }; -struct blkio_stats { +__EXPORT__ struct blkio_stats { uint64_t read; uint64_t write; uint64_t total; @@ -71,7 +73,7 @@ struct blkio_stats { /* * Store lcr container state */ -struct lcr_container_state { +__EXPORT__ struct lcr_container_state { /* Name of container */ char *name; /* State of container */ @@ -108,14 +110,14 @@ typedef enum { lcr_msg_exit_code, } lcr_msg_type_t; -struct lcr_msg { +__EXPORT__ struct lcr_msg { lcr_msg_type_t type; char name[NAME_MAX + 1]; int value; int pid; }; -struct lcr_cgroup_resources { +__EXPORT__ struct lcr_cgroup_resources { uint64_t blkio_weight; uint64_t cpu_shares; uint64_t cpu_period; @@ -134,23 +136,23 @@ struct lcr_cgroup_resources { * Get one container info for a given lcrpath. * return struct of container info, or NULL on error. */ -struct lcr_container_info *lcr_container_info_get(const char *name, const char *lcrpath); +__EXPORT__ struct lcr_container_info *lcr_container_info_get(const char *name, const char *lcrpath); /* * Free lcr_container_info returned lcr_container_info_get */ -void lcr_container_info_free(struct lcr_container_info *info); +__EXPORT__ void lcr_container_info_free(struct lcr_container_info *info); /* * Get a complete list of all containers for a given lcrpath. * return Number of containers, or -1 on error. */ -int lcr_list_all_containers(const char *lcrpath, struct lcr_container_info **info_arr); +__EXPORT__ int lcr_list_all_containers(const char *lcrpath, struct lcr_container_info **info_arr); /* * Free lcr_container_info array returned by lcr_list_{active,all}_containers */ -void lcr_containers_info_free(struct lcr_container_info **info_arr, size_t size); +__EXPORT__ void lcr_containers_info_free(struct lcr_container_info **info_arr, size_t size); /* * Create a container @@ -158,7 +160,7 @@ void lcr_containers_info_free(struct lcr_container_info **info_arr, size_t size) * param lcrpath : container path * param oci_json_data : json string of oci config data */ -bool lcr_create_from_ocidata(const char *name, const char *lcrpath, const void *oci_json_data); +__EXPORT__ bool lcr_create_from_ocidata(const char *name, const char *lcrpath, const void *oci_json_data); /* * Create a container @@ -166,7 +168,7 @@ bool lcr_create_from_ocidata(const char *name, const char *lcrpath, const void * * param lcrpath : container path * param oci_config : pointer of struct oci config */ -bool lcr_create(const char *name, const char *lcrpath, void *oci_config); +__EXPORT__ bool lcr_create(const char *name, const char *lcrpath, void *oci_config); /* * Start a container @@ -188,7 +190,7 @@ bool lcr_create(const char *name, const char *lcrpath, void *oci_config); * gid : user in which group * additional_gids : Add additional groups to join */ -struct lcr_start_request { +__EXPORT__ struct lcr_start_request { const char *name; const char *lcrpath; @@ -204,7 +206,7 @@ struct lcr_start_request { const char *exit_fifo; bool image_type_oci; }; -bool lcr_start(const struct lcr_start_request *request); +__EXPORT__ bool lcr_start(const struct lcr_start_request *request); /* * Stop a container @@ -212,7 +214,7 @@ bool lcr_start(const struct lcr_start_request *request); * param lcrpath : container path, set to NULL if you want use default lcrpath. * param signal : signal to send to the container. */ -bool lcr_kill(const char *name, const char *lcrpath, uint32_t signal); +__EXPORT__ bool lcr_kill(const char *name, const char *lcrpath, uint32_t signal); /* * Delete a container @@ -220,9 +222,9 @@ bool lcr_kill(const char *name, const char *lcrpath, uint32_t signal); * param lcrpath : container path, set to NULL if you want use default lcrpath. * param force : force to delete container */ -bool lcr_delete(const char *name, const char *lcrpath); +__EXPORT__ bool lcr_delete(const char *name, const char *lcrpath); -bool lcr_clean(const char *name, const char *lcrpath, const char *logpath, const char *loglevel, pid_t pid); +__EXPORT__ bool lcr_clean(const char *name, const char *lcrpath, const char *logpath, const char *loglevel, pid_t pid); /* * Get state of the container @@ -230,26 +232,26 @@ bool lcr_clean(const char *name, const char *lcrpath, const char *logpath, const * param lcrpath : container path, set to NULL if you want use default lcrpath. * param lcs : returned contaiener state */ -bool lcr_state(const char *name, const char *lcrpath, struct lcr_container_state *lcs); +__EXPORT__ bool lcr_state(const char *name, const char *lcrpath, struct lcr_container_state *lcs); /* * Pause a container * param name : container name, required. * param lcrpath : container path, set to NULL if you want use default lcrpath. */ -bool lcr_pause(const char *name, const char *lcrpath); +__EXPORT__ bool lcr_pause(const char *name, const char *lcrpath); /* * Resume a container * param name : container name, required. * param lcrpath : container path, set to NULL if you want use default lcrpath. */ -bool lcr_resume(const char *name, const char *lcrpath); +__EXPORT__ bool lcr_resume(const char *name, const char *lcrpath); /* * Free lcr_container_state returned by lcr_state */ -void lcr_container_state_free(struct lcr_container_state *lcs); +__EXPORT__ void lcr_container_state_free(struct lcr_container_state *lcs); /* * console function @@ -259,7 +261,7 @@ void lcr_container_state_free(struct lcr_container_state *lcs); * param out_fifo : fifo names of output FIFO * Returns false if the console FIFOs add failed, true if success */ -bool lcr_console(const char *name, const char *lcrpath, const char *in_fifo, const char *out_fifo, +__EXPORT__ bool lcr_console(const char *name, const char *lcrpath, const char *in_fifo, const char *out_fifo, const char *err_fifo); /* @@ -268,14 +270,14 @@ bool lcr_console(const char *name, const char *lcrpath, const char *in_fifo, con * param lcrpath : container path, set to NULL if you want use default lcrpath. * param config : use to store container console configs, cannot be NULL */ -bool lcr_get_console_config(const char *name, const char *lcrpath, struct lcr_console_config *config); +__EXPORT__ bool lcr_get_console_config(const char *name, const char *lcrpath, struct lcr_console_config *config); -void lcr_free_console_config(struct lcr_console_config *config); +__EXPORT__ void lcr_free_console_config(struct lcr_console_config *config); -int lcr_log_init(const char *name, const char *file, const char *priority, +__EXPORT__ int lcr_log_init(const char *name, const char *file, const char *priority, const char *prefix, int quiet, const char *lcrpath); -struct lcr_exec_request { +__EXPORT__ struct lcr_exec_request { const char *name; const char *lcrpath; @@ -303,18 +305,18 @@ struct lcr_exec_request { /* * Execute process inside a container */ -bool lcr_exec(const struct lcr_exec_request *request, int *exit_code); +__EXPORT__ bool lcr_exec(const struct lcr_exec_request *request, int *exit_code); -bool lcr_update(const char *name, const char *lcrpath, const struct lcr_cgroup_resources *cr); +__EXPORT__ bool lcr_update(const char *name, const char *lcrpath, const struct lcr_cgroup_resources *cr); -const char *lcr_get_errmsg(); +__EXPORT__ const char *lcr_get_errmsg(); -void lcr_free_errmsg(); +__EXPORT__ void lcr_free_errmsg(); -bool lcr_get_container_pids(const char *name, const char *lcrpath, pid_t **pids, size_t *pids_len); +__EXPORT__ bool lcr_get_container_pids(const char *name, const char *lcrpath, pid_t **pids, size_t *pids_len); -bool lcr_resize(const char *name, const char *lcrpath, unsigned int height, unsigned int width); -bool lcr_exec_resize(const char *name, const char *lcrpath, const char *suffix, unsigned int height, +__EXPORT__ bool lcr_resize(const char *name, const char *lcrpath, unsigned int height, unsigned int width); +__EXPORT__ bool lcr_exec_resize(const char *name, const char *lcrpath, const char *suffix, unsigned int height, unsigned int width); #ifdef __cplusplus } diff --git a/src/utils/utils_compile.h b/src/utils/utils_compile.h new file mode 100644 index 0000000..3bdb24e --- /dev/null +++ b/src/utils/utils_compile.h @@ -0,0 +1,50 @@ +/****************************************************************************** + * isula: compile utils + * + * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. + * + * Authors: + * Haozi007 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ********************************************************************************/ +#ifndef _ISULA_UTILS_UTILS_COMPILE_H +#define _ISULA_UTILS_UTILS_COMPILE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(__GNUC__) && (__GNUC__ >= 4) +#ifndef __HIDDEN__ +#define __HIDDEN__ __attribute__((visibility("hidden"))) +#endif + +#ifndef __EXPORT__ +#define __EXPORT__ __attribute__((visibility("default"))) +#endif + +#else +#define __HIDDEN__ +#ifndef __EXPORT__ +#endif + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _ISULA_UTILS_UTILS_COMPILE_H */ \ No newline at end of file -- 2.34.1