From: Michael Jeanson Date: Thu, 16 Feb 2017 16:03:09 +0000 (-0500) Subject: Port: plugin system compat for mingw / macOS X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=5223801707ae9452cf695f32be4ba145d9240c47 Port: plugin system compat for mingw / macOS Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- diff --git a/cli/Makefile.am b/cli/Makefile.am index d5918366..197aa5d7 100644 --- a/cli/Makefile.am +++ b/cli/Makefile.am @@ -5,7 +5,11 @@ if ENABLE_DEBUG_INFO LTTNG_UTILS_PLUGIN_PATH += :$(PLUGINS_PATH)/lttng-utils endif +if BABELTRACE_BUILD_WITH_MINGW +IN_TREE_PLUGIN_PATH := $(shell cygpath -pm "$(PLUGINS_PATH)/ctf:$(PLUGINS_PATH)/text:$(PLUGINS_PATH)/utils$(LTTNG_UTILS_PLUGIN_PATH)") +else IN_TREE_PLUGIN_PATH = $(PLUGINS_PATH)/ctf:$(PLUGINS_PATH)/text:$(PLUGINS_PATH)/utils$(LTTNG_UTILS_PLUGIN_PATH) +endif AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include \ '-DCONFIG_IN_TREE_PLUGIN_PATH="$(IN_TREE_PLUGIN_PATH)"' diff --git a/common/common.c b/common/common.c index 0a0d1583..363ffe2d 100644 --- a/common/common.c +++ b/common/common.c @@ -201,19 +201,19 @@ int bt_common_append_plugin_path_dirs(const char *paths, GPtrArray *dirs) while (at < end) { GString *path; - const char *next_colon; + const char *next_sep; - next_colon = strchr(at, ':'); - if (next_colon == at) { + next_sep = strchr(at, G_SEARCHPATH_SEPARATOR); + if (next_sep == at) { /* * Empty path: try next character (supported * to conform to the typical parsing of $PATH). */ at++; continue; - } else if (!next_colon) { - /* No more colon: use the remaining */ - next_colon = paths + strlen(paths); + } else if (!next_sep) { + /* No more separator: use the remaining */ + next_sep = paths + strlen(paths); } path = g_string_new(NULL); @@ -221,8 +221,8 @@ int bt_common_append_plugin_path_dirs(const char *paths, GPtrArray *dirs) goto error; } - g_string_append_len(path, at, next_colon - at); - at = next_colon + 1; + g_string_append_len(path, at, next_sep - at); + at = next_sep + 1; g_ptr_array_add(dirs, path); } diff --git a/include/babeltrace/plugin/plugin-dev.h b/include/babeltrace/plugin/plugin-dev.h index c50a9e3e..9ddc6a1c 100644 --- a/include/babeltrace/plugin/plugin-dev.h +++ b/include/babeltrace/plugin/plugin-dev.h @@ -32,6 +32,7 @@ */ #include +#include #include #include #include @@ -226,35 +227,160 @@ struct __bt_plugin_component_class_descriptor_attribute { } value; } __attribute__((packed)); +struct __bt_plugin_descriptor const * const *__bt_get_begin_section_plugin_descriptors(void); +struct __bt_plugin_descriptor const * const *__bt_get_end_section_plugin_descriptors(void); +struct __bt_plugin_descriptor_attribute const * const *__bt_get_begin_section_plugin_descriptor_attributes(void); +struct __bt_plugin_descriptor_attribute const * const *__bt_get_end_section_plugin_descriptor_attributes(void); +struct __bt_plugin_component_class_descriptor const * const *__bt_get_begin_section_component_class_descriptors(void); +struct __bt_plugin_component_class_descriptor const * const *__bt_get_end_section_component_class_descriptors(void); +struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_begin_section_component_class_descriptor_attributes(void); +struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_end_section_component_class_descriptor_attributes(void); + /* * Variable attributes for a plugin descriptor pointer to be added to * the plugin descriptor section (internal use). */ +#ifdef __APPLE__ +#define __BT_PLUGIN_DESCRIPTOR_ATTRS \ + __attribute__((section("__DATA,btp_desc"), used)) + +#define __BT_PLUGIN_DESCRIPTOR_BEGIN_SYMBOL \ + __start___bt_plugin_descriptors + +#define __BT_PLUGIN_DESCRIPTOR_END_SYMBOL \ + __stop___bt_plugin_descriptors + +#define __BT_PLUGIN_DESCRIPTOR_BEGIN_EXTRA \ + __asm("section$start$__DATA$btp_desc") + +#define __BT_PLUGIN_DESCRIPTOR_END_EXTRA \ + __asm("section$end$__DATA$btp_desc") + +#else + #define __BT_PLUGIN_DESCRIPTOR_ATTRS \ __attribute__((section("__bt_plugin_descriptors"), used)) +#define __BT_PLUGIN_DESCRIPTOR_BEGIN_SYMBOL \ + __start___bt_plugin_descriptors + +#define __BT_PLUGIN_DESCRIPTOR_END_SYMBOL \ + __stop___bt_plugin_descriptors + +#define __BT_PLUGIN_DESCRIPTOR_BEGIN_EXTRA + +#define __BT_PLUGIN_DESCRIPTOR_END_EXTRA +#endif + /* * Variable attributes for a plugin attribute pointer to be added to * the plugin attribute section (internal use). */ +#ifdef __APPLE__ +#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_ATTRS \ + __attribute__((section("__DATA,btp_desc_att"), used)) + +#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL \ + __start___bt_plugin_descriptor_attributes + +#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_END_SYMBOL \ + __stop___bt_plugin_descriptor_attributes + +#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_BEGIN_EXTRA \ + __asm("section$start$__DATA$btp_desc_att") + +#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_END_EXTRA \ + __asm("section$end$__DATA$btp_desc_att") + +#else + #define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_ATTRS \ __attribute__((section("__bt_plugin_descriptor_attributes"), used)) +#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL \ + __start___bt_plugin_descriptor_attributes + +#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_END_SYMBOL \ + __stop___bt_plugin_descriptor_attributes + +#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_BEGIN_EXTRA + +#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_END_EXTRA +#endif + /* * Variable attributes for a component class descriptor pointer to be * added to the component class descriptor section (internal use). */ +#ifdef __APPLE__ +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS \ + __attribute__((section("__DATA,btp_cc_desc"), used)) + +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_BEGIN_SYMBOL \ + __start___bt_plugin_component_class_descriptors + +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_END_SYMBOL \ + __stop___bt_plugin_component_class_descriptors + +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_BEGIN_EXTRA \ + __asm("section$start$__DATA$btp_cc_desc") + +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_END_EXTRA \ + __asm("section$end$__DATA$btp_cc_desc") + +#else + #define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS \ __attribute__((section("__bt_plugin_component_class_descriptors"), used)) +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_BEGIN_SYMBOL \ + __start___bt_plugin_component_class_descriptors + +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_END_SYMBOL \ + __stop___bt_plugin_component_class_descriptors + +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_BEGIN_EXTRA + +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_END_EXTRA +#endif + /* * Variable attributes for a component class descriptor attribute * pointer to be added to the component class descriptor attribute * section (internal use). */ +#ifdef __APPLE__ +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS \ + __attribute__((section("__DATA,btp_cc_desc_att"), used)) + +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL \ + __start___bt_plugin_component_class_descriptor_attributes + +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_END_SYMBOL \ + __stop___bt_plugin_component_class_descriptor_attributes + +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_BEGIN_EXTRA \ + __asm("section$start$__DATA$btp_cc_desc_att") + +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_END_EXTRA \ + __asm("section$end$__DATA$btp_cc_desc_att") + +#else + #define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS \ __attribute__((section("__bt_plugin_component_class_descriptor_attributes"), used)) +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL \ + __start___bt_plugin_component_class_descriptor_attributes + +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_END_SYMBOL \ + __stop___bt_plugin_component_class_descriptor_attributes + +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_BEGIN_EXTRA + +#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_END_EXTRA +#endif + /* * Declares a plugin descriptor pointer variable with a custom ID. * @@ -274,9 +400,7 @@ struct __bt_plugin_component_class_descriptor_attribute { .minor = __BT_PLUGIN_VERSION_MINOR, \ .name = _name, \ }; \ - static struct __bt_plugin_descriptor const * const __bt_plugin_descriptor_##_id##_ptr __BT_PLUGIN_DESCRIPTOR_ATTRS = &__bt_plugin_descriptor_##_id; \ - extern struct __bt_plugin_descriptor const *__start___bt_plugin_descriptors; \ - extern struct __bt_plugin_descriptor const *__stop___bt_plugin_descriptors + static struct __bt_plugin_descriptor const * const __bt_plugin_descriptor_##_id##_ptr __BT_PLUGIN_DESCRIPTOR_ATTRS = &__bt_plugin_descriptor_##_id /* * Defines a plugin attribute (generic, internal use). @@ -293,9 +417,7 @@ struct __bt_plugin_component_class_descriptor_attribute { .type = _attr_type, \ .value._attr_name = _x, \ }; \ - static struct __bt_plugin_descriptor_attribute const * const __bt_plugin_descriptor_attribute_##_id##_##_attr_name##_ptr __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_ATTRS = &__bt_plugin_descriptor_attribute_##_id##_##_attr_name; \ - extern struct __bt_plugin_descriptor_attribute const *__start___bt_plugin_descriptor_attributes; \ - extern struct __bt_plugin_descriptor_attribute const *__stop___bt_plugin_descriptor_attributes + static struct __bt_plugin_descriptor_attribute const * const __bt_plugin_descriptor_attribute_##_id##_##_attr_name##_ptr __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_ATTRS = &__bt_plugin_descriptor_attribute_##_id##_##_attr_name /* * Defines a plugin initialization function attribute attached to a @@ -360,14 +482,6 @@ struct __bt_plugin_component_class_descriptor_attribute { #define BT_PLUGIN_VERSION_WITH_ID(_id, _major, _minor, _patch, _extra) \ __BT_PLUGIN_DESCRIPTOR_ATTRIBUTE(version, BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_VERSION, _id, __BT_PLUGIN_VERSION_STRUCT_VALUE(_major, _minor, _patch, _extra)) -/* - * Declaration of start and stop symbols of component class descriptors - * section. - */ -#define __BT_PLUGIN_DECL_COMPONENT_CLASS_DESCRIPTORS_SECTION_START_STOP \ - extern struct __bt_plugin_component_class_descriptor const *__start___bt_plugin_component_class_descriptors; \ - extern struct __bt_plugin_component_class_descriptor const *__stop___bt_plugin_component_class_descriptors - /* * Defines a source component class descriptor with a custom ID. * @@ -386,8 +500,7 @@ struct __bt_plugin_component_class_descriptor_attribute { .notif_iter_next = _notif_iter_next_method, \ }, \ }; \ - static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_source_component_class_descriptor_##_id##_##_comp_class_id##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = &__bt_plugin_source_component_class_descriptor_##_id##_##_comp_class_id; \ - __BT_PLUGIN_DECL_COMPONENT_CLASS_DESCRIPTORS_SECTION_START_STOP + static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_source_component_class_descriptor_##_id##_##_comp_class_id##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = &__bt_plugin_source_component_class_descriptor_##_id##_##_comp_class_id /* * Defines a filter component class descriptor with a custom ID. @@ -407,8 +520,7 @@ struct __bt_plugin_component_class_descriptor_attribute { .notif_iter_next = _notif_iter_next_method, \ }, \ }; \ - static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_filter_component_class_descriptor_##_id##_##_comp_class_id##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = &__bt_plugin_filter_component_class_descriptor_##_id##_##_comp_class_id; \ - __BT_PLUGIN_DECL_COMPONENT_CLASS_DESCRIPTORS_SECTION_START_STOP + static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_filter_component_class_descriptor_##_id##_##_comp_class_id##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = &__bt_plugin_filter_component_class_descriptor_##_id##_##_comp_class_id /* * Defines a sink component class descriptor with a custom ID. @@ -428,8 +540,7 @@ struct __bt_plugin_component_class_descriptor_attribute { .consume = _consume_method, \ }, \ }; \ - static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_sink_component_class_descriptor_##_id##_##_comp_class_id##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = &__bt_plugin_sink_component_class_descriptor_##_id##_##_comp_class_id; \ - __BT_PLUGIN_DECL_COMPONENT_CLASS_DESCRIPTORS_SECTION_START_STOP + static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_sink_component_class_descriptor_##_id##_##_comp_class_id##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = &__bt_plugin_sink_component_class_descriptor_##_id##_##_comp_class_id /* * Defines a component class descriptor attribute (generic, internal @@ -450,9 +561,7 @@ struct __bt_plugin_component_class_descriptor_attribute { .type = _attr_type, \ .value._attr_name = _x, \ }; \ - static struct __bt_plugin_component_class_descriptor_attribute const * const __bt_plugin_##_type##_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_attr_name##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS = &__bt_plugin_##_type##_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_attr_name; \ - extern struct __bt_plugin_component_class_descriptor_attribute const *__start___bt_plugin_component_class_descriptor_attributes; \ - extern struct __bt_plugin_component_class_descriptor_attribute const *__stop___bt_plugin_component_class_descriptor_attributes + static struct __bt_plugin_component_class_descriptor_attribute const * const __bt_plugin_##_type##_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_attr_name##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS = &__bt_plugin_##_type##_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_attr_name /* * Defines a description attribute attached to a specific source @@ -1225,6 +1334,56 @@ struct __bt_plugin_component_class_descriptor_attribute { #define BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_SEEK_TIME_METHOD(_name, _x) \ BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_SEEK_TIME_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_MODULE() \ + static struct __bt_plugin_descriptor const * const __bt_plugin_descriptor_dummy __BT_PLUGIN_DESCRIPTOR_ATTRS = NULL; \ + BT_HIDDEN extern struct __bt_plugin_descriptor const *__BT_PLUGIN_DESCRIPTOR_BEGIN_SYMBOL __BT_PLUGIN_DESCRIPTOR_BEGIN_EXTRA; \ + BT_HIDDEN extern struct __bt_plugin_descriptor const *__BT_PLUGIN_DESCRIPTOR_END_SYMBOL __BT_PLUGIN_DESCRIPTOR_END_EXTRA; \ + \ + static struct __bt_plugin_descriptor_attribute const * const __bt_plugin_descriptor_attribute_dummy __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_ATTRS = NULL; \ + BT_HIDDEN extern struct __bt_plugin_descriptor_attribute const *__BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_BEGIN_EXTRA; \ + BT_HIDDEN extern struct __bt_plugin_descriptor_attribute const *__BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_END_SYMBOL __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_END_EXTRA; \ + \ + static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_component_class_descriptor_dummy __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = NULL; \ + BT_HIDDEN extern struct __bt_plugin_component_class_descriptor const *__BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_BEGIN_SYMBOL __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_BEGIN_EXTRA; \ + BT_HIDDEN extern struct __bt_plugin_component_class_descriptor const *__BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_END_SYMBOL __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_END_EXTRA; \ + \ + static struct __bt_plugin_component_class_descriptor_attribute const * const __bt_plugin_component_class_descriptor_attribute_dummy __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS = NULL; \ + BT_HIDDEN extern struct __bt_plugin_component_class_descriptor_attribute const *__BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_BEGIN_EXTRA; \ + BT_HIDDEN extern struct __bt_plugin_component_class_descriptor_attribute const *__BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_END_SYMBOL __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_END_EXTRA; \ + \ + struct __bt_plugin_descriptor const * const *__bt_get_begin_section_plugin_descriptors(void) \ + { \ + return &__BT_PLUGIN_DESCRIPTOR_BEGIN_SYMBOL; \ + } \ + struct __bt_plugin_descriptor const * const *__bt_get_end_section_plugin_descriptors(void) \ + { \ + return &__BT_PLUGIN_DESCRIPTOR_END_SYMBOL; \ + } \ + struct __bt_plugin_descriptor_attribute const * const *__bt_get_begin_section_plugin_descriptor_attributes(void) \ + { \ + return &__BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL; \ + } \ + struct __bt_plugin_descriptor_attribute const * const *__bt_get_end_section_plugin_descriptor_attributes(void) \ + { \ + return &__BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_END_SYMBOL; \ + } \ + struct __bt_plugin_component_class_descriptor const * const *__bt_get_begin_section_component_class_descriptors(void) \ + { \ + return &__BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_BEGIN_SYMBOL; \ + } \ + struct __bt_plugin_component_class_descriptor const * const *__bt_get_end_section_component_class_descriptors(void) \ + { \ + return &__BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_END_SYMBOL; \ + } \ + struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_begin_section_component_class_descriptor_attributes(void) \ + { \ + return &__BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL; \ + } \ + struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_end_section_component_class_descriptor_attributes(void) \ + { \ + return &__BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_END_SYMBOL; \ + } + #ifdef __cplusplus } #endif diff --git a/lib/plugin/plugin-so.c b/lib/plugin/plugin-so.c index f8fb4df8..c656a35e 100644 --- a/lib/plugin/plugin-so.c +++ b/lib/plugin/plugin-so.c @@ -52,18 +52,7 @@ #define PLUGIN_SUFFIX_LEN max_t(size_t, sizeof(NATIVE_PLUGIN_SUFFIX), \ sizeof(LIBTOOL_PLUGIN_SUFFIX)) -#define SECTION_BEGIN(_name) (&(__start_##_name)) -#define SECTION_END(_name) (&(__stop_##_name)) -#define SECTION_ELEMENT_COUNT(_name) (SECTION_END(_name) - SECTION_BEGIN(_name)) - -#define DECLARE_SECTION(_type, _name) \ - extern _type __start_##_name __attribute((weak)); \ - extern _type __stop_##_name __attribute((weak)) - -DECLARE_SECTION(struct __bt_plugin_descriptor const *, __bt_plugin_descriptors); -DECLARE_SECTION(struct __bt_plugin_descriptor_attribute const *, __bt_plugin_descriptor_attributes); -DECLARE_SECTION(struct __bt_plugin_component_class_descriptor const *, __bt_plugin_component_class_descriptors); -DECLARE_SECTION(struct __bt_plugin_component_class_descriptor_attribute const *, __bt_plugin_component_class_descriptor_attributes); +BT_PLUGIN_MODULE(); /* * This list, global to the library, keeps all component classes that @@ -336,6 +325,10 @@ enum bt_plugin_status bt_plugin_so_init( const struct __bt_plugin_descriptor_attribute *cur_attr = *cur_attr_ptr; + if (cur_attr == NULL) { + continue; + } + if (cur_attr->plugin_descriptor != descriptor) { continue; } @@ -393,6 +386,10 @@ enum bt_plugin_status bt_plugin_so_init( *cur_cc_descr_ptr; struct comp_class_full_descriptor full_descriptor = {0}; + if (cur_cc_descr == NULL) { + continue; + } + if (cur_cc_descr->plugin_descriptor != descriptor) { continue; } @@ -411,6 +408,10 @@ enum bt_plugin_status bt_plugin_so_init( const struct __bt_plugin_component_class_descriptor_attribute *cur_cc_descr_attr = *cur_cc_descr_attr_ptr; + if (cur_cc_descr_attr == NULL) { + continue; + } + if (cur_cc_descr_attr->comp_class_descriptor->plugin_descriptor != descriptor) { continue; @@ -805,6 +806,23 @@ end: return plugin; } +static +size_t count_non_null_items_in_section(const void *begin, const void *end) +{ + size_t count = 0; + const int * const *begin_int = (const int * const *) begin; + const int * const *end_int = (const int * const *) end; + const int * const *iter; + + for (iter = begin_int; iter != end_int; iter++) { + if (*iter) { + count++; + } + } + + return count; +} + static struct bt_plugin_set *bt_plugin_so_create_all_from_sections( struct bt_plugin_so_shared_lib_handle *shared_lib_handle, @@ -824,10 +842,10 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_sections( size_t i; struct bt_plugin_set *plugin_set = NULL; - descriptor_count = descriptors_end - descriptors_begin; - attrs_count = attrs_end - attrs_begin; - cc_descriptors_count = cc_descriptors_end - cc_descriptors_begin; - cc_descr_attrs_count = cc_descr_attrs_end - cc_descr_attrs_begin; + descriptor_count = count_non_null_items_in_section(descriptors_begin, descriptors_end); + attrs_count = count_non_null_items_in_section(attrs_begin, attrs_end); + cc_descriptors_count = count_non_null_items_in_section(cc_descriptors_begin, cc_descriptors_end); + cc_descr_attrs_count = count_non_null_items_in_section(cc_descr_attrs_begin, cc_descr_attrs_end); BT_LOGD("Creating all SO plugins from sections: " "plugin-path=\"%s\", " @@ -850,12 +868,16 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_sections( goto error; } - for (i = 0; i < descriptor_count; i++) { + for (i = 0; i < descriptors_end - descriptors_begin; i++) { enum bt_plugin_status status; const struct __bt_plugin_descriptor *descriptor = descriptors_begin[i]; struct bt_plugin *plugin; + if (descriptor == NULL) { + continue; + } + BT_LOGD("Creating plugin object for plugin: " "name=\"%s\", abi-major=%d, abi-minor=%d", descriptor->name, descriptor->major, descriptor->minor); @@ -928,14 +950,14 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_static(void) BT_LOGD_STR("Creating all SO plugins from built-in plugins."); plugin_set = bt_plugin_so_create_all_from_sections(shared_lib_handle, - SECTION_BEGIN(__bt_plugin_descriptors), - SECTION_END(__bt_plugin_descriptors), - SECTION_BEGIN(__bt_plugin_descriptor_attributes), - SECTION_END(__bt_plugin_descriptor_attributes), - SECTION_BEGIN(__bt_plugin_component_class_descriptors), - SECTION_END(__bt_plugin_component_class_descriptors), - SECTION_BEGIN(__bt_plugin_component_class_descriptor_attributes), - SECTION_END(__bt_plugin_component_class_descriptor_attributes)); + __bt_get_begin_section_plugin_descriptors(), + __bt_get_end_section_plugin_descriptors(), + __bt_get_begin_section_plugin_descriptor_attributes(), + __bt_get_end_section_plugin_descriptor_attributes(), + __bt_get_begin_section_component_class_descriptors(), + __bt_get_end_section_component_class_descriptors(), + __bt_get_begin_section_component_class_descriptor_attributes(), + __bt_get_end_section_component_class_descriptor_attributes()); end: BT_PUT(shared_lib_handle); @@ -956,6 +978,14 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_file(const char *path) struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_end = NULL; struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_begin = NULL; struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_end = NULL; + struct __bt_plugin_descriptor const * const *(*get_begin_section_plugin_descriptors)(void); + struct __bt_plugin_descriptor const * const *(*get_end_section_plugin_descriptors)(void); + struct __bt_plugin_descriptor_attribute const * const *(*get_begin_section_plugin_descriptor_attributes)(void); + struct __bt_plugin_descriptor_attribute const * const *(*get_end_section_plugin_descriptor_attributes)(void); + struct __bt_plugin_component_class_descriptor const * const *(*get_begin_section_component_class_descriptors)(void); + struct __bt_plugin_component_class_descriptor const * const *(*get_end_section_component_class_descriptors)(void); + struct __bt_plugin_component_class_descriptor_attribute const * const *(*get_begin_section_component_class_descriptor_attributes)(void); + struct __bt_plugin_component_class_descriptor_attribute const * const *(*get_end_section_component_class_descriptor_attributes)(void); bt_bool is_libtool_wrapper = BT_FALSE, is_shared_object = BT_FALSE; struct bt_plugin_so_shared_lib_handle *shared_lib_handle = NULL; @@ -995,34 +1025,42 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_file(const char *path) goto end; } - if (!g_module_symbol(shared_lib_handle->module, "__start___bt_plugin_descriptors", - (gpointer *) &descriptors_begin)) { + if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_plugin_descriptors", + (gpointer *) &get_begin_section_plugin_descriptors)) { + descriptors_begin = get_begin_section_plugin_descriptors(); + } else { BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", " "symbol=\"%s\"", path, - "__start___bt_plugin_descriptors"); + "__bt_get_begin_section_plugin_descriptors"); goto end; } - if (!g_module_symbol(shared_lib_handle->module, "__stop___bt_plugin_descriptors", - (gpointer *) &descriptors_end)) { + if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_plugin_descriptors", + (gpointer *) &get_end_section_plugin_descriptors)) { + descriptors_end = get_end_section_plugin_descriptors(); + } else { BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", " "symbol=\"%s\"", path, - "__stop___bt_plugin_descriptors"); + "__bt_get_end_section_plugin_descriptors"); goto end; } - if (!g_module_symbol(shared_lib_handle->module, "__start___bt_plugin_descriptor_attributes", - (gpointer *) &attrs_begin)) { + if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_plugin_descriptor_attributes", + (gpointer *) &get_begin_section_plugin_descriptor_attributes)) { + attrs_begin = get_begin_section_plugin_descriptor_attributes(); + } else { BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", " "symbol=\"%s\"", path, - "__start___bt_plugin_descriptor_attributes"); + "__bt_get_begin_section_plugin_descriptor_attributes"); } - if (!g_module_symbol(shared_lib_handle->module, "__stop___bt_plugin_descriptor_attributes", - (gpointer *) &attrs_end)) { + if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_plugin_descriptor_attributes", + (gpointer *) &get_end_section_plugin_descriptor_attributes)) { + attrs_end = get_end_section_plugin_descriptor_attributes(); + } else { BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", " "symbol=\"%s\"", path, - "__stop___bt_plugin_descriptor_attributes"); + "__bt_get_end_section_plugin_descriptor_attributes"); } if ((!!attrs_begin - !!attrs_end) != 0) { @@ -1030,24 +1068,28 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_file(const char *path) "path=\"%s\", symbol-start=\"%s\", " "symbol-end=\"%s\", symbol-start-addr=%p, " "symbol-end-addr=%p", - path, "__start___bt_plugin_descriptor_attributes", - "__stop___bt_plugin_descriptor_attributes", + path, "__bt_get_begin_section_plugin_descriptor_attributes", + "__bt_get_end_section_plugin_descriptor_attributes", attrs_begin, attrs_end); goto end; } - if (!g_module_symbol(shared_lib_handle->module, "__start___bt_plugin_component_class_descriptors", - (gpointer *) &cc_descriptors_begin)) { + if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_component_class_descriptors", + (gpointer *) &get_begin_section_component_class_descriptors)) { + cc_descriptors_begin = get_begin_section_component_class_descriptors(); + } else { BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", " "symbol=\"%s\"", path, - "__start___bt_plugin_component_class_descriptors"); + "__bt_get_begin_section_component_class_descriptors"); } - if (!g_module_symbol(shared_lib_handle->module, "__stop___bt_plugin_component_class_descriptors", - (gpointer *) &cc_descriptors_end)) { + if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_component_class_descriptors", + (gpointer *) &get_end_section_component_class_descriptors)) { + cc_descriptors_end = get_end_section_component_class_descriptors(); + } else { BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", " "symbol=\"%s\"", path, - "__stop___bt_plugin_component_class_descriptors"); + "__bt_get_end_section_component_class_descriptors"); } if ((!!cc_descriptors_begin - !!cc_descriptors_end) != 0) { @@ -1055,24 +1097,28 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_file(const char *path) "path=\"%s\", symbol-start=\"%s\", " "symbol-end=\"%s\", symbol-start-addr=%p, " "symbol-end-addr=%p", - path, "__start___bt_plugin_component_class_descriptors", - "__stop___bt_plugin_component_class_descriptors", + path, "__bt_get_begin_section_component_class_descriptors", + "__bt_get_end_section_component_class_descriptors", cc_descriptors_begin, cc_descriptors_end); goto end; } - if (!g_module_symbol(shared_lib_handle->module, "__start___bt_plugin_component_class_descriptor_attributes", - (gpointer *) &cc_descr_attrs_begin)) { + if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_component_class_descriptor_attributes", + (gpointer *) &get_begin_section_component_class_descriptor_attributes)) { + cc_descr_attrs_begin = get_begin_section_component_class_descriptor_attributes(); + } else { BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", " "symbol=\"%s\"", path, - "__start___bt_plugin_component_class_descriptor_attributes"); + "__bt_get_begin_section_component_class_descriptor_attributes"); } - if (!g_module_symbol(shared_lib_handle->module, "__stop___bt_plugin_component_class_descriptor_attributes", - (gpointer *) &cc_descr_attrs_end)) { + if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_component_class_descriptor_attributes", + (gpointer *) &get_end_section_component_class_descriptor_attributes)) { + cc_descr_attrs_end = get_end_section_component_class_descriptor_attributes(); + } else { BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", " "symbol=\"%s\"", path, - "__stop___bt_plugin_component_class_descriptor_attributes"); + "__bt_get_end_section_component_class_descriptor_attributes"); } if ((!!cc_descr_attrs_begin - !!cc_descr_attrs_end) != 0) { @@ -1080,8 +1126,8 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_file(const char *path) "path=\"%s\", symbol-start=\"%s\", " "symbol-end=\"%s\", symbol-start-addr=%p, " "symbol-end-addr=%p", - path, "__start___bt_plugin_component_class_descriptor_attributes", - "__stop___bt_plugin_component_class_descriptor_attributes", + path, "__bt_get_begin_section_component_class_descriptor_attributes", + "__bt_get_end_section_component_class_descriptor_attributes", cc_descr_attrs_begin, cc_descr_attrs_end); goto end; } diff --git a/lib/plugin/plugin.c b/lib/plugin/plugin.c index b1193147..2a76815c 100644 --- a/lib/plugin/plugin.c +++ b/lib/plugin/plugin.c @@ -406,13 +406,16 @@ int nftw_append_all_from_dir(const char *file, const struct stat *sb, int flag, switch (flag) { case FTW_F: + { + struct bt_plugin_set *plugins_from_file; + if (name[0] == '.') { /* Skip hidden files */ BT_LOGV("Skipping hidden file: path=\"%s\"", file); goto end; } - struct bt_plugin_set *plugins_from_file = - bt_plugin_create_all_from_file(file); + + plugins_from_file = bt_plugin_create_all_from_file(file); if (plugins_from_file) { size_t j; @@ -430,6 +433,7 @@ int nftw_append_all_from_dir(const char *file, const struct stat *sb, int flag, bt_put(plugins_from_file); } break; + } case FTW_DNR: /* Continue to next file / directory. */ BT_LOGW("Cannot enter directory: continuing: path=\"%s\"", file); diff --git a/plugins/ctf/plugin.c b/plugins/ctf/plugin.c index 789f3c7e..d6d225fe 100644 --- a/plugins/ctf/plugin.c +++ b/plugins/ctf/plugin.c @@ -31,6 +31,10 @@ #include "fs-sink/writer.h" #include "lttng-live/lttng-live-internal.h" +#ifndef BT_BUILT_IN_PLUGINS +BT_PLUGIN_MODULE(); +#endif + /* Initialize plug-in description. */ BT_PLUGIN(ctf); BT_PLUGIN_DESCRIPTION("CTF source and sink support"); diff --git a/plugins/lttng-utils/plugin.c b/plugins/lttng-utils/plugin.c index 1b63b8db..d27f6728 100644 --- a/plugins/lttng-utils/plugin.c +++ b/plugins/lttng-utils/plugin.c @@ -479,6 +479,10 @@ error: return ret; } +#ifndef BT_BUILT_IN_PLUGINS +BT_PLUGIN_MODULE(); +#endif + /* Initialize plug-in entry points. */ BT_PLUGIN_WITH_ID(lttng_utils, "lttng-utils"); BT_PLUGIN_DESCRIPTION_WITH_ID(lttng_utils, "LTTng utilities"); diff --git a/plugins/text/plugin.c b/plugins/text/plugin.c index ff982630..563c8d77 100644 --- a/plugins/text/plugin.c +++ b/plugins/text/plugin.c @@ -23,6 +23,10 @@ #include #include "pretty/pretty.h" +#ifndef BT_BUILT_IN_PLUGINS +BT_PLUGIN_MODULE(); +#endif + BT_PLUGIN(text); BT_PLUGIN_DESCRIPTION("Plain text component classes"); BT_PLUGIN_AUTHOR("Julien Desfossez, Mathieu Desnoyers, Philippe Proulx"); diff --git a/plugins/utils/plugin.c b/plugins/utils/plugin.c index 872402f5..c5ed25a3 100644 --- a/plugins/utils/plugin.c +++ b/plugins/utils/plugin.c @@ -26,6 +26,10 @@ #include "trimmer/iterator.h" #include "muxer/muxer.h" +#ifndef BT_BUILT_IN_PLUGINS +BT_PLUGIN_MODULE(); +#endif + BT_PLUGIN(utils); BT_PLUGIN_DESCRIPTION("Graph utilities"); BT_PLUGIN_AUTHOR("Julien Desfossez, Jérémie Galarneau, Philippe Proulx");