From 08ba2503b86d1506117c077c99eb1c38973a48f3 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Thu, 22 Apr 2021 12:48:52 -0400 Subject: [PATCH] Make futex compat internal to liblttng-ust This compat header originated in userspace RCU where it's used across multiple shared objects hence the need to have the mutexes as public weak symbols, in our case it's only used internally by liblttng-ust so we can hide them. If we end up using this compat header in another library in this project we will have to use the same scheme, but in the meantime, don't expose those symbols in the ABI. Move the code to the liblttng-ust directory to make sure it's not used by other libraries. Change-Id: Ibfaef9448eeaf6247b42f71d6b6d8de234d79a3c Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- src/common/Makefile.am | 7 ------- src/lib/lttng-ust/Makefile.am | 2 ++ src/{common/compat => lib/lttng-ust}/futex.c | 20 +++++++++++++++----- src/{common/compat => lib/lttng-ust}/futex.h | 4 ++-- src/lib/lttng-ust/lttng-ust-comm.c | 2 +- 5 files changed, 20 insertions(+), 15 deletions(-) rename src/{common/compat => lib/lttng-ust}/futex.c (81%) rename src/{common/compat => lib/lttng-ust}/futex.h (96%) diff --git a/src/common/Makefile.am b/src/common/Makefile.am index b5f8473b..f4c134a7 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -49,7 +49,6 @@ noinst_HEADERS += \ noinst_LTLIBRARIES = \ libcounter.la \ - libcompat.la \ libmsgpack.la \ libringbuffer.la \ libsnprintf.la \ @@ -77,11 +76,6 @@ endif libcounter_la_CFLAGS = -DUST_COMPONENT="libcounter" $(AM_CFLAGS) -# compat -libcompat_la_SOURCES = \ - compat/futex.c \ - compat/futex.h - # msgpack libmsgpack_la_SOURCES = \ msgpack/msgpack.c \ @@ -154,7 +148,6 @@ libcommon_la_SOURCES = \ patient.c libcommon_la_LIBADD = \ - libcompat.la \ libmsgpack.la \ libsnprintf.la diff --git a/src/lib/lttng-ust/Makefile.am b/src/lib/lttng-ust/Makefile.am index 3ef20aa6..73ceb438 100644 --- a/src/lib/lttng-ust/Makefile.am +++ b/src/lib/lttng-ust/Makefile.am @@ -44,6 +44,8 @@ liblttng_ust_runtime_la_SOURCES = \ lttng-ust-statedump.c \ lttng-ust-statedump.h \ lttng-ust-statedump-provider.h \ + futex.c \ + futex.h \ ust_lib.c \ ust_lib.h \ context-internal.h \ diff --git a/src/common/compat/futex.c b/src/lib/lttng-ust/futex.c similarity index 81% rename from src/common/compat/futex.c rename to src/lib/lttng-ust/futex.c index c87d7134..cf86dfcd 100644 --- a/src/common/compat/futex.c +++ b/src/lib/lttng-ust/futex.c @@ -17,9 +17,21 @@ #include #include -#include "common/compat/futex.h" +#include "lib/lttng-ust/futex.h" /* + * This compat header originated in userspace RCU where it's used across + * multiple shared objects hence the need to have the mutexes as public weak + * symbols, in our case here, it's only used internally by liblttng-ust so we + * can hide them. If we end up using this compat header in another library in + * this project we will have to use the same scheme, but in the meantime, don't + * expose those symbols in the ABI. + */ + +/* + * This comment will apply if we start using this compat header in multiple + * libraires. + * * Using attribute "weak" for __lttng_ust_compat_futex_lock and * __lttng_ust_compat_futex_cond. Those are globally visible by the entire * program, even though many shared objects may have their own version. @@ -27,10 +39,8 @@ * (executable and all shared objects). */ -__attribute__((weak)) -pthread_mutex_t __lttng_ust_compat_futex_lock = PTHREAD_MUTEX_INITIALIZER; -__attribute__((weak)) -pthread_cond_t __lttng_ust_compat_futex_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t __lttng_ust_compat_futex_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t __lttng_ust_compat_futex_cond = PTHREAD_COND_INITIALIZER; /* * _NOT SIGNAL-SAFE_. pthread_cond is not signal-safe anyway. Though. diff --git a/src/common/compat/futex.h b/src/lib/lttng-ust/futex.h similarity index 96% rename from src/common/compat/futex.h rename to src/lib/lttng-ust/futex.h index 71b98677..ef6b349a 100644 --- a/src/common/compat/futex.h +++ b/src/lib/lttng-ust/futex.h @@ -35,11 +35,11 @@ extern "C" { * (returns EINTR). */ -extern int lttng_ust_compat_futex_noasync(int32_t *uaddr, int op, int32_t val, +int lttng_ust_compat_futex_noasync(int32_t *uaddr, int op, int32_t val, const struct timespec *timeout, int32_t *uaddr2, int32_t val3) __attribute__((visibility("hidden"))); -extern int lttng_ust_compat_futex_async(int32_t *uaddr, int op, int32_t val, +int lttng_ust_compat_futex_async(int32_t *uaddr, int op, int32_t val, const struct timespec *timeout, int32_t *uaddr2, int32_t val3) __attribute__((visibility("hidden"))); diff --git a/src/lib/lttng-ust/lttng-ust-comm.c b/src/lib/lttng-ust/lttng-ust-comm.c index 6cdce82d..61f0b34a 100644 --- a/src/lib/lttng-ust/lttng-ust-comm.c +++ b/src/lib/lttng-ust/lttng-ust-comm.c @@ -39,7 +39,7 @@ #include #include #include -#include "common/compat/futex.h" +#include "lib/lttng-ust/futex.h" #include "common/ustcomm.h" #include "common/ust-fd.h" #include "common/logging.h" -- 2.34.1