Fix builds with built-in plugins
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 26 May 2017 23:24:13 +0000 (19:24 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 9 Jun 2017 20:58:11 +0000 (16:58 -0400)
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 <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
13 files changed:
Makefile.am
cli/Makefile.am
configure.ac
lib/Makefile.am
plugins/ctf/Makefile.am
plugins/ctf/common/metadata/Makefile.am
plugins/ctf/fs-sink/Makefile.am
plugins/ctf/fs-src/Makefile.am
plugins/lttng-utils/Makefile.am
plugins/text/Makefile.am
plugins/text/pretty/Makefile.am
plugins/utils/Makefile.am
plugins/utils/trimmer/Makefile.am

index 63613f885912907a775b99f1d6069dbcfc6ab206..4c6b4d37a9197a66f86a78748a1749a233d042d5 100644 (file)
@@ -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
 
index 2e82301a979cfbd6fbb3f4a7608ec59a64fe92ee..5f07bf19b7c17543d5a5c58c4270dcfd093a4197 100644 (file)
@@ -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
index a9b2c6a970892d72415c1c5535445ba474e2209a..5701e6b7de562dc411820ab945acc0aaa1a86d3f 100644 (file)
@@ -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])
 ])
index 416d703c26438244e50b1ba5ce0a5e7db3fdc41c..6a35b8f8d2c3766b90f252158c2e86be90349d70 100644 (file)
@@ -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
index 8814cd11dd5aee899a0af781cbb10b5c0d66b210..937ce639206f8583204f1e9c01c4016515ef5175 100644 (file)
@@ -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
index 5ca0873a53b65b1414341ab08046c1ce9ce948dc..9e675e2241af78f6b402361a2e1de05194755f8d 100644 (file)
@@ -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
index 62f771129e2ead0513913ca889bd00800580f2d4..56e0e17e26ef7bb4211f6ab692aad9408487c89e 100644 (file)
@@ -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
index 70be5f0f2392f0788c2d5906bb112ec8562bc015..65691d5744b5441bb92f058c58817255819788cf 100644 (file)
@@ -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 \
index 97a327bbb02201c3abf36997848262f433d65f47..5686b90ad1c50b75c1c779bb6cc690dc291c9f5e 100644 (file)
@@ -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
index 105742b62542197f8ac4483cd4d4f479e9d6d801..876276d742fd50a6785c5958bca0d1f99d79702c 100644 (file)
@@ -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
index 1cb89a2f1f052912fd0252339adfbd3ac58aa070..4af26170051e504151e1e5c4099c1355915998c4 100644 (file)
@@ -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
index 7cc7c842745dde0accb6359c5ea1eff493a9bd5b..a6b520be31fb6c5f7a445ab88f90b55f03239ab7 100644 (file)
@@ -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
index 931607dff3627f9348748bfac68d02b529bb669f..74bad1c912ebd36fc0cca7a6d45e7083a957ec06 100644 (file)
@@ -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
This page took 0.032124 seconds and 4 git commands to generate.