From: Mathieu Desnoyers Date: Thu, 16 Feb 2023 21:41:19 +0000 (-0500) Subject: Fix: trace events in C constructors/destructors X-Git-Url: http://git.liburcu.org/?p=lttng-ust.git;a=commitdiff_plain;h=63661b6634527fca365d4ac9e46cc9c8c94c1e49 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 --- diff --git a/include/lttng/tracepoint.h b/include/lttng/tracepoint.h index b10c514e..cf3519cd 100644 --- a/include/lttng/tracepoint.h +++ b/include/lttng/tracepoint.h @@ -446,7 +446,7 @@ lttng_ust_tracepoints_print_disabled_message(void) static void lttng_ust__tracepoints__init(void) - lttng_ust_notrace __attribute__((constructor)); + lttng_ust_notrace __attribute__((constructor(LTTNG_UST_CONSTRUCTOR_PRIO))); static void lttng_ust__tracepoints__init(void) { @@ -471,7 +471,7 @@ lttng_ust__tracepoints__init(void) static void lttng_ust__tracepoints__destroy(void) - lttng_ust_notrace __attribute__((destructor)); + lttng_ust_notrace __attribute__((destructor(LTTNG_UST_CONSTRUCTOR_PRIO))); static void lttng_ust__tracepoints__destroy(void) { @@ -583,7 +583,7 @@ extern struct lttng_ust_tracepoint * const __stop_lttng_ust_tracepoints_ptrs[] static void lttng_ust__tracepoints__ptrs_init(void) - lttng_ust_notrace __attribute__((constructor)); + lttng_ust_notrace __attribute__((constructor(LTTNG_UST_CONSTRUCTOR_PRIO))); static void lttng_ust__tracepoints__ptrs_init(void) { @@ -626,7 +626,7 @@ lttng_ust__tracepoints__ptrs_init(void) static void lttng_ust__tracepoints__ptrs_destroy(void) - lttng_ust_notrace __attribute__((destructor)); + lttng_ust_notrace __attribute__((destructor(LTTNG_UST_CONSTRUCTOR_PRIO))); static void lttng_ust__tracepoints__ptrs_destroy(void) { diff --git a/include/lttng/ust-compiler.h b/include/lttng/ust-compiler.h index b7fd2c1c..e81246a3 100644 --- a/include/lttng/ust-compiler.h +++ b/include/lttng/ust-compiler.h @@ -10,6 +10,16 @@ #include +/* + * 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)) /* @@ -130,13 +140,13 @@ const lttng::ust::details::LTTNG_UST_COMPILER_COMBINE_TOKENS( \ #define LTTNG_UST_DECLARE_CONSTRUCTOR_DESTRUCTOR(name, constructor_func, \ destructor_func, ...) \ static void LTTNG_UST_COMPILER_COMBINE_TOKENS(lttng_ust_constructor_, name)(void) \ - __attribute__((constructor)) __VA_ARGS__; \ + __attribute__((constructor(LTTNG_UST_CONSTRUCTOR_PRIO))) __VA_ARGS__; \ static void LTTNG_UST_COMPILER_COMBINE_TOKENS(lttng_ust_constructor_, name)(void) \ { \ constructor_func(); \ } \ static void LTTNG_UST_COMPILER_COMBINE_TOKENS(lttng_ust_destructor_, name)(void) \ - __attribute__((destructor)) __VA_ARGS__; \ + __attribute__((destructor(LTTNG_UST_CONSTRUCTOR_PRIO))) __VA_ARGS__; \ static void LTTNG_UST_COMPILER_COMBINE_TOKENS(lttng_ust_destructor_, name)(void) \ { \ destructor_func(); \