dynamic-linking: note about instrumenting a SO
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 19 Dec 2014 21:17:21 +0000 (16:17 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 19 Dec 2014 21:19:35 +0000 (16:19 -0500)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
contents/using-lttng/instrumenting/c-application/building-linking/dynamic-linking.md

index e52363bc78715ea0b5bf02f2f03e14ab6193d013..aec70c690ad82cd65566e2a8ac1792974aeb3c51 100644 (file)
@@ -68,15 +68,48 @@ provider, but still needs `libdl`:
 gcc -o app other.o files.o of.o your.o app.o <strong>-ldl</strong>
 </pre>
 
-Now, to make LTTng-UST tracing available to the application,
-the `LD_PRELOAD` environment variable is used to preload the
-tracepoint provider shared library _before_ the application actually
-starts:
+Now, to make LTTng-UST tracing available to the application, the
+`LD_PRELOAD` environment variable is used to preload the tracepoint
+provider shared library _before_ the application actually starts:
 
 <pre class="term">
 <strong>LD_PRELOAD=/path/to/tp.so</strong> ./app
 </pre>
 
+<div class="tip">
+<p>
+    <span class="t">Note:</span>It is not safe to use
+    <code>dlclose()</code> on a tracepoint provider shared object that
+    is being actively used for tracing, due to a lack of reference
+    counting from LTTng-UST to the shared object.
+</p>
+
+<p>
+    For example, statically linking a tracepoint provider to a
+    shared object which is to be dynamically loaded by an application
+    (e.g., a plugin) is not safe: the shared object, which contains the
+    tracepoint provider, could be dynamically closed
+    (<code>dlclose()</code>) at any time by the application.
+</p>
+
+<p>
+    To instrument a shared object, either:
+</p>
+
+<ol>
+    <li>
+        Statically link the tracepoint provider to the
+        <em>application</em>, or
+    </li>
+    <li>
+        Build the tracepoint provider as a shared object (following
+        the procedure shown in this section), and preload it when
+        tracing is needed using the <code>LD_PRELOAD</code>
+        environment variable.
+    </li>
+</ol>
+</div>
+
 Your application will still work without this preloading, albeit without
 LTTng-UST tracing support:
 
This page took 0.023578 seconds and 4 git commands to generate.