Fix: ensure all probe providers have their symbols
[lttng-ust.git] / include / lttng / tracepoint.h
index 3d54864fcf578ebc9fd50bfa69f2537334ef5dad..3433560a10e9d2ce220cb925a0252c01211bc391 100644 (file)
  *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
  */
 
 #include <lttng/tracepoint-types.h>
@@ -22,6 +30,7 @@
 #include <string.h>    /* for memset */
 #include <assert.h>
 #include <lttng/ust-config.h>  /* for sdt */
+#include <lttng/ust-compiler.h>
 
 #ifdef LTTNG_UST_HAVE_SDT_INTEGRATION
 #define SDT_USE_VARIADIC
@@ -137,7 +146,10 @@ extern "C" {
 
 #define _DECLARE_TRACEPOINT(_provider, _name, ...)                                     \
 extern struct tracepoint __tracepoint_##_provider##___##_name;                         \
-static inline void __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_ARGS__))        \
+static inline lttng_ust_notrace                                                                \
+void __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_ARGS__));             \
+static inline                                                                          \
+void __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_ARGS__))              \
 {                                                                                      \
        struct tracepoint_probe *__tp_probe;                                            \
                                                                                        \
@@ -148,7 +160,7 @@ static inline void __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_A
        if (caa_unlikely(!__tp_probe))                                                  \
                goto end;                                                               \
        do {                                                                            \
-               void *__tp_cb = __tp_probe->func;                                       \
+               void (*__tp_cb)(void) = __tp_probe->func;                                       \
                void *__tp_data = __tp_probe->data;                                     \
                                                                                        \
                URCU_FORCE_CAST(void (*)(_TP_ARGS_DATA_PROTO(__VA_ARGS__)), __tp_cb)    \
@@ -157,21 +169,30 @@ static inline void __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_A
 end:                                                                                   \
        tp_rcu_read_unlock_bp();                                                        \
 }                                                                                      \
-static inline void __tracepoint_register_##_provider##___##_name(char *name,           \
-               void *func, void *data)                                                 \
+static inline lttng_ust_notrace                                                                \
+void __tracepoint_register_##_provider##___##_name(char *name,                         \
+               void (*func)(void), void *data);                                        \
+static inline                                                                          \
+void __tracepoint_register_##_provider##___##_name(char *name,                         \
+               void (*func)(void), void *data)                                         \
 {                                                                                      \
        __tracepoint_probe_register(name, func, data,                                   \
                __tracepoint_##_provider##___##_name.signature);                        \
 }                                                                                      \
-static inline void __tracepoint_unregister_##_provider##___##_name(char *name,         \
-               void *func, void *data)                                                 \
+static inline lttng_ust_notrace                                                                \
+void __tracepoint_unregister_##_provider##___##_name(char *name,                       \
+               void (*func)(void), void *data);                                        \
+static inline                                                                          \
+void __tracepoint_unregister_##_provider##___##_name(char *name,                       \
+               void (*func)(void), void *data)                                         \
 {                                                                                      \
        __tracepoint_probe_unregister(name, func, data);                                \
 }
 
-extern int __tracepoint_probe_register(const char *name, void *func, void *data,
-               const char *signature);
-extern int __tracepoint_probe_unregister(const char *name, void *func, void *data);
+extern int __tracepoint_probe_register(const char *name, void (*func)(void),
+               void *data, const char *signature);
+extern int __tracepoint_probe_unregister(const char *name, void (*func)(void),
+               void *data);
 
 /*
  * tracepoint dynamic linkage handling (callbacks). Hidden visibility:
@@ -194,6 +215,16 @@ extern struct tracepoint_dlopen tracepoint_dlopen;
 
 #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 tracepoint * const __start___tracepoints_ptrs[]
+       __attribute__((weak, visibility("hidden")));
+extern struct tracepoint * const __stop___tracepoints_ptrs[]
+       __attribute__((weak, visibility("hidden")));
+
 /*
  * When TRACEPOINT_PROBE_DYNAMIC_LINKAGE is defined, we do not emit a
  * unresolved symbol that requires the provider to be linked in. When
@@ -234,21 +265,50 @@ extern struct tracepoint_dlopen tracepoint_dlopen;
                __attribute__((used, section("__tracepoints_ptrs"))) =          \
                        &__tracepoint_##_provider##___##_name;
 
+static inline void __tracepoints__init_define(void)
+{
+       tracepoint_dlopen.tracepoint_register_lib(__start___tracepoints_ptrs,
+                               __stop___tracepoints_ptrs -
+                               __start___tracepoints_ptrs);
+}
+
+static inline void __tracepoints__destroy_define(void)
+{
+       if (tracepoint_dlopen.tracepoint_unregister_lib)
+               tracepoint_dlopen.tracepoint_unregister_lib(__start___tracepoints_ptrs);
+}
+
+
+#else /* TRACEPOINT_DEFINE */
+
+#define _DEFINE_TRACEPOINT(_provider, _name, _args)
+
+static inline void __tracepoints__init_define(void)
+{
+}
+
+static inline void __tracepoints__destroy_define(void)
+{
+}
+
+#endif /* #else TRACEPOINT_DEFINE */
+
+#if defined(TRACEPOINT_DEFINE) || defined(TRACEPOINT_CREATE_PROBES)
+
 /*
  * 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 tracepoint * const __start___tracepoints_ptrs[]
-       __attribute__((weak, visibility("hidden")));
-extern struct tracepoint * const __stop___tracepoints_ptrs[]
-       __attribute__((weak, visibility("hidden")));
 int __tracepoint_registered
        __attribute__((weak, visibility("hidden")));
 struct tracepoint_dlopen tracepoint_dlopen
        __attribute__((weak, visibility("hidden")));
 
-static void __attribute__((constructor)) __tracepoints__init(void)
+static void lttng_ust_notrace __attribute__((constructor))
+__tracepoints__init(void);
+static void
+__tracepoints__init(void)
 {
        if (__tracepoint_registered++)
                return;
@@ -279,19 +339,19 @@ static void __attribute__((constructor)) __tracepoints__init(void)
                                dlsym(tracepoint_dlopen.liblttngust_handle,
                                        "tp_rcu_dereference_sym_bp"));
 #endif
-       tracepoint_dlopen.tracepoint_register_lib(__start___tracepoints_ptrs,
-                               __stop___tracepoints_ptrs -
-                               __start___tracepoints_ptrs);
+       __tracepoints__init_define();
 }
 
-static void __attribute__((destructor)) __tracepoints__destroy(void)
+static void lttng_ust_notrace __attribute__((destructor))
+__tracepoints__destroy(void);
+static void
+__tracepoints__destroy(void)
 {
        int ret;
 
        if (--__tracepoint_registered)
                return;
-       if (tracepoint_dlopen.tracepoint_unregister_lib)
-               tracepoint_dlopen.tracepoint_unregister_lib(__start___tracepoints_ptrs);
+       __tracepoints__destroy_define();
        if (tracepoint_dlopen.liblttngust_handle) {
                ret = dlclose(tracepoint_dlopen.liblttngust_handle);
                assert(!ret);
@@ -299,11 +359,7 @@ static void __attribute__((destructor)) __tracepoints__destroy(void)
        }
 }
 
-#else /* TRACEPOINT_DEFINE */
-
-#define _DEFINE_TRACEPOINT(_provider, _name, _args)
-
-#endif /* #else TRACEPOINT_DEFINE */
+#endif
 
 #ifdef __cplusplus
 }
@@ -499,3 +555,9 @@ enum {
 #define TRACEPOINT_LOGLEVEL(provider, name, loglevel)
 
 #endif /* #ifndef TRACEPOINT_LOGLEVEL */
+
+#ifndef TRACEPOINT_MODEL_EMF_URI
+
+#define TRACEPOINT_MODEL_EMF_URI(provider, name, uri)
+
+#endif /* #ifndef TRACEPOINT_MODEL_EMF_URI */
This page took 0.026735 seconds and 4 git commands to generate.