From ab4919b5b443ac46269a5ba9f6bd00f0cbd9f35b Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Thu, 8 Feb 2024 08:46:46 -0500 Subject: [PATCH 1/1] tests: test_ust_constructor: Use a C-compiled static archive MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Jérémie Galarneau Change-Id: I3837fe318b2f8e1d9572ee0bfb6f6bbbd047c5f5 --- .../ust-constructor/test_ust_constructor.py | 4 +-- .../gen-ust-events-constructor/Makefile.am | 14 +++++++- .../gen-ust-events-constructor/main.cpp | 5 +-- .../testapp/gen-ust-events-constructor/tp-a.h | 4 --- .../tp-a_c-define.c | 8 +++++ .../tp-a_c-provider.c | 8 +++++ .../gen-ust-events-constructor/tp-a_c.h | 33 +++++++++++++++++++ 7 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 tests/utils/testapp/gen-ust-events-constructor/tp-a_c-define.c create mode 100644 tests/utils/testapp/gen-ust-events-constructor/tp-a_c-provider.c create mode 100644 tests/utils/testapp/gen-ust-events-constructor/tp-a_c.h diff --git a/tests/regression/ust/ust-constructor/test_ust_constructor.py b/tests/regression/ust/ust-constructor/test_ust_constructor.py index f4d9cedf0..f9d97e20b 100755 --- a/tests/regression/ust/ust-constructor/test_ust_constructor.py +++ b/tests/regression/ust/ust-constructor/test_ust_constructor.py @@ -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, diff --git a/tests/utils/testapp/gen-ust-events-constructor/Makefile.am b/tests/utils/testapp/gen-ust-events-constructor/Makefile.am index b323baee2..a855b25fe 100644 --- a/tests/utils/testapp/gen-ust-events-constructor/Makefile.am +++ b/tests/utils/testapp/gen-ust-events-constructor/Makefile.am @@ -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) diff --git a/tests/utils/testapp/gen-ust-events-constructor/main.cpp b/tests/utils/testapp/gen-ust-events-constructor/main.cpp index 8cb4f7898..9b754f61f 100644 --- a/tests/utils/testapp/gen-ust-events-constructor/main.cpp +++ b/tests/utils/testapp/gen-ust-events-constructor/main.cpp @@ -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"); diff --git a/tests/utils/testapp/gen-ust-events-constructor/tp-a.h b/tests/utils/testapp/gen-ust-events-constructor/tp-a.h index ab1471393..2e161b242 100644 --- a/tests/utils/testapp/gen-ust-events-constructor/tp-a.h +++ b/tests/utils/testapp/gen-ust-events-constructor/tp-a.h @@ -15,10 +15,6 @@ #include -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 index 000000000..c3496eb06 --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-constructor/tp-a_c-define.c @@ -0,0 +1,8 @@ +/* + * Copyright (C) 2024 Kienan Stewart + * + * 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 index 000000000..8d4c18407 --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-constructor/tp-a_c-provider.c @@ -0,0 +1,8 @@ +/* + * Copyright (C) 2024 Kienan Stewart + * + * 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 index 000000000..f2ab443dd --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-constructor/tp-a_c.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024 Kienan Stewart + * + * 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 + +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 + +#ifdef __cplusplus +} +#endif -- 2.34.1