From c3ddb532606565c9526c20703b5c70171031c558 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 26 May 2017 19:24:13 -0400 Subject: [PATCH] Fix builds with built-in plugins MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The recent convenience libraries are an issue for built-in plugins because they lead to multiple definitions of the same symbols. This is because we have to use --whole-archive when embedding the plugin archives (.a), so the linker wants to embed all the symbols found. If the same symbol is found twice, the linker is not happy. For example: the `ctf` plugin's archive includes the symbols of libbabeltrace-common.a. The CLI also includes the symbols of libbabeltrace-common.a. When adding the `ctf` archive to the CLI with --whole-archive, the symbols of libbabeltrace-common.a already exist in the CLI, so we get the multiple definition error. My solution here is to avoid adding the convenience libraries to the individual plugins and to the library itself when BUILT_IN_PLUGINS is true. The convenience libraries are added only one time to the CLI (in cli/Makefile.am directly). When BUILT_IN_PLUGINS is false, it is important to include the convenience library functions in each plugin because they could be loaded outside the CLI, where those functions do not exist. There's also a fix to properly embed the Python plugin provider into the library, and to print an error at configure time when BUILT_IN_PYTHON_PLUGIN_SUPPORT=1 is used without --enable-python-plugins. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- Makefile.am | 5 +-- cli/Makefile.am | 48 ++++++++++++++++++++++--- configure.ac | 9 +++-- lib/Makefile.am | 10 ++++-- plugins/ctf/Makefile.am | 7 +++- plugins/ctf/common/metadata/Makefile.am | 2 +- plugins/ctf/fs-sink/Makefile.am | 8 +++-- plugins/ctf/fs-src/Makefile.am | 2 -- plugins/lttng-utils/Makefile.am | 10 +++--- plugins/text/Makefile.am | 7 +++- plugins/text/pretty/Makefile.am | 3 -- plugins/utils/Makefile.am | 6 +++- plugins/utils/trimmer/Makefile.am | 6 +++- 13 files changed, 96 insertions(+), 27 deletions(-) diff --git a/Makefile.am b/Makefile.am index 63613f88..4c6b4d37 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,13 +2,14 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = \ - include \ +SUBDIRS = include \ common \ compat \ logging if WITH_PYTHON_PLUGINS +# Only build the Python plugin provider shared object if the +# configuration doesn't ask to make it built-in. SUBDIRS += python-plugin-provider endif diff --git a/cli/Makefile.am b/cli/Makefile.am index 2e82301a..5f07bf19 100644 --- a/cli/Makefile.am +++ b/cli/Makefile.am @@ -1,6 +1,14 @@ PLUGINS_PATH = $(abs_top_builddir)/plugins +LTTNG_UTILS_PLUGIN_PATH = + +if ENABLE_DEBUG_INFO +LTTNG_UTILS_PLUGIN_PATH += :$(PLUGINS_PATH)/lttng-utils +endif + +IN_TREE_PLUGIN_PATH = $(PLUGINS_PATH)/ctf:$(PLUGINS_PATH)/text:$(PLUGINS_PATH)/utils$(LTTNG_UTILS_PLUGIN_PATH) + AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include \ - -DCONFIG_IN_TREE_PLUGIN_PATH=\"$(PLUGINS_PATH)/ctf:$(PLUGINS_PATH)/lttng-utils:$(PLUGINS_PATH)/text:$(PLUGINS_PATH)/writer:$(PLUGINS_PATH)/utils\" + '-DCONFIG_IN_TREE_PLUGIN_PATH="$(IN_TREE_PLUGIN_PATH)"' AM_LDFLAGS = -lpopt bin_PROGRAMS = babeltrace.bin @@ -22,15 +30,47 @@ babeltrace_bin_SOURCES = \ # -Wl,--no-as-needed is needed for recent gold linker who seems to think # it knows better and considers libraries with constructors having # side-effects as dead code. -babeltrace_bin_LDFLAGS = -Wl, $(LD_NO_AS_NEEDED), -export-dynamic +babeltrace_bin_LDFLAGS = $(LD_NO_AS_NEEDED) -Wl,-export-dynamic + +# Add all the convenience libraries used by Babeltrace plugins and the +# library. They will be used when embedding plugins (BUILT_IN_PLUGINS), +# otherwise we're looking after multiple definitions of the same symbols if +# a plugin's archive (.a) includes the convenience library because +# we're using --whole-archive below (needed to make sure the linker does +# not discard the plugins since the CLI does not use their symbols +# directly). babeltrace_bin_LDADD = \ $(top_builddir)/lib/libbabeltrace.la \ $(top_builddir)/compat/libcompat.la \ $(top_builddir)/common/libbabeltrace-common.la \ - $(top_builddir)/logging/libbabeltrace-logging.la + $(top_builddir)/logging/libbabeltrace-logging.la \ + $(top_builddir)/plugins/libctfcopytrace/libctfcopytrace.la if BUILT_IN_PLUGINS -babeltrace_bin_LDFLAGS += -Wl,--whole-archive,$(top_builddir)/plugins/ctf/.libs/libbabeltrace-plugin-ctf.a,$(top_builddir)/plugins/text/.libs/libbabeltrace-plugin-ctf-text.a,$(top_builddir)/plugins/muxer/.libs/libbabeltrace-plugin-muxer.a,$(top_builddir)/plugins/writer/.libs/libbabeltrace-plugin-ctf-writer.a,--no-whole-archive +# Takes a plugin name and outputs the needed LDFLAGS to embed it. +# +# The --whole-archive option is important here. From the GNU linker's +# documentation: +# +# For each archive mentioned on the command line after the +# --whole-archive option, include every object file in the archive in +# the link, rather than searching the archive for the required object +# files. +# +# In our case, we find the plugins thanks to special sections in the +# binary that are filled by plugin objects. If the linker discards those +# symbols because the CLI does not use them directly, the CLI reports +# no plugins found (plugins are effectively not embedded). +pluginarchive = -Wl,--whole-archive,$(PLUGINS_PATH)/$(1)/.libs/libbabeltrace-plugin-$(1).a,--no-whole-archive + +# Built-in plugins +babeltrace_bin_LDFLAGS += $(call pluginarchive,ctf) +babeltrace_bin_LDFLAGS += $(call pluginarchive,text) +babeltrace_bin_LDFLAGS += $(call pluginarchive,utils) + +if ENABLE_DEBUG_INFO +babeltrace_bin_LDFLAGS += $(call pluginarchive,lttng-utils) +endif endif if BABELTRACE_BUILD_WITH_MINGW diff --git a/configure.ac b/configure.ac index a9b2c6a9..5701e6b7 100644 --- a/configure.ac +++ b/configure.ac @@ -274,7 +274,7 @@ else fi if test "x$enable_python_bindings" != xno || test "x$enable_python_plugins" != xno; then - AM_PATH_PYTHON([3.0], , [AC_MSG_ERROR(Python3 is not available or is not the default Python interpreter on your system. See the README file to learn how to override your distribution's default Python interpreter.)]) + AM_PATH_PYTHON([3.0], , [AC_MSG_ERROR(Python 3 is not available or is not the default Python interpreter on your system. See the README file to learn how to override your distribution's default Python interpreter.)]) AM_PATH_PYTHON_MODULES([PYTHON]) # pythondir is the path where extra modules are to be installed @@ -310,6 +310,8 @@ if test "x$enable_python_bindings" != xno || test "x$enable_python_plugins" != x ]) fi +AS_IF([test "x$BUILT_IN_PLUGINS" = ""]) + AM_CONDITIONAL([WITH_PYTHON_PLUGINS], [test "x$enable_python_plugins" != xno]) AS_IF( [test "x$enable_python_plugins" != xno], @@ -387,11 +389,14 @@ AS_IF([test "x$BUILT_IN_PLUGINS" != x], [ ]) AM_CONDITIONAL([BUILT_IN_PLUGINS], [test "x$built_in_plugins" = "xyes"]) -AC_ARG_VAR([BUILT_IN_PYTHON_PLUGIN_SUPPORT], [Statically-link Python plugin support into the babeltrace binary]) +AC_ARG_VAR([BUILT_IN_PYTHON_PLUGIN_SUPPORT], [Statically-link Python plugin support into the babeltrace library]) AS_IF([test "x$BUILT_IN_PYTHON_PLUGIN_SUPPORT" != x], [ # Built-in plug-ins are only available when the --disable-shared --enable-static options are used. AS_IF([test "x$enable_static" != "xyes"], [AC_MSG_ERROR(--enable-static must be used to bundle Python plugin support in the babeltrace executable)]) AS_IF([test "x$enable_shared" = "xyes"], [AC_MSG_ERROR(--disable-shared must be used to bundle Python plugin support in the babeltrace executable)]) + AS_IF([test "x$enable_python_plugins" = "xno"], [ + AC_MSG_ERROR([You can't use BUILT_IN_PYTHON_PLUGIN_SUPPORT=1 without --enable-python-plugins.]) + ]) built_in_python_plugin_support=yes AC_DEFINE([BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT], [1], [Define to 1 to register plug-in attributes in static executable sections]) ]) diff --git a/lib/Makefile.am b/lib/Makefile.am index 416d703c..6a35b8f8 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -9,14 +9,18 @@ libbabeltrace_la_LDFLAGS = -version-info $(BABELTRACE_LIBRARY_VERSION) libbabeltrace_la_LIBADD = \ prio_heap/libprio_heap.la \ - $(top_builddir)/compat/libcompat.la \ graph/libgraph.la \ plugin/libplugin.la \ - $(top_builddir)/common/libbabeltrace-common.la \ - $(top_builddir)/logging/libbabeltrace-logging.la \ ctf-ir/libctf-ir.la \ ctf-writer/libctf-writer.la if BUILT_IN_PYTHON_PLUGIN_SUPPORT libbabeltrace_la_LIBADD += $(top_builddir)/python-plugin-provider/libbabeltrace-python-plugin-provider.la endif + +if !BUILT_IN_PLUGINS +libbabeltrace_la_LIBADD += \ + $(top_builddir)/logging/libbabeltrace-logging.la \ + $(top_builddir)/common/libbabeltrace-common.la \ + $(top_builddir)/compat/libcompat.la +endif diff --git a/plugins/ctf/Makefile.am b/plugins/ctf/Makefile.am index 8814cd11..937ce639 100644 --- a/plugins/ctf/Makefile.am +++ b/plugins/ctf/Makefile.am @@ -14,9 +14,14 @@ libbabeltrace_plugin_ctf_la_LDFLAGS = \ -version-info $(BABELTRACE_LIBRARY_VERSION) libbabeltrace_plugin_ctf_la_LIBADD = \ - $(top_builddir)/lib/libbabeltrace.la \ fs-src/libbabeltrace-plugin-ctf-fs.la \ lttng-live/libbabeltrace-plugin-ctf-lttng-live.la \ fs-sink/libbabeltrace-plugin-ctf-writer.la \ + common/libbabeltrace-plugin-ctf-common.la + +if !BUILT_IN_PLUGINS +libbabeltrace_plugin_ctf_la_LIBADD += \ + $(top_builddir)/lib/libbabeltrace.la \ $(top_builddir)/logging/libbabeltrace-logging.la \ $(top_builddir)/common/libbabeltrace-common.la +endif diff --git a/plugins/ctf/common/metadata/Makefile.am b/plugins/ctf/common/metadata/Makefile.am index 5ca0873a..9e675e22 100644 --- a/plugins/ctf/common/metadata/Makefile.am +++ b/plugins/ctf/common/metadata/Makefile.am @@ -24,7 +24,7 @@ libctf_ast_la_SOURCES = \ decoder.c \ decoder.h -libctf_ast_la_LIBADD = $(top_builddir)/lib/libbabeltrace.la +libctf_ast_la_LIBADD = if BABELTRACE_BUILD_WITH_LIBUUID libctf_ast_la_LIBADD += -luuid diff --git a/plugins/ctf/fs-sink/Makefile.am b/plugins/ctf/fs-sink/Makefile.am index 62f77112..56e0e17e 100644 --- a/plugins/ctf/fs-sink/Makefile.am +++ b/plugins/ctf/fs-sink/Makefile.am @@ -3,6 +3,10 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/plugins \ noinst_LTLIBRARIES = libbabeltrace-plugin-ctf-writer.la -libbabeltrace_plugin_ctf_writer_la_LIBADD = \ - $(top_builddir)/plugins/libctfcopytrace/libctfcopytrace.la +libbabeltrace_plugin_ctf_writer_la_LIBADD = libbabeltrace_plugin_ctf_writer_la_SOURCES = writer.c writer.h write.c + +if !BUILT_IN_PLUGINS +libbabeltrace_plugin_ctf_writer_la_LIBADD += \ + $(top_builddir)/plugins/libctfcopytrace/libctfcopytrace.la +endif diff --git a/plugins/ctf/fs-src/Makefile.am b/plugins/ctf/fs-src/Makefile.am index 70be5f0f..65691d57 100644 --- a/plugins/ctf/fs-src/Makefile.am +++ b/plugins/ctf/fs-src/Makefile.am @@ -2,8 +2,6 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/plugins noinst_LTLIBRARIES = libbabeltrace-plugin-ctf-fs.la -libbabeltrace_plugin_ctf_fs_la_LIBADD = \ - $(builddir)/../common/libbabeltrace-plugin-ctf-common.la libbabeltrace_plugin_ctf_fs_la_SOURCES = \ data-stream-file.c \ data-stream-file.h \ diff --git a/plugins/lttng-utils/Makefile.am b/plugins/lttng-utils/Makefile.am index 97a327bb..5686b90a 100644 --- a/plugins/lttng-utils/Makefile.am +++ b/plugins/lttng-utils/Makefile.am @@ -4,7 +4,7 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/plugins \ SUBDIRS = . plugindir = "$(PLUGINSDIR)" -plugin_LTLIBRARIES = libbabeltrace-plugin-debug-info.la +plugin_LTLIBRARIES = libbabeltrace-plugin-lttng-utils.la noinst_HEADERS = \ crc32.h \ @@ -14,13 +14,15 @@ noinst_HEADERS = \ utils.h \ copy.h -libbabeltrace_plugin_debug_info_la_SOURCES = \ +libbabeltrace_plugin_lttng_utils_la_SOURCES = \ plugin.c debug-info.h debug-info.c bin-info.c dwarf.c crc32.c utils.c \ copy.c -libbabeltrace_plugin_debug_info_la_LDFLAGS = \ +libbabeltrace_plugin_lttng_utils_la_LDFLAGS = \ -version-info $(BABELTRACE_LIBRARY_VERSION) -lelf -ldw -libbabeltrace_plugin_debug_info_la_LIBADD = \ +if !BUILT_IN_PLUGINS +libbabeltrace_plugin_lttng_utils_la_LIBADD = \ $(top_builddir)/lib/libbabeltrace.la \ $(top_builddir)/plugins/libctfcopytrace/libctfcopytrace.la +endif diff --git a/plugins/text/Makefile.am b/plugins/text/Makefile.am index 105742b6..876276d7 100644 --- a/plugins/text/Makefile.am +++ b/plugins/text/Makefile.am @@ -9,5 +9,10 @@ libbabeltrace_plugin_text_la_SOURCES = plugin.c libbabeltrace_plugin_text_la_LDFLAGS = \ -version-info $(BABELTRACE_LIBRARY_VERSION) libbabeltrace_plugin_text_la_LIBADD = \ - $(top_builddir)/lib/libbabeltrace.la \ pretty/libbabeltrace-plugin-text-pretty-cc.la + +if !BUILT_IN_PLUGINS +libbabeltrace_plugin_text_la_LIBADD += \ + $(top_builddir)/lib/libbabeltrace.la \ + $(top_builddir)/common/libbabeltrace-common.la +endif diff --git a/plugins/text/pretty/Makefile.am b/plugins/text/pretty/Makefile.am index 1cb89a2f..4af26170 100644 --- a/plugins/text/pretty/Makefile.am +++ b/plugins/text/pretty/Makefile.am @@ -7,6 +7,3 @@ libbabeltrace_plugin_text_pretty_cc_la_SOURCES = \ pretty.c \ print.c \ pretty.h - -libbabeltrace_plugin_text_pretty_cc_la_LIBADD = \ - $(top_builddir)/common/libbabeltrace-common.la diff --git a/plugins/utils/Makefile.am b/plugins/utils/Makefile.am index 7cc7c842..a6b520be 100644 --- a/plugins/utils/Makefile.am +++ b/plugins/utils/Makefile.am @@ -9,7 +9,11 @@ libbabeltrace_plugin_utils_la_SOURCES = plugin.c libbabeltrace_plugin_utils_la_LDFLAGS = \ -version-info $(BABELTRACE_LIBRARY_VERSION) libbabeltrace_plugin_utils_la_LIBADD = \ - $(top_builddir)/lib/libbabeltrace.la \ dummy/libbabeltrace-plugin-dummy-cc.la \ trimmer/libbabeltrace-plugin-trimmer.la \ muxer/libbabeltrace-plugin-muxer.la + +if !BUILT_IN_PLUGINS +libbabeltrace_plugin_utils_la_LIBADD += \ + $(top_builddir)/lib/libbabeltrace.la +endif diff --git a/plugins/utils/trimmer/Makefile.am b/plugins/utils/trimmer/Makefile.am index 931607df..74bad1c9 100644 --- a/plugins/utils/trimmer/Makefile.am +++ b/plugins/utils/trimmer/Makefile.am @@ -10,5 +10,9 @@ libbabeltrace_plugin_trimmer_la_SOURCES = \ iterator.h \ copy.h -libbabeltrace_plugin_trimmer_la_LIBADD = \ +libbabeltrace_plugin_trimmer_la_LIBADD = + +if !BUILT_IN_PLUGINS +libbabeltrace_plugin_trimmer_la_LIBADD += \ $(top_builddir)/plugins/libctfcopytrace/libctfcopytrace.la +endif -- 2.34.1