From: Mathieu Desnoyers Date: Fri, 26 Aug 2011 15:34:46 +0000 (-0400) Subject: tracepoint: Remove TRACEPOINT_LIB declaration X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=1fcf7ad708a39a7ab3b76b3cacbee2b39b19d0db;p=ust.git tracepoint: Remove TRACEPOINT_LIB declaration Signed-off-by: Mathieu Desnoyers --- diff --git a/include/ust/tracepoint-internal.h b/include/ust/tracepoint-internal.h index 6ed7890..93d8925 100644 --- a/include/ust/tracepoint-internal.h +++ b/include/ust/tracepoint-internal.h @@ -34,6 +34,12 @@ #include #include +struct tracepoint_lib { + struct tracepoint * const *tracepoints_start; + int tracepoints_count; + struct cds_list_head list; +}; + extern int tracepoint_probe_register_noupdate(const char *name, void *probe, void *data); extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe, diff --git a/include/ust/tracepoint.h b/include/ust/tracepoint.h index 158d9b8..76645dd 100644 --- a/include/ust/tracepoint.h +++ b/include/ust/tracepoint.h @@ -46,26 +46,35 @@ struct tracepoint { #define tracepoint(name, args...) __trace_##name(args) /* - * Library should be made known to libust by declaring TRACEPOINT_LIB in - * the source file. (Usually at the end of the file, in the outermost - * scope). + * These weak symbols, the constructor, and destructor take care of + * registering only _one_ instance of the tracepoints per shared-ojbect + * (or for the whole main program). + * The dummy tracepoint entry ensures that the start/stop pointers get + * initialized by the linker when no tracepoints are present in a + * shared-object (or main program). */ -#define TRACEPOINT_LIB \ - extern struct tracepoint * const __start___tracepoints_ptrs[] __attribute__((weak, visibility("hidden"))); \ - extern struct tracepoint * const __stop___tracepoints_ptrs[] __attribute__((weak, visibility("hidden"))); \ - static struct tracepoint * __tracepoint_ptr_dummy \ - __attribute__((used, section("__tracepoints_ptrs"))); \ - static void __attribute__((constructor)) __tracepoints__init(void) \ - { \ - tracepoint_register_lib(__start___tracepoints_ptrs, \ - __stop___tracepoints_ptrs - \ - __start___tracepoints_ptrs); \ - } \ - \ - static void __attribute__((destructor)) __tracepoints__destroy(void) \ - { \ - tracepoint_unregister_lib(__start___tracepoints_ptrs); \ - } +extern struct tracepoint * const __start___tracepoints_ptrs[] + __attribute__((weak, visibility("hidden"))); +extern struct tracepoint * const __stop___tracepoints_ptrs[] + __attribute__((weak, visibility("hidden"))); +int __tracepoint_registered + __attribute__((weak, visibility("hidden"))); + +static void __attribute__((constructor)) __tracepoints__init(void) +{ + if (__tracepoint_registered++) + return; + tracepoint_register_lib(__start___tracepoints_ptrs, + __stop___tracepoints_ptrs - + __start___tracepoints_ptrs); +} + +static void __attribute__((destructor)) __tracepoints__destroy(void) +{ + if (--__tracepoint_registered) + return; + tracepoint_unregister_lib(__start___tracepoints_ptrs); +} /* * it_func[0] is never NULL because there is at least one element in the array @@ -182,12 +191,6 @@ int __tracepoint_probe_register(const char *name, void *probe, void *data); extern int __tracepoint_probe_unregister(const char *name, void *probe, void *data); -struct tracepoint_lib { - struct tracepoint * const *tracepoints_start; - int tracepoints_count; - struct cds_list_head list; -}; - extern int tracepoint_register_lib(struct tracepoint * const *tracepoints_start, int tracepoints_count); diff --git a/libust/tracepoint.c b/libust/tracepoint.c index 2b45a88..a006f70 100644 --- a/libust/tracepoint.c +++ b/libust/tracepoint.c @@ -31,14 +31,6 @@ #include -extern struct tracepoint * const __start___tracepoints_ptrs[] - __attribute__((visibility("hidden"))); -extern struct tracepoint * const __stop___tracepoints_ptrs[] - __attribute__((visibility("hidden"))); - -static struct tracepoint * __tracepoint_ptr_dummy - __attribute__((used, section("__tracepoints_ptrs"))); - /* Set to 1 to enable tracepoint debug output */ static const int tracepoint_debug; static int initialized; @@ -667,8 +659,8 @@ lib_added: /* TODO: update just the loaded lib */ lib_update_tracepoints(); - /* tracepoints_count - 1: skip dummy */ - DBG("just registered a tracepoints section from %p and having %d tracepoints (minus dummy tracepoints)", tracepoints_start, tracepoints_count); + DBG("just registered a tracepoints section from %p and having %d tracepoints", + tracepoints_start, tracepoints_count); return 0; } @@ -696,12 +688,8 @@ void init_tracepoint(void) if (uatomic_xchg(&initialized, 1) == 1) return; init_usterr(); - tracepoint_register_lib(__start___tracepoints_ptrs, - __stop___tracepoints_ptrs - - __start___tracepoints_ptrs); } void exit_tracepoint(void) { - tracepoint_unregister_lib(__start___tracepoints_ptrs); } diff --git a/libustjava/UST.c b/libustjava/UST.c index 84b7393..7ad1c71 100644 --- a/libustjava/UST.c +++ b/libustjava/UST.c @@ -13,5 +13,3 @@ JNIEXPORT void JNICALL Java_UST_ust_1java_1event (JNIEnv *env, jobject jobj, tracepoint(ust_java_event, ev_name_cstr, args_cstr); } - -TRACEPOINT_LIB diff --git a/tests/fork/fork.c b/tests/fork/fork.c index be96d81..1716257 100644 --- a/tests/fork/fork.c +++ b/tests/fork/fork.c @@ -24,7 +24,6 @@ #define TRACEPOINT_CREATE_PROBES #include "ust_tests_fork.h" -TRACEPOINT_LIB int main(int argc, char **argv, char *env[]) { diff --git a/tests/fork/fork2.c b/tests/fork/fork2.c index 42e2fac..187b7a1 100644 --- a/tests/fork/fork2.c +++ b/tests/fork/fork2.c @@ -20,7 +20,6 @@ #define TRACEPOINT_CREATE_PROBES #include "ust_tests_fork.h" -TRACEPOINT_LIB int main() { diff --git a/tests/hello/hello.c b/tests/hello/hello.c index b265b34..72a30d0 100644 --- a/tests/hello/hello.c +++ b/tests/hello/hello.c @@ -28,7 +28,6 @@ #include #include "ust_tests_hello.h" -TRACEPOINT_LIB void inthandler(int sig) {