From a8fafb675a9f580f6a889223e26664ea11cb0c99 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 17 Feb 2023 16:08:46 -0500 Subject: [PATCH] Fix: trace events in C constructors/destructors Adding a priority (150) to the tracepoint and tracepoint provider constructors/destructors ensures that we trace tracepoints located within C constructors/destructors with a higher priority value, including the default init priority of 65535, when the tracepoint vs tracepoint definition vs tracepoint probe provider are in different compile units (and in various link order one compared to another). Signed-off-by: Mathieu Desnoyers Change-Id: Ia8e36317ae058402cdb81cb921da69cfa97a2f82 --- include/lttng/tracepoint.h | 8 ++++---- include/lttng/ust-compiler.h | 10 ++++++++++ include/lttng/ust-tracepoint-event.h | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/lttng/tracepoint.h b/include/lttng/tracepoint.h index 1cf02188..56249f6e 100644 --- a/include/lttng/tracepoint.h +++ b/include/lttng/tracepoint.h @@ -333,7 +333,7 @@ __tracepoint__init_urcu_sym(void) } #endif -static void lttng_ust_notrace __attribute__((constructor)) +static void lttng_ust_notrace __attribute__((constructor(LTTNG_UST_CONSTRUCTOR_PRIO))) __tracepoints__init(void); static void __tracepoints__init(void) @@ -355,7 +355,7 @@ __tracepoints__init(void) __tracepoint__init_urcu_sym(); } -static void lttng_ust_notrace __attribute__((destructor)) +static void lttng_ust_notrace __attribute__((destructor(LTTNG_UST_CONSTRUCTOR_PRIO))) __tracepoints__destroy(void); static void __tracepoints__destroy(void) @@ -460,7 +460,7 @@ extern struct lttng_ust_tracepoint * const __stop___tracepoints_ptrs[] __lttng_ust_variable_attribute_no_sanitize_address = \ &__tracepoint_##_provider##___##_name; -static void lttng_ust_notrace __attribute__((constructor)) +static void lttng_ust_notrace __attribute__((constructor(LTTNG_UST_CONSTRUCTOR_PRIO))) __tracepoints__ptrs_init(void); static void __tracepoints__ptrs_init(void) @@ -504,7 +504,7 @@ __tracepoints__ptrs_init(void) } } -static void lttng_ust_notrace __attribute__((destructor)) +static void lttng_ust_notrace __attribute__((destructor(LTTNG_UST_CONSTRUCTOR_PRIO))) __tracepoints__ptrs_destroy(void); static void __tracepoints__ptrs_destroy(void) diff --git a/include/lttng/ust-compiler.h b/include/lttng/ust-compiler.h index 31eaf73c..7e9aa497 100644 --- a/include/lttng/ust-compiler.h +++ b/include/lttng/ust-compiler.h @@ -24,6 +24,16 @@ * SOFTWARE. */ +/* + * By default, LTTng-UST uses the priority 150 for the tracepoint and probe + * provider constructors to trace tracepoints located within + * constructors/destructors with a higher priority value within the same + * module. This priority can be overridden by the application. + */ +#ifndef LTTNG_UST_CONSTRUCTOR_PRIO +#define LTTNG_UST_CONSTRUCTOR_PRIO 150 +#endif + #define lttng_ust_notrace __attribute__((no_instrument_function)) #define LTTNG_PACKED __attribute__((__packed__)) diff --git a/include/lttng/ust-tracepoint-event.h b/include/lttng/ust-tracepoint-event.h index da52162c..80906feb 100644 --- a/include/lttng/ust-tracepoint-event.h +++ b/include/lttng/ust-tracepoint-event.h @@ -1017,7 +1017,7 @@ static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER) /* Reset all macros within TRACEPOINT_EVENT */ #include -static void lttng_ust_notrace __attribute__((constructor)) +static void lttng_ust_notrace __attribute__((constructor(LTTNG_UST_CONSTRUCTOR_PRIO))) _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void); static void _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void) @@ -1044,7 +1044,7 @@ _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void) } } -static void lttng_ust_notrace __attribute__((destructor)) +static void lttng_ust_notrace __attribute__((destructor(LTTNG_UST_CONSTRUCTOR_PRIO))) _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void); static void _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void) -- 2.34.1