From 3d034ba9c64588d20bc670c868fe7a03a8cc6667 Mon Sep 17 00:00:00 2001 From: fengzero Date: Mon, 9 Aug 2021 07:41:52 +0000 Subject: [PATCH] OS X support AddressSanitizer --- CMakeLists.txt | 9 +++------ src/core/neu_manager.c | 21 ++++++++++++++------- src/core/plugin_manager.c | 4 ++-- src/core/plugin_manager.h | 2 +- tests/plugins/mqtt/CMakeLists.txt | 2 +- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e4c1104..4e9ed3a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,19 +13,16 @@ endif() set(CMAKE_C_FLAGS "$ENV{CFLAGS} -Wall -Wextra") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O2") -if(APPLE) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -O0 -fsanitize=address \ -fsanitize-recover=address -fsanitize-address-use-after-scope \ - -fno-stack-protector -fno-omit-frame-pointer -fno-var-tracking -static-libsan" + -fno-stack-protector -fno-omit-frame-pointer -fno-var-tracking" ) -else() set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -O0 -fsanitize=address \ -fsanitize-recover=address -fsanitize-address-use-after-scope \ - -fno-stack-protector -fno-omit-frame-pointer -fno-var-tracking -static-libasan" + -fno-stack-protector -fno-omit-frame-pointer -fno-var-tracking" ) -endif() if(NOT DEFINED CMAKE_SUPPRESS_DEVELOPER_WARNINGS) set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS @@ -94,7 +91,7 @@ add_library(neuron-base SHARED) target_sources(neuron-base PRIVATE ${NEURON_BASE_SOURCES}) target_include_directories(neuron-base PRIVATE ${NEURON_BASE_INCLUDE_DIRECTORIES}) -target_link_libraries(neuron-base vector-static jansson ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(neuron-base paho-mqtt3as vector-static jansson ssl crypto ${CMAKE_THREAD_LIBS_INIT}) # define for plugins set(SAMPLE_PLUGIN_SOURCES plugins/plugin_sample.c) diff --git a/src/core/neu_manager.c b/src/core/neu_manager.c index 27a54066..3b006af1 100644 --- a/src/core/neu_manager.c +++ b/src/core/neu_manager.c @@ -562,10 +562,11 @@ static int manager_stop_adapter(neu_manager_t *manager, neu_adapter_t *adapter) // Call this function before start manager loop, so it don't need lock static int register_default_plugins(neu_manager_t *manager) { - int rv = 0; - uint32_t i, j; - plugin_id_t plugin_id; - const plugin_reg_param_t *reg_param; + int rv = 0; + uint32_t i, j; + plugin_id_t plugin_id; + plugin_reg_param_t reg_param; + int path_len = 64; for (i = 0; i < DEFAULT_PLUGIN_COUNT; i++) { plugin_id.id_val = 0; @@ -577,13 +578,19 @@ static int register_default_plugins(neu_manager_t *manager) } if (j < SYSTEM_PLUGIN_INFO_SIZE) { - reg_param = &system_plugin_infos[j]; + reg_param = system_plugin_infos[j]; + reg_param.plugin_lib_name = calloc(1, path_len); + + snprintf(reg_param.plugin_lib_name, path_len, "./%s", + system_plugin_infos[j].plugin_lib_name); plugin_id = - plugin_manager_reg_plugin(manager->plugin_manager, reg_param); + plugin_manager_reg_plugin(manager->plugin_manager, ®_param); if (plugin_id.id_val == 0) { log_warn("Failed to register plugin: %s", - reg_param->plugin_name); + reg_param.plugin_name); } + + free(reg_param.plugin_lib_name); } } diff --git a/src/core/plugin_manager.c b/src/core/plugin_manager.c index b273b548..ffc3990c 100644 --- a/src/core/plugin_manager.c +++ b/src/core/plugin_manager.c @@ -158,8 +158,8 @@ static void reg_entity_init(plugin_reg_entity_t * reg_entity, reg_entity->plugin_id = plugin_id; reg_entity->plugin_kind = param->plugin_kind; reg_entity->adapter_type = param->adapter_type; - reg_entity->plugin_name = param->plugin_name; - reg_entity->plugin_lib_name = param->plugin_lib_name; + reg_entity->plugin_name = strdup(param->plugin_name); + reg_entity->plugin_lib_name = strdup(param->plugin_lib_name); return; } diff --git a/src/core/plugin_manager.h b/src/core/plugin_manager.h index e30c87d8..208b8df3 100644 --- a/src/core/plugin_manager.h +++ b/src/core/plugin_manager.h @@ -36,7 +36,7 @@ typedef struct plugin_reg_param { // The buffer should be move to plugin manager, don't free it const char *plugin_name; // The buffer should be move to plugin manager, don't free it - const char *plugin_lib_name; + char *plugin_lib_name; } plugin_reg_param_t; typedef struct plugin_reg_info { diff --git a/tests/plugins/mqtt/CMakeLists.txt b/tests/plugins/mqtt/CMakeLists.txt index 8b0c9b7e..e3f856d2 100644 --- a/tests/plugins/mqtt/CMakeLists.txt +++ b/tests/plugins/mqtt/CMakeLists.txt @@ -4,7 +4,7 @@ include_directories(../../../plugins/mqtt) file(GLOB MQTT_SRC "../../../plugins/mqtt/*.c") set(src ${MQTT_SRC} paho_client_test.cc) add_executable(paho_client_test ${src}) -target_link_libraries(paho_client_test neuron-base paho-mqtt3as gtest gtest_main pthread) +target_link_libraries(paho_client_test neuron-base gtest gtest_main) # add_test( # NAME