OS X support AddressSanitizer

This commit is contained in:
fengzero
2021-08-09 07:41:52 +00:00
committed by Parker Liu
parent 4229a7c283
commit 3d034ba9c6
5 changed files with 21 additions and 17 deletions
+3 -6
View File
@@ -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)
+14 -7
View File
@@ -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, &reg_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);
}
}
+2 -2
View File
@@ -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;
}
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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