tests: test_ust_constructor: Use a C-compiled static archive
authorKienan Stewart <kstewart@efficios.com>
Thu, 8 Feb 2024 13:46:46 +0000 (08:46 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 7 Mar 2024 17:11:31 +0000 (12:11 -0500)
Observed issue
==============

The test output describes the tracepoint as
`constructor_c_provider_static_archive`, which can be a bit misleading.

The tracepoints are indeed emitted inside C-style constructors. However,
as the tracepoints are being compiled inside a C++ translation unit,
they were never traceable when using a heap allocated implementation. If
the static archive is compiled as C and linked against the C++
application, the tracepoints are expected to always be visible.

Solution
========

In splitting the c-style constructors for the static archive into a
separate object the compilation can be made to use gcc instead of g++.

Drawback
========

This change doesn't keep a C-style constructor inside a C++ application
and asserts that it is indeed not traced when compiled using a heap
allocated implementation.

Signed-off-by: Kienan Stewart <kstewart@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I3837fe318b2f8e1d9572ee0bfb6f6bbbd047c5f5

tests/regression/ust/ust-constructor/test_ust_constructor.py
tests/utils/testapp/gen-ust-events-constructor/Makefile.am
tests/utils/testapp/gen-ust-events-constructor/main.cpp
tests/utils/testapp/gen-ust-events-constructor/tp-a.h
tests/utils/testapp/gen-ust-events-constructor/tp-a_c-define.c [new file with mode: 0644]
tests/utils/testapp/gen-ust-events-constructor/tp-a_c-provider.c [new file with mode: 0644]
tests/utils/testapp/gen-ust-events-constructor/tp-a_c.h [new file with mode: 0644]

index f4d9cedf04b86cab779d1f2bb997931843596914..f9d97e20b39af30f2b375f31c5282e877e2539b7 100755 (executable)
@@ -60,7 +60,7 @@ expected_events = [
         "count": 0,
     },
     {
-        "name": "tp_a:constructor_cplusplus_provider_static_archive",
+        "name": "tp_a_c:constructor_cplusplus_provider_static_archive",
         "msg": "global - static archive define and provider",
         "count": 0,
         "may_fail": compound_literal_on_heap,
@@ -259,7 +259,7 @@ expected_events = [
         "may_fail": compound_literal_on_heap,
     },
     {
-        "name": "tp_a:destructor_c_provider_static_archive",
+        "name": "tp_a_c:destructor_c_provider_static_archive",
         "msg": None,
         "count": 0,
         "may_fail": compound_literal_on_heap,
index b323baee2f2fb449f0644d0890fc707063c8e603..a855b25fe8ad4ab2f1ef6fec2bcb71ac49b942ba 100644 (file)
@@ -24,7 +24,8 @@ FORCE_SHARED_LIB_OPTIONS = -module -shared -avoid-version \
 endif
 
 noinst_LTLIBRARIES = libtp-so-provider.la libtp-so-define.la \
-                    libtp-a-provider.la libtp-a-define.la
+                    libtp-a-provider.la libtp-a-define.la \
+                    libtp-a_c-provider.la libtp-a_c-define.la
 
 # dynamic libraries
 libtp_so_provider_la_SOURCES = \
@@ -48,6 +49,15 @@ libtp_a_define_la_SOURCES = \
        tp-a-define.cpp \
        tp-a.h
 
+libtp_a_c_provider_la_SOURCES = \
+       tp-a_c-provider.c \
+       tp-a_c.h
+
+libtp_a_c_define_la_SOURCES = \
+       tp-a_c-define.c \
+       tp-a_c.h
+
+
 noinst_PROGRAMS = gen-ust-events-constructor \
        uses_heap
 gen_ust_events_constructor_SOURCES = main.cpp \
@@ -64,6 +74,8 @@ gen_ust_events_constructor_LDADD = $(UST_LIBS) \
                $(builddir)/libtp-so-provider.la \
                $(builddir)/libtp-a-define.la \
                $(builddir)/libtp-a-provider.la \
+               $(builddir)/libtp-a_c-define.la \
+               $(builddir)/libtp-a_c-provider.la \
                $(top_builddir)/tests/utils/libtestutils.la \
                $(DL_LIBS)
 
index 8cb4f78985045b6e9b5370f4aa04ee50dc0082fe..9b754f61f8d3757f9f423bdad95ba67abfc5b2c9 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "obj.h"
 #include "tp-a.h"
+#include "tp-a_c.h"
 #include "tp-so.h"
 #include "tp.h"
 
@@ -28,13 +29,13 @@ Objso g_objso_shared_library("global - shared library define and provider");
 void test_constructor_a(void) __attribute__((constructor));
 void test_constructor_a(void)
 {
-       tracepoint(tp_a, constructor_c_provider_static_archive);
+       tracepoint(tp_a_c, constructor_c_provider_static_archive);
 }
 
 void test_destructor_a(void) __attribute__((destructor));
 void test_destructor_a(void)
 {
-       tracepoint(tp_a, destructor_c_provider_static_archive);
+       tracepoint(tp_a_c, destructor_c_provider_static_archive);
 }
 
 Obja g_obja_static_archive("global - static archive define and provider");
index ab14713935c698b11af6ed3524fd0c6dafa476ec..2e161b242e81650579290156f20e9e4aca807596 100644 (file)
 
 #include <stdint.h>
 
-TRACEPOINT_EVENT(tp_a, constructor_c_provider_static_archive, TP_ARGS(), TP_FIELDS())
-
-TRACEPOINT_EVENT(tp_a, destructor_c_provider_static_archive, TP_ARGS(), TP_FIELDS())
-
 TRACEPOINT_EVENT(tp_a,
                 constructor_cplusplus_provider_static_archive,
                 TP_ARGS(const char *, msg),
diff --git a/tests/utils/testapp/gen-ust-events-constructor/tp-a_c-define.c b/tests/utils/testapp/gen-ust-events-constructor/tp-a_c-define.c
new file mode 100644 (file)
index 0000000..c3496eb
--- /dev/null
@@ -0,0 +1,8 @@
+/*
+ * Copyright (C) 2024 Kienan Stewart <kstewart@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ */
+
+#define TRACEPOINT_DEFINE
+#include "tp-a_c.h"
diff --git a/tests/utils/testapp/gen-ust-events-constructor/tp-a_c-provider.c b/tests/utils/testapp/gen-ust-events-constructor/tp-a_c-provider.c
new file mode 100644 (file)
index 0000000..8d4c184
--- /dev/null
@@ -0,0 +1,8 @@
+/*
+ * Copyright (C) 2024 Kienan Stewart <kstewart@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ */
+
+#define TRACEPOINT_CREATE_PROBES
+#include "tp-a_c.h"
diff --git a/tests/utils/testapp/gen-ust-events-constructor/tp-a_c.h b/tests/utils/testapp/gen-ust-events-constructor/tp-a_c.h
new file mode 100644 (file)
index 0000000..f2ab443
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2024 Kienan Stewart <kstewart@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER tp_a_c
+
+#if !defined(_TRACEPOINT_TP_A_C_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_TP_A_C_H
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(tp_a_c, constructor_c_provider_static_archive, TP_ARGS(), TP_FIELDS())
+
+TRACEPOINT_EVENT(tp_a_c, destructor_c_provider_static_archive, TP_ARGS(), TP_FIELDS())
+
+#endif /* _TRACEPOINT_TP_A_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./tp-a_c.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
This page took 0.028806 seconds and 4 git commands to generate.