Fix: Reevaluate LTTNG_UST_TRACEPOINT_DEFINE each time tracepoint.h is included
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 21 Feb 2023 19:29:49 +0000 (14:29 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 21 Feb 2023 19:49:07 +0000 (14:49 -0500)
Fix issues with missing symbols in use-cases where tracef.h is included
before defining LTTNG_UST_TRACEPOINT_DEFINE, e.g.:

 #include <lttng/tracef.h>
 #define LTTNG_UST_TRACEPOINT_DEFINE
 #include <provider.h>

It is caused by the fact that tracef.h includes tracepoint.h in a
context which has LTTNG_UST_TRACEPOINT_DEFINE undefined, and this is not
re-evaluated for the following includes.

Fix this by lifting the definition code in tracepoint.h outside of the
header include guards, and #undef the old LTTNG_UST__DEFINE_TRACEPOINT
before re-defining it to its new semantic. Use a new
_LTTNG_UST_TRACEPOINT_DEFINE_ONCE include guard within the
LTTNG_UST_TRACEPOINT_DEFINE defined case to ensure symbols are not
duplicated.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I0ef720435003a7ca0bfcf29d7bf27866c5ff8678

include/lttng/tracepoint.h

index cf3519cd25739aee8688811e963a48c3d25a7cc1..38cd86c0030e5012090869175fef93dd938351c9 100644 (file)
@@ -513,8 +513,30 @@ lttng_ust__tracepoints__destroy(void)
 # endif
 #endif /* #if LTTNG_UST_COMPAT_API(0) */
 
+#if LTTNG_UST_COMPAT_API(0)
+#define tracepoint                     lttng_ust_tracepoint
+#define do_tracepoint                  lttng_ust_do_tracepoint
+#define tracepoint_enabled             lttng_ust_tracepoint_enabled
+#define TP_ARGS                                LTTNG_UST_TP_ARGS
+#endif /* #if LTTNG_UST_COMPAT_API(0) */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LTTNG_UST_TRACEPOINT_H */
+
+/* The following declarations must be outside re-inclusion protection. */
+
 #ifdef LTTNG_UST_TRACEPOINT_DEFINE
 
+#ifndef _LTTNG_UST_TRACEPOINT_DEFINE_ONCE
+#define _LTTNG_UST_TRACEPOINT_DEFINE_ONCE
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * These weak symbols, the constructor, and destructor take care of
  * registering only _one_ instance of the tracepoints per shared-ojbect
@@ -554,6 +576,7 @@ extern struct lttng_ust_tracepoint * const __stop_lttng_ust_tracepoints_ptrs[]
  */
 #define LTTNG_UST__TP_EXTRACT_STRING(...)      #__VA_ARGS__
 
+#undef LTTNG_UST__DEFINE_TRACEPOINT
 #define LTTNG_UST__DEFINE_TRACEPOINT(_provider, _name, _args)                          \
        lttng_ust_tracepoint_validate_name_len(_provider, _name);               \
        extern int lttng_ust_tracepoint_provider_##_provider                    \
@@ -653,26 +676,18 @@ lttng_ust__tracepoints__ptrs_destroy(void)
        }
 }
 
-#else /* LTTNG_UST_TRACEPOINT_DEFINE */
-
-#define LTTNG_UST__DEFINE_TRACEPOINT(_provider, _name, _args)
-
-#endif /* #else LTTNG_UST_TRACEPOINT_DEFINE */
-
-#if LTTNG_UST_COMPAT_API(0)
-#define tracepoint                     lttng_ust_tracepoint
-#define do_tracepoint                  lttng_ust_do_tracepoint
-#define tracepoint_enabled             lttng_ust_tracepoint_enabled
-#define TP_ARGS                                LTTNG_UST_TP_ARGS
-#endif /* #if LTTNG_UST_COMPAT_API(0) */
-
 #ifdef __cplusplus
 }
 #endif
 
-#endif /* _LTTNG_UST_TRACEPOINT_H */
+#endif /* _LTTNG_UST_TRACEPOINT_DEFINE_ONCE */
 
-/* The following declarations must be outside re-inclusion protection. */
+#else /* LTTNG_UST_TRACEPOINT_DEFINE */
+
+#undef LTTNG_UST__DEFINE_TRACEPOINT
+#define LTTNG_UST__DEFINE_TRACEPOINT(_provider, _name, _args)
+
+#endif /* #else LTTNG_UST_TRACEPOINT_DEFINE */
 
 /*
  * LTTNG_UST_TRACEPOINT_HIDDEN_DEFINITION: Define this before including
This page took 0.025578 seconds and 4 git commands to generate.