+
+static inline void tracepoint_disable_destructors(void)
+{
+ if (!lttng_ust_tracepoint_dlopen_ptr)
+ lttng_ust_tracepoint_dlopen_ptr = <tng_ust_tracepoint_dlopen;
+ if (!lttng_ust_tracepoint_destructors_syms_ptr)
+ lttng_ust_tracepoint_destructors_syms_ptr = <tng_ust_tracepoint_destructors_syms;
+ if (lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle
+ && lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_disable_destructors)
+ lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_disable_destructors();
+}
+
+#ifndef _LGPL_SOURCE
+static inline void
+lttng_ust_tracepoint__init_urcu_sym(void)
+ lttng_ust_notrace;
+static inline void
+lttng_ust_tracepoint__init_urcu_sym(void)
+{
+ if (!lttng_ust_tracepoint_dlopen_ptr)
+ lttng_ust_tracepoint_dlopen_ptr = <tng_ust_tracepoint_dlopen;
+ /*
+ * Symbols below are needed by tracepoint call sites and probe
+ * providers.
+ */
+ if (!lttng_ust_tracepoint_dlopen_ptr->rcu_read_lock_sym)
+ lttng_ust_tracepoint_dlopen_ptr->rcu_read_lock_sym =
+ URCU_FORCE_CAST(void (*)(void),
+ dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle,
+ "tp_rcu_read_lock"));
+ if (!lttng_ust_tracepoint_dlopen_ptr->rcu_read_unlock_sym)
+ lttng_ust_tracepoint_dlopen_ptr->rcu_read_unlock_sym =
+ URCU_FORCE_CAST(void (*)(void),
+ dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle,
+ "tp_rcu_read_unlock"));
+ if (!lttng_ust_tracepoint_dlopen_ptr->rcu_dereference_sym)
+ lttng_ust_tracepoint_dlopen_ptr->rcu_dereference_sym =
+ URCU_FORCE_CAST(void *(*)(void *p),
+ dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle,
+ "tp_rcu_dereference_sym"));
+}
+#else
+static inline void
+lttng_ust_tracepoint__init_urcu_sym(void)
+ lttng_ust_notrace;
+static inline void
+lttng_ust_tracepoint__init_urcu_sym(void)
+{
+}
+#endif
+
+static void
+__tracepoints__init(void)
+ lttng_ust_notrace __attribute__((constructor));
+static void
+__tracepoints__init(void)
+{
+ if (lttng_ust_tracepoint_registered++) {
+ if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle)
+ return;
+ lttng_ust_tracepoint__init_urcu_sym();
+ return;
+ }
+
+ if (!lttng_ust_tracepoint_dlopen_ptr)
+ lttng_ust_tracepoint_dlopen_ptr = <tng_ust_tracepoint_dlopen;
+ if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle)
+ lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle =
+ dlopen(LTTNG_UST_TRACEPOINT_LIB_SONAME, RTLD_NOW | RTLD_GLOBAL);
+ if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle)
+ return;
+ lttng_ust_tracepoint__init_urcu_sym();
+}
+
+static void
+__tracepoints__destroy(void)
+ lttng_ust_notrace __attribute__((destructor));
+static void
+__tracepoints__destroy(void)
+{
+ int ret;
+
+ if (--lttng_ust_tracepoint_registered)
+ return;
+ if (!lttng_ust_tracepoint_dlopen_ptr)
+ lttng_ust_tracepoint_dlopen_ptr = <tng_ust_tracepoint_dlopen;
+ if (!lttng_ust_tracepoint_destructors_syms_ptr)
+ lttng_ust_tracepoint_destructors_syms_ptr = <tng_ust_tracepoint_destructors_syms;
+ if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle)
+ return;
+ if (lttng_ust_tracepoint_ptrs_registered)
+ return;
+ /*
+ * Lookup if destructors must be executed using the new method.
+ */
+ if (lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_get_destructors_state
+ && !lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_get_destructors_state()) {
+ /*
+ * The tracepoint_get_destructors_state symbol was found with
+ * dlsym but its returned value is 0 meaning that destructors
+ * must not be executed.
+ */
+ return;
+ }
+ ret = dlclose(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle);
+ if (ret) {
+ fprintf(stderr, "Error (%d) in dlclose\n", ret);
+ abort();
+ }
+ memset(lttng_ust_tracepoint_dlopen_ptr, 0, sizeof(*lttng_ust_tracepoint_dlopen_ptr));
+}
+
+#ifdef TRACEPOINT_DEFINE
+
+/*
+ * These weak symbols, the constructor, and destructor take care of
+ * registering only _one_ instance of the tracepoints per shared-ojbect
+ * (or for the whole main program).
+ */
+extern struct lttng_ust_tracepoint * const __start___tracepoints_ptrs[]