Fix: Reevaluate LTTNG_UST_TRACEPOINT_DEFINE each time tracepoint.h is included
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 21 Feb 2023 19:43:29 +0000 (14:43 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 21 Feb 2023 19:43:29 +0000 (14:43 -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: Id48a5f73527d8de5fc1b3605c1d858d848b78633

include/lttng/tracepoint.h

index 56249f6e74cc424d3b40170aea3671158fa6a2a4..8886e900a0511738895b1c9048e294dc6fc26f55 100644 (file)
@@ -405,8 +405,23 @@ __tracepoints__destroy(void)
        memset(tracepoint_dlopen_ptr, 0, sizeof(*tracepoint_dlopen_ptr));
 }
 
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LTTNG_TRACEPOINT_H */
+
+/* The following declarations must be outside re-inclusion protection. */
+
 #ifdef 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
@@ -439,6 +454,7 @@ extern struct lttng_ust_tracepoint * const __stop___tracepoints_ptrs[]
  */
 #define _TP_EXTRACT_STRING(...)        #__VA_ARGS__
 
+#undef _DEFINE_TRACEPOINT
 #define _DEFINE_TRACEPOINT(_provider, _name, _args)                            \
        extern int __tracepoint_provider_##_provider;                           \
        static const char __tp_strtab_##_provider##___##_name[]                 \
@@ -532,19 +548,18 @@ __tracepoints__ptrs_destroy(void)
        }
 }
 
-#else /* TRACEPOINT_DEFINE */
-
-#define _DEFINE_TRACEPOINT(_provider, _name, _args)
-
-#endif /* #else TRACEPOINT_DEFINE */
-
 #ifdef __cplusplus
 }
 #endif
 
-#endif /* _LTTNG_TRACEPOINT_H */
+#endif /* _LTTNG_UST_TRACEPOINT_DEFINE_ONCE */
 
-/* The following declarations must be outside re-inclusion protection. */
+#else /* TRACEPOINT_DEFINE */
+
+#undef _DEFINE_TRACEPOINT
+#define _DEFINE_TRACEPOINT(_provider, _name, _args)
+
+#endif /* #else TRACEPOINT_DEFINE */
 
 #ifndef TRACEPOINT_ENUM
 
This page took 0.027131 seconds and 4 git commands to generate.