From a878d96125906e6660e6ef3d1f970c13a4e22fbd Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 11 Jan 2022 15:57:37 -0500 Subject: [PATCH] Introduce libcommon-lgpl for liblttng-ctl MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit liblttng-ctl is a LGPLv2.1 library should should not use GPLv2 code. Introduce libcommon-lgpl as a static archive containing only LGPLv2.1 compatible code. This also removes the dependency from liblttng-ctl to liburcu. Include some source files in libcommon-lgpl.a which are indirectly needed by source files required in libcommon-lgpl.a: - endpoint.cpp, - lttng-elf.cpp, - lttng-elf.h. Include some source files in libcommon-lgpl.a which are only needed to link the lttng executable: - domain.cpp, - spawn-viewer.cpp, spawn-viewer.h. Introduce the new source file hashtable/seed.cpp to move the lttng_ht_seed symbol in a source file which does not require liburcu-cds, so it can be present in libcommon-lgpl. This allows building compile units which are needed in the lgpl common library which also contain functions which directly refer to lttng_ht_seed. Programs and libraries which use libhashtable.la are changed to use libcommon-gpl.la instead. libhashtable becomes internal to libcommon. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau Change-Id: I27d2acb823a6d951692a5da88ce32bbe6bafb072 --- src/bin/lttng-consumerd/Makefile.am | 1 - src/bin/lttng-relayd/Makefile.am | 1 - src/bin/lttng-sessiond/Makefile.am | 1 - src/common/Makefile.am | 66 +++++++++++++++---------- src/common/consumer/Makefile.am | 2 - src/common/hashtable/Makefile.am | 18 +++++-- src/common/hashtable/hashtable.c | 1 - src/common/hashtable/seed.c | 11 +++++ src/common/kernel-consumer/Makefile.am | 4 +- src/common/ust-consumer/Makefile.am | 4 +- src/lib/lttng-ctl/Makefile.am | 2 +- tests/regression/tools/live/Makefile.am | 7 --- tests/unit/Makefile.am | 15 +++--- tests/unit/ini_config/Makefile.am | 4 +- 14 files changed, 74 insertions(+), 63 deletions(-) create mode 100644 src/common/hashtable/seed.c diff --git a/src/bin/lttng-consumerd/Makefile.am b/src/bin/lttng-consumerd/Makefile.am index 5704ee721..2c2ee1d75 100644 --- a/src/bin/lttng-consumerd/Makefile.am +++ b/src/bin/lttng-consumerd/Makefile.am @@ -9,7 +9,6 @@ lttng_consumerd_SOURCES = lttng-consumerd.c \ lttng_consumerd_LDADD = \ $(top_builddir)/src/common/consumer/libconsumer.la \ - $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la \ $(top_builddir)/src/common/libcommon-gpl.la \ $(top_builddir)/src/common/index/libindex.la \ $(top_builddir)/src/common/health/libhealth.la \ diff --git a/src/bin/lttng-relayd/Makefile.am b/src/bin/lttng-relayd/Makefile.am index d22484ad0..61663d923 100644 --- a/src/bin/lttng-relayd/Makefile.am +++ b/src/bin/lttng-relayd/Makefile.am @@ -31,7 +31,6 @@ lttng_relayd_SOURCES = main.c lttng-relayd.h utils.h utils.c cmd.h \ lttng_relayd_LDADD = $(URCU_LIBS) \ $(top_builddir)/src/common/libcommon-gpl.la \ $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la \ - $(top_builddir)/src/common/hashtable/libhashtable.la \ $(top_builddir)/src/common/compat/libcompat.la \ $(top_builddir)/src/common/index/libindex.la \ $(top_builddir)/src/common/health/libhealth.la \ diff --git a/src/bin/lttng-sessiond/Makefile.am b/src/bin/lttng-sessiond/Makefile.am index 13eb24e9b..4ea50e400 100644 --- a/src/bin/lttng-sessiond/Makefile.am +++ b/src/bin/lttng-sessiond/Makefile.am @@ -72,7 +72,6 @@ liblttng_sessiond_common_la_LIBADD = $(URCU_LIBS) $(KMOD_LIBS) \ $(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la \ $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la \ $(top_builddir)/src/common/kernel-ctl/libkernel-ctl.la \ - $(top_builddir)/src/common/hashtable/libhashtable.la \ $(top_builddir)/src/common/libcommon-gpl.la \ $(top_builddir)/src/common/compat/libcompat.la \ $(top_builddir)/src/common/relayd/librelayd.la \ diff --git a/src/common/Makefile.am b/src/common/Makefile.am index ba35170d9..675885a67 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -36,10 +36,14 @@ DIST_SUBDIRS = \ argpar-utils # Common library -noinst_LTLIBRARIES = libcommon-gpl.la +noinst_LTLIBRARIES = libcommon-lgpl.la libcommon-gpl.la EXTRA_DIST = mi-lttng-4.1.xsd -libcommon_gpl_la_SOURCES = \ +# The libcommon-lgpl static archive contains only LGPLv2.1 code. It is +# meant to be used by LGPLv2.1 libraries such as liblttng-ctl. It also +# contains libcommon-lgpl.la. + +libcommon_lgpl_la_SOURCES = \ actions/action.c \ actions/list.c \ actions/notify.c \ @@ -50,15 +54,12 @@ libcommon_gpl_la_SOURCES = \ actions/stop-session.c \ actions/rate-policy.c \ buffer-view.h buffer-view.c \ - common.h \ conditions/buffer-usage.c \ conditions/condition.c \ conditions/event-rule-matches.c \ conditions/session-consumed-size.c \ conditions/session-rotation.c \ - context.c context.h \ credentials.c credentials.h \ - daemonize.c daemonize.h \ defaults.c \ domain.c \ dynamic-array.c dynamic-array.h \ @@ -67,7 +68,6 @@ libcommon_gpl_la_SOURCES = \ error.c error.h \ error-query.c \ evaluation.c \ - event.c \ event-expr/event-expr.c \ event-field-value.c \ event-rule/event-rule.c \ @@ -79,53 +79,66 @@ libcommon_gpl_la_SOURCES = \ event-rule/log4j-logging.c \ event-rule/jul-logging.c \ event-rule/python-logging.c \ - filter.c filter.h \ fd-handle.c fd-handle.h \ - fs-handle.c fs-handle.h fs-handle-internal.h \ - futex.c futex.h \ kernel-probe.c \ - index-allocator.c index-allocator.h \ location.c \ log-level-rule.c \ mi-lttng.c mi-lttng.h \ notification.c \ - optional.h \ payload.c payload.h \ payload-view.c payload-view.h \ - pipe.c pipe.h \ readwrite.c readwrite.h \ runas.c runas.h \ - shm.c shm.h \ session-descriptor.c \ snapshot.c snapshot.h \ spawn-viewer.c spawn-viewer.h \ + thread.c thread.h \ time.c \ - trace-chunk.c trace-chunk.h \ - trace-chunk-registry.h \ + tracker.c tracker.h \ trigger.c \ unix.c unix.h \ uri.c uri.h \ userspace-probe.c \ - utils.c utils.h \ - uuid.c uuid.h \ - thread.c thread.h \ - tracker.c tracker.h \ - waiter.c waiter.h + utils.c utils.h if HAVE_ELF_H -libcommon_gpl_la_SOURCES += \ +libcommon_lgpl_la_SOURCES += \ lttng-elf.c lttng-elf.h endif -libcommon_gpl_la_LIBADD = \ +libcommon_lgpl_la_LIBADD = \ $(top_builddir)/src/common/bytecode/libbytecode.la \ - $(top_builddir)/src/common/config/libconfig.la \ $(top_builddir)/src/common/compat/libcompat.la \ - $(top_builddir)/src/common/hashtable/libhashtable.la \ - $(top_builddir)/src/common/fd-tracker/libfd-tracker.la \ + $(top_builddir)/src/common/config/libconfig.la \ $(top_builddir)/src/common/filter/libfilter.la \ + $(top_builddir)/src/common/hashtable/libhashtable-lgpl.la \ $(top_builddir)/src/vendor/msgpack/libmsgpack.la +# The libcommon-gpl static archive contains GPLv2 compatible code. It is +# meant to be used by GPL executables. + +libcommon_gpl_la_SOURCES = \ + common.h \ + context.c context.h \ + daemonize.c daemonize.h \ + event.c \ + filter.c filter.h \ + fs-handle.c fs-handle.h fs-handle-internal.h \ + futex.c futex.h \ + index-allocator.c index-allocator.h \ + optional.h \ + pipe.c pipe.h \ + shm.c shm.h \ + trace-chunk.c trace-chunk.h \ + trace-chunk-registry.h \ + uuid.c uuid.h \ + waiter.c waiter.h + +libcommon_gpl_la_LIBADD = \ + libcommon-lgpl.la \ + $(top_builddir)/src/common/hashtable/libhashtable-gpl.la \ + $(top_builddir)/src/common/fd-tracker/libfd-tracker.la + if BUILD_LIB_HEALTH SUBDIRS += health endif @@ -178,8 +191,7 @@ noinst_HEADERS = \ noinst_PROGRAMS = filter-grammar-test filter_grammar_test_SOURCES = filter-grammar-test.c -filter_grammar_test_LDADD = \ - libcommon-gpl.la +filter_grammar_test_LDADD = libcommon-gpl.la all-local: @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ diff --git a/src/common/consumer/Makefile.am b/src/common/consumer/Makefile.am index 55e47b210..24185bc10 100644 --- a/src/common/consumer/Makefile.am +++ b/src/common/consumer/Makefile.am @@ -12,8 +12,6 @@ libconsumer_la_SOURCES = consumer.c consumer.h consumer-metadata-cache.c \ libconsumer_la_LIBADD = \ $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la \ $(top_builddir)/src/common/kernel-consumer/libkernel-consumer.la \ - $(top_builddir)/src/common/hashtable/libhashtable.la \ - $(top_builddir)/src/common/compat/libcompat.la \ $(top_builddir)/src/common/relayd/librelayd.la if HAVE_LIBLTTNG_UST_CTL diff --git a/src/common/hashtable/Makefile.am b/src/common/hashtable/Makefile.am index 5f6770a81..25d0e4d48 100644 --- a/src/common/hashtable/Makefile.am +++ b/src/common/hashtable/Makefile.am @@ -1,9 +1,17 @@ # SPDX-License-Identifier: GPL-2.0-only -noinst_LTLIBRARIES = libhashtable.la +noinst_LTLIBRARIES = libhashtable-gpl.la libhashtable-lgpl.la -libhashtable_la_SOURCES = hashtable.c hashtable.h \ - utils.c utils.h \ - hashtable-symbols.h +libhashtable_lgpl_la_SOURCES = \ + seed.c \ + utils.c \ + utils.h -libhashtable_la_LIBADD = $(URCU_LIBS) $(URCU_CDS_LIBS) +libhashtable_gpl_la_SOURCES = \ + hashtable.cpp \ + hashtable.h \ + hashtable-symbols.h + +libhashtable_gpl_la_LIBADD = \ + $(URCU_LIBS) \ + $(URCU_CDS_LIBS) diff --git a/src/common/hashtable/hashtable.c b/src/common/hashtable/hashtable.c index 2b1efe26b..73f2ae856 100644 --- a/src/common/hashtable/hashtable.c +++ b/src/common/hashtable/hashtable.c @@ -20,7 +20,6 @@ /* seed_lock protects both seed_init and lttng_ht_seed. */ static pthread_mutex_t seed_lock = PTHREAD_MUTEX_INITIALIZER; static bool seed_init; -unsigned long lttng_ht_seed; static unsigned long min_hash_alloc_size = 1; static unsigned long max_hash_buckets_size = 0; diff --git a/src/common/hashtable/seed.c b/src/common/hashtable/seed.c new file mode 100644 index 000000000..24da1bc95 --- /dev/null +++ b/src/common/hashtable/seed.c @@ -0,0 +1,11 @@ +/* + * Copyright (C) 2021 Mathieu Desnoyers + * + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#define _LGPL_SOURCE +#include "hashtable.h" +#include "utils.h" + +unsigned long lttng_ht_seed; diff --git a/src/common/kernel-consumer/Makefile.am b/src/common/kernel-consumer/Makefile.am index cf86e2a63..0f9d8330b 100644 --- a/src/common/kernel-consumer/Makefile.am +++ b/src/common/kernel-consumer/Makefile.am @@ -4,6 +4,4 @@ noinst_LTLIBRARIES = libkernel-consumer.la libkernel_consumer_la_SOURCES = kernel-consumer.c kernel-consumer.h -libkernel_consumer_la_LIBADD = \ - $(top_builddir)/src/common/kernel-ctl/libkernel-ctl.la \ - $(top_builddir)/src/common/relayd/librelayd.la +libkernel_consumer_la_LIBADD = $(top_builddir)/src/common/kernel-ctl/libkernel-ctl.la diff --git a/src/common/ust-consumer/Makefile.am b/src/common/ust-consumer/Makefile.am index 5ab0fe602..914c00a2b 100644 --- a/src/common/ust-consumer/Makefile.am +++ b/src/common/ust-consumer/Makefile.am @@ -6,8 +6,6 @@ noinst_LTLIBRARIES = libust-consumer.la libust_consumer_la_SOURCES = ust-consumer.c ust-consumer.h -libust_consumer_la_LIBADD = \ - $(UST_CTL_LIBS) \ - $(top_builddir)/src/common/relayd/librelayd.la +libust_consumer_la_LIBADD = $(UST_CTL_LIBS) endif diff --git a/src/lib/lttng-ctl/Makefile.am b/src/lib/lttng-ctl/Makefile.am index c8525260e..630602f14 100644 --- a/src/lib/lttng-ctl/Makefile.am +++ b/src/lib/lttng-ctl/Makefile.am @@ -16,7 +16,7 @@ liblttng_ctl_la_LDFLAGS = \ liblttng_ctl_la_LIBADD = \ $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la \ - $(top_builddir)/src/common/libcommon-gpl.la + $(top_builddir)/src/common/libcommon-lgpl.la pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = lttng-ctl.pc diff --git a/tests/regression/tools/live/Makefile.am b/tests/regression/tools/live/Makefile.am index 7248245e9..563df0b73 100644 --- a/tests/regression/tools/live/Makefile.am +++ b/tests/regression/tools/live/Makefile.am @@ -3,13 +3,6 @@ AM_CPPFLAGS += -I$(top_srcdir)/tests/utils/ -I$(srcdir) LIBTAP=$(top_builddir)/tests/utils/tap/libtap.la - -LIBCOMMON_GPL=$(top_builddir)/src/common/libcommon-gpl.la -LIBSESSIOND_COMM=$(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la -LIBHASHTABLE=$(top_builddir)/src/common/hashtable/libhashtable.la -LIBRELAYD=$(top_builddir)/src/common/relayd/librelayd.la -LIBHEALTH=$(top_builddir)/src/common/health/libhealth.la -LIBCOMPAT=$(top_builddir)/src/common/compat/libcompat.la LIBLTTNG_SESSIOND_COMMON=$(top_builddir)/src/bin/lttng-sessiond/liblttng-sessiond-common.la noinst_PROGRAMS = live_test diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index a07643206..304a1bce9 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -40,7 +40,6 @@ LIBCOMMON_GPL=$(top_builddir)/src/common/libcommon-gpl.la LIBSTRINGUTILS=$(top_builddir)/src/common/string-utils/libstring-utils.la LIBFDTRACKER=$(top_builddir)/src/common/fd-tracker/libfd-tracker.la LIBSESSIOND_COMM=$(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la -LIBHASHTABLE=$(top_builddir)/src/common/hashtable/libhashtable.la LIBRELAYD=$(top_builddir)/src/common/relayd/librelayd.la LIBLTTNG_CTL=$(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la LIBLTTNG_SESSIOND_COMMON=$(top_builddir)/src/bin/lttng-sessiond/liblttng-sessiond-common.la @@ -79,7 +78,7 @@ endif # URI unit tests test_uri_SOURCES = test_uri.c -test_uri_LDADD = $(LIBTAP) $(LIBCOMMON_GPL) $(LIBHASHTABLE) $(DL_LIBS) +test_uri_LDADD = $(LIBTAP) $(LIBCOMMON_GPL) $(DL_LIBS) RELAYD_OBJS = $(top_builddir)/src/bin/lttng-relayd/backward-compatibility-group-by.$(OBJEXT) @@ -104,15 +103,15 @@ test_kernel_data_LDADD = $(LIBTAP) $(LIBLTTNG_SESSIOND_COMMON) $(DL_LIBS) # parse_size_suffix unit test test_utils_parse_size_suffix_SOURCES = test_utils_parse_size_suffix.c -test_utils_parse_size_suffix_LDADD = $(LIBTAP) $(LIBHASHTABLE) $(LIBCOMMON_GPL) $(DL_LIBS) +test_utils_parse_size_suffix_LDADD = $(LIBTAP) $(LIBCOMMON_GPL) $(DL_LIBS) # parse_time_suffix unit test test_utils_parse_time_suffix_SOURCES = test_utils_parse_time_suffix.c -test_utils_parse_time_suffix_LDADD = $(LIBTAP) $(LIBHASHTABLE) $(LIBCOMMON_GPL) +test_utils_parse_time_suffix_LDADD = $(LIBTAP) $(LIBCOMMON_GPL) # compat_poll unit test test_utils_compat_poll_SOURCES = test_utils_compat_poll.c -test_utils_compat_poll_LDADD = $(LIBTAP) $(LIBHASHTABLE) $(DL_LIBS) \ +test_utils_compat_poll_LDADD = $(LIBTAP) $(DL_LIBS) \ $(top_builddir)/src/common/compat/libcompat.la $(LIBCOMMON_GPL) # compat_pthread unit test @@ -122,11 +121,11 @@ test_utils_compat_pthread_LDADD = $(LIBTAP) \ # expand_path unit test test_utils_expand_path_SOURCES = test_utils_expand_path.c -test_utils_expand_path_LDADD = $(LIBTAP) $(LIBHASHTABLE) $(LIBCOMMON_GPL) $(DL_LIBS) +test_utils_expand_path_LDADD = $(LIBTAP) $(LIBCOMMON_GPL) $(DL_LIBS) # directory handle unit test test_directory_handle_SOURCES = test_directory_handle.c -test_directory_handle_LDADD = $(LIBTAP) $(LIBHASHTABLE) $(LIBCOMMON_GPL) $(DL_LIBS) +test_directory_handle_LDADD = $(LIBTAP) $(LIBCOMMON_GPL) $(DL_LIBS) # string utilities unit test test_string_utils_SOURCES = test_string_utils.c @@ -157,7 +156,7 @@ test_rate_policy_LDADD = $(LIBTAP) $(LIBCOMMON_GPL) $(LIBLTTNG_CTL) $(DL_LIBS) \ # fd tracker unit test test_fd_tracker_SOURCES = test_fd_tracker.c -test_fd_tracker_LDADD = $(LIBTAP) $(LIBFDTRACKER) $(DL_LIBS) $(URCU_LIBS) $(LIBCOMMON_GPL) $(LIBHASHTABLE) +test_fd_tracker_LDADD = $(LIBTAP) $(LIBFDTRACKER) $(DL_LIBS) $(URCU_LIBS) $(LIBCOMMON_GPL) # uuid unit test test_uuid_SOURCES = test_uuid.c diff --git a/tests/unit/ini_config/Makefile.am b/tests/unit/ini_config/Makefile.am index 080b39ea3..f4c084079 100644 --- a/tests/unit/ini_config/Makefile.am +++ b/tests/unit/ini_config/Makefile.am @@ -4,15 +4,13 @@ AM_CPPFLAGS += -I$(top_srcdir)/tests/utils/ LIBTAP=$(top_builddir)/tests/utils/tap/libtap.la LIBCOMMON_GPL=$(top_builddir)/src/common/libcommon-gpl.la -LIBHASHTABLE=$(top_builddir)/src/common/hashtable/libhashtable.la LIBLTTNG_CTL=$(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la noinst_PROGRAMS = ini_config EXTRA_DIST = test_ini_config sample.ini ini_config_SOURCES = ini_config.c -ini_config_LDADD = $(LIBTAP) $(LIBCOMMON_GPL) $(LIBLTTNG_CTL) $(LIBHASHTABLE) - +ini_config_LDADD = $(LIBTAP) $(LIBCOMMON_GPL) $(LIBLTTNG_CTL) all-local: @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ -- 2.34.1