From: Michael Jeanson Date: Thu, 25 Feb 2021 16:14:47 +0000 (-0500) Subject: Hide private usterr-signal-safe.h symbols X-Git-Tag: v2.13.0-rc1~351 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2b6f437483769831e50886b9f3bc4710b28f4ac9;p=lttng-ust.git Hide private usterr-signal-safe.h symbols The major SONAME bump to '1' gives us the opportunity to hide private symbols that should never have been visible. Changing 'ust_loglevel' from a public weak symbol to a private one, means that each library that uses ust_err will now have it's own private copy of the loglevel and will have to call 'ust_err_init' in it's constructor. While we're at it, namespace the symbols that were previously part of the ABI. Change-Id: I031d4ebfaa43fa4fb3c9f60dc6b557b1d30eca18 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/include/Makefile.am b/include/Makefile.am index 2c78459e..61a09cdc 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -48,8 +48,6 @@ nobase_nodist_include_HEADERS = \ ### Global private headers ### ### ### -# note: usterr-signal-safe.h need namespace cleanup. - noinst_HEADERS = \ usterr-signal-safe.h \ ust-snprintf.h \ diff --git a/include/usterr-signal-safe.h b/include/usterr-signal-safe.h index 3d675687..bbdad049 100644 --- a/include/usterr-signal-safe.h +++ b/include/usterr-signal-safe.h @@ -12,34 +12,40 @@ #include #include #include +#include #include #include +#include "ust-helper.h" #include "ust-tid.h" #include "ust-snprintf.h" -enum ust_loglevel { - UST_LOGLEVEL_UNKNOWN = 0, - UST_LOGLEVEL_NORMAL, - UST_LOGLEVEL_DEBUG, +enum ust_err_loglevel { + UST_ERR_LOGLEVEL_UNKNOWN = 0, + UST_ERR_LOGLEVEL_NORMAL, + UST_ERR_LOGLEVEL_DEBUG, }; -extern volatile enum ust_loglevel ust_loglevel; -void init_usterr(void); +LTTNG_HIDDEN +extern volatile enum ust_err_loglevel ust_err_loglevel; +LTTNG_HIDDEN +void ust_err_init(void); #ifdef LTTNG_UST_DEBUG -static inline int ust_debug(void) +static inline bool ust_err_debug_enabled(void) { - return 1; + return true; } #else /* #ifdef LTTNG_UST_DEBUG */ -static inline int ust_debug(void) +static inline bool ust_err_debug_enabled(void) { - return ust_loglevel == UST_LOGLEVEL_DEBUG; + return ust_err_loglevel == UST_ERR_LOGLEVEL_DEBUG; } #endif /* #else #ifdef LTTNG_UST_DEBUG */ +/* + * The default component for error messages. + */ #ifndef UST_COMPONENT -//#error UST_COMPONENT is undefined #define UST_COMPONENT libust #endif @@ -47,17 +53,18 @@ static inline int ust_debug(void) #define UST_XSTR(d) UST_STR(d) #define UST_STR(s) #s -#define USTERR_MAX_LEN 512 +#define UST_ERR_MAX_LEN 512 -/* We sometimes print in the tracing path, and tracing can occur in +/* + * We sometimes print in the tracing path, and tracing can occur in * signal handlers, so we must use a print method which is signal safe. */ -/* Can't use dynamic allocation. Limit ourselves to USTERR_MAX_LEN chars. */ +/* Can't use dynamic allocation. Limit ourselves to UST_ERR_MAX_LEN chars. */ /* Add end of string in case of buffer overflow. */ #define sigsafe_print_err(fmt, args...) \ do { \ - if (ust_debug()) { \ - char ____buf[USTERR_MAX_LEN]; \ + if (ust_err_debug_enabled()) { \ + char ____buf[UST_ERR_MAX_LEN]; \ int ____saved_errno; \ \ ____saved_errno = errno; /* signal-safety */ \ @@ -92,7 +99,7 @@ do { \ */ #define PERROR(call, args...) \ do { \ - if (ust_debug()) { \ + if (ust_err_debug_enabled()) { \ char buf[200] = "Error in strerror_r()"; \ strerror_r(errno, buf, sizeof(buf)); \ ERRMSG("Error: " call ": %s", ## args, buf); \ @@ -104,7 +111,7 @@ do { \ */ #define PERROR(call, args...) \ do { \ - if (ust_debug()) { \ + if (ust_err_debug_enabled()) { \ char *buf; \ char tmp[200]; \ buf = strerror_r(errno, tmp, sizeof(tmp)); \ diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c index 057895d8..a149e9d6 100644 --- a/liblttng-ust-ctl/ustctl.c +++ b/liblttng-ust-ctl/ustctl.c @@ -2921,8 +2921,8 @@ int ustctl_counter_clear(struct ustctl_daemon_counter *counter, static __attribute__((constructor)) void ustctl_init(void) { - init_usterr(); - lttng_ust_getenv_init(); /* Needs init_usterr() to be completed. */ + ust_err_init(); + lttng_ust_getenv_init(); /* Needs ust_err_init() to be completed. */ lttng_ust_clock_init(); lttng_ring_buffer_metadata_client_init(); lttng_ring_buffer_client_overwrite_init(); diff --git a/liblttng-ust-dl/lttng-ust-dl.c b/liblttng-ust-dl/lttng-ust-dl.c index 6b7362ac..b2e43b96 100644 --- a/liblttng-ust-dl/lttng-ust-dl.c +++ b/liblttng-ust-dl/lttng-ust-dl.c @@ -32,6 +32,12 @@ static void *(*__lttng_ust_plibc_dlmopen)(Lmid_t nsid, const char *filename, #endif static int (*__lttng_ust_plibc_dlclose)(void *handle); +static __attribute__((constructor)) +void _lttng_ust_dl_init(void) +{ + ust_err_init(); +} + static void *_lttng_ust_dl_libc_dlopen(const char *filename, int flags) { diff --git a/liblttng-ust-fd/Makefile.am b/liblttng-ust-fd/Makefile.am index 9b30d87c..b9242d8f 100644 --- a/liblttng-ust-fd/Makefile.am +++ b/liblttng-ust-fd/Makefile.am @@ -8,6 +8,7 @@ liblttng_ust_fd_la_SOURCES = \ liblttng_ust_fd_la_LIBADD = \ $(top_builddir)/liblttng-ust/liblttng-ust.la \ + $(top_builddir)/snprintf/libustsnprintf.la \ $(DL_LIBS) liblttng_ust_fd_la_CFLAGS = -DUST_COMPONENT=liblttng-ust-fd $(AM_CFLAGS) diff --git a/liblttng-ust-fd/lttng-ust-fd.c b/liblttng-ust-fd/lttng-ust-fd.c index c60f3f03..607df41e 100644 --- a/liblttng-ust-fd/lttng-ust-fd.c +++ b/liblttng-ust-fd/lttng-ust-fd.c @@ -18,6 +18,12 @@ static int (*__lttng_ust_fd_plibc_close)(int fd); static int (*__lttng_ust_fd_plibc_fclose)(FILE *stream); +static __attribute__((constructor)) +void _lttng_ust_fd_init(void) +{ + ust_err_init(); +} + static int _lttng_ust_fd_libc_close(int fd) { diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 18701936..a2691049 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -1718,7 +1718,7 @@ void wait_for_sessiond(struct sock_info *sock_info) "Please upgrade your kernel " "(fix is commit 9ea71503a8ed9184d2d0b8ccc4d269d05f7940ae in Linux kernel " "mainline). LTTng-UST will use polling mode fallback."); - if (ust_debug()) + if (ust_err_debug_enabled()) PERROR("futex"); goto end_wait; } @@ -2107,8 +2107,8 @@ void __attribute__((constructor)) lttng_ust_init(void) * sessiond (otherwise leading to errors when trying to create * sessiond before the init functions are completed). */ - init_usterr(); - lttng_ust_getenv_init(); /* Needs init_usterr() to be completed. */ + ust_err_init(); + lttng_ust_getenv_init(); /* Needs ust_err_init() to be completed. */ init_tracepoint(); lttng_ust_init_fd_tracker(); lttng_ust_clock_init(); diff --git a/liblttng-ust/tracepoint.c b/liblttng-ust/tracepoint.c index 089232e1..e0b5da3f 100644 --- a/liblttng-ust/tracepoint.c +++ b/liblttng-ust/tracepoint.c @@ -897,7 +897,7 @@ lib_added: DBG("just registered a tracepoints section from %p and having %d tracepoints", tracepoints_start, tracepoints_count); - if (ust_debug()) { + if (ust_err_debug_enabled()) { int i; for (i = 0; i < tracepoints_count; i++) { @@ -960,7 +960,7 @@ void init_tracepoint(void) { if (uatomic_xchg(&initialized, 1) == 1) return; - init_usterr(); + ust_err_init(); check_weak_hidden(); } diff --git a/snprintf/core.c b/snprintf/core.c index c4d9e0b1..d0f60a10 100644 --- a/snprintf/core.c +++ b/snprintf/core.c @@ -6,13 +6,13 @@ #include -volatile enum ust_loglevel ust_loglevel; +volatile enum ust_err_loglevel ust_err_loglevel; -void init_usterr(void) +void ust_err_init(void) { char *ust_debug; - if (ust_loglevel == UST_LOGLEVEL_UNKNOWN) { + if (ust_err_loglevel == UST_ERR_LOGLEVEL_UNKNOWN) { /* * This getenv is not part of lttng_getenv() because it * is required to print ERR() performed during getenv @@ -20,8 +20,8 @@ void init_usterr(void) */ ust_debug = getenv("LTTNG_UST_DEBUG"); if (ust_debug) - ust_loglevel = UST_LOGLEVEL_DEBUG; + ust_err_loglevel = UST_ERR_LOGLEVEL_DEBUG; else - ust_loglevel = UST_LOGLEVEL_NORMAL; + ust_err_loglevel = UST_ERR_LOGLEVEL_NORMAL; } }