Fix: trace events in C constructors/destructors
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 17 Feb 2023 21:08:46 +0000 (16:08 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 17 Feb 2023 21:08:46 +0000 (16:08 -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
include/lttng/ust-tracepoint-event.h

index 1cf02188f37f78eafb1f61a32b56e99f748b697e..56249f6e74cc424d3b40170aea3671158fa6a2a4 100644 (file)
@@ -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)
index 31eaf73c0139026b9adbb8c87ca7076c0df77125..7e9aa4971618bbe6e9aa2fcd11a8a72838b621e6 100644 (file)
  * 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__))
 
index da52162c4a256d40278700f014949bc65f37b043..80906feb0003bb1688baaf06ba85ba5e9f6454a3 100644 (file)
@@ -1017,7 +1017,7 @@ static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER)
 
 /* Reset all macros within TRACEPOINT_EVENT */
 #include <lttng/ust-tracepoint-event-reset.h>
-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)
This page took 0.026976 seconds and 4 git commands to generate.