Bug #597
closedlttng-gen-tp: tracepoint provider templates fail when SystemTap and C++ are combined
100%
Description
I have a small C++ application that demonstrates LTTng instrumentation (user-space tracepoints). However, when I try to make it after installing SystemTap, the make fails badly:
error: template with C linkage error: template specialization with C linkage (28 times) error: template with C linkage (twice)
This occurs starting at sdt.h
line 71. A little investigation reveals the problem is caused by sdt.h
using C++ templates (the templates are within an #ifdef __cplusplus
block). C++ templates cannot be inside an extern "C"
block (it's a peculiarity of the C++ spec; see http://stackoverflow.com/questions/4877705/why-cant-templates-be-within-extern-c-blocks for the details). tracepoint.h
correctly calls sdt.h
before entering its own extern "C"
block, but the lttng-ust/doc/examples/easy-ust/sample_component_provider.h
wraps its call to #include <lttng/tracepoint.h>
in such a block. Hence kablooie.
It looks like the tracepoint provider header should change from:
#undef TRACEPOINT_PROVIDER #define TRACEPOINT_PROVIDER sample_component #undef TRACEPOINT_INCLUDE #define TRACEPOINT_INCLUDE "./tp.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #if !defined(_SAMPLE_COMPONENT_PROVIDER_H) || defined(TRACEPOINT_HEADER_MULTI_READ) #define _SAMPLE_COMPONENT_PROVIDER_H #include <lttng/tracepoint.h> [...]
To:
#undef TRACEPOINT_PROVIDER #define TRACEPOINT_PROVIDER sample_component #undef TRACEPOINT_INCLUDE #define TRACEPOINT_INCLUDE "./tp.h" #include <lttng/tracepoint.h> #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #if !defined(_SAMPLE_COMPONENT_PROVIDER_H) || defined(TRACEPOINT_HEADER_MULTI_READ) #define _SAMPLE_COMPONENT_PROVIDER_H [...]
This moves the #include <lttng/tracepoint.h>
line up and out of the extern "C"
block. Maybe the _SAMPLE_COMPONENT_PROVIDER_H
line should move along, I don't know for sure.
I rebuilt my various samples using this modified tracepoint provider header and everything now works as it did before SystemTap was installed.
If this is indeed the correct fix (maybe there are other circumstances that justify keeping the #include <lttng/tracepoint.h>
inside an extern "C"
block), then lttng-gen-tp
will need to be modified. So will the sample tracepoint provider headers in lttng-ust/doc/examples
.