Fix: trace events in C constructors/destructors
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 16 Feb 2023 21:41:19 +0000 (16:41 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 17 Feb 2023 21:06:11 +0000 (16:06 -0500)
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 <mathieu.desnoyers@efficios.com>
Change-Id: Ia8e36317ae058402cdb81cb921da69cfa97a2f82

include/lttng/tracepoint.h
include/lttng/ust-compiler.h

index 17fa2a0c68ef884857cc6dfa5066172e425d2b0d..3c2bbbf841198e02b52d584e0cd76c9bc3e28b1e 100644 (file)
@@ -431,7 +431,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)
 {
@@ -456,7 +456,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)
 {
@@ -568,7 +568,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)
 {
@@ -611,7 +611,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)
 {
index b7fd2c1c42bff2bac5d6bfc1c4f403a61fa82234..e81246a34b63a2cfb374467e211c93286a749a65 100644 (file)
 
 #include <assert.h>
 
+/*
+ * 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();                                              \
This page took 0.0277 seconds and 4 git commands to generate.