[lttng-dev] Emitting events from shared object constructors is (currently) not possible

Woegerer, Paul Paul_Woegerer at mentor.com
Thu Nov 22 09:08:40 EST 2012


I recently stumbled over the following lttng-ust limitation:

I tried to emit events from a shared objects constructor function:

__attribute__((constructor))
void func_constructor()
{
   tracepoint( foo, bar ); 
}

Unfortunately this doesn't work because the constructor functions of LTTng itself (__tracepoints__init and the ones from ust-tracepoint-event.h) are not yet run.

Trying to solve this problem with explicit constructor priority on my side alone doesn't work:

__attribute__((constructor (1111)))
void func_constructor()
{
   tracepoint( foo, bar ); 
}

That's because whatever I specify as priority is irrelevant. LTTng's constructors without priority will always come last.

After also adding priority to the lttng constructor I was able to make it work (see patch below):

diff --git a/include/lttng/tracepoint.h b/include/lttng/tracepoint.h
index 8b08914..532f1d2 100644
--- a/include/lttng/tracepoint.h
+++ b/include/lttng/tracepoint.h
@@ -261,7 +261,7 @@ int __tracepoint_registered
 struct tracepoint_dlopen tracepoint_dlopen
        __attribute__((weak, visibility("hidden")));
 
-static void lttng_ust_notrace __attribute__((constructor))
+static void lttng_ust_notrace __attribute__((constructor (1000)))
 __tracepoints__init(void);
 static void
 __tracepoints__init(void)
@@ -300,7 +300,7 @@ __tracepoints__init(void)
                                __start___tracepoints_ptrs);
 }
 
-static void lttng_ust_notrace __attribute__((destructor))
+static void lttng_ust_notrace __attribute__((destructor (1000)))
 __tracepoints__destroy(void);
 static void
 __tracepoints__destroy(void)
diff --git a/include/lttng/ust-tracepoint-event.h b/include/lttng/ust-tracepoint-event.h
index 74d06e1..7ad3144 100644
--- a/include/lttng/ust-tracepoint-event.h
+++ b/include/lttng/ust-tracepoint-event.h
@@ -638,7 +638,7 @@ static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PR
 
 /* Reset all macros within TRACEPOINT_EVENT */
 #include <lttng/ust-tracepoint-event-reset.h>
-static void lttng_ust_notrace __attribute__((constructor))
+static void lttng_ust_notrace __attribute__((constructor (1000)))
 _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void);
 static void
 _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void)
@@ -649,7 +649,7 @@ _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void)
        assert(!ret);
 }
 
-static void lttng_ust_notrace __attribute__((destructor))
+static void lttng_ust_notrace __attribute__((destructor (1000)))
 _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void);
 static void
 _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void)



-- 
Paul Woegerer | SW Development Engineer
http://go.mentor.com/sourceryanalyzer

Mentor Embedded(tm) | Prinz Eugen Straße 72/2/4, Vienna, 1040 Austria
Nucleus® | Linux® | Android(tm) | Services | UI | Multi-OS

Android is a trademark of Google Inc. Use of this trademark is subject to Google Permissions.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.



More information about the lttng-dev mailing list