[lttng-dev] dlopen, gcc -l and LD_PRELOAD

Jérémie Galarneau jeremie.galarneau at efficios.com
Tue Mar 19 11:51:29 EDT 2013


On Tue, Mar 19, 2013 at 10:03 AM, Thibault, Daniel
<Daniel.Thibault at drdc-rddc.gc.ca> wrote:
>> "I noticed that commit ID b834deadbfa8a78ae1d00440fd91c41dfd351eba changed README to remove a note suggesting that dlopen() not be used.  It looks like the same change should be made to doc/man/lttng-ust.3, which still suggests that you not use dlopen()."
>>
>> Just a reminder that it does appear to have been intended that that note be removed, so it should probably be disregarded.
>
>> You may want to have a look at the comment at
>> lttng-ust/include/lttng/tracepoint.h:229 which explains how this is accomplished. Basically, the tracepoint provider symbols are initialised and the probe is registered when the provider's shared object constructor is invoked. See ust-tracepoint-event.h:671 if you are interested in the actual implementation.
>
>> Have a look at the Makefiles and sources in lttng-ust/tests/demo and lttng-ust/tests/daemon which respectively demonstrate the use of tracepoint providers that are dynamically linked and built as part of the traced application.
>
>    The Makefile in lttng-ust/tests/demo is generated by automake and therefore horrendously large and complicated.  If there is a simple series of compile and link commands in there concerning the demo, that fish is thoroughly drowned.  I spotted one demo$(EXEXT) target which looked promising.  After oodles of substitutions and presuming six undefined variables were blank, it resolves to:
>
> demo : demo.o
>         @rm -f demo
>         @echo "  CCLD  " $@;/bin/bash ../../libtool --silent --tag=CC --mode=link gcc -Wall -g -02 -L/usr/local/lib -o $@ demo.o -ldl
>
> ...which isn't very enlightening (in the sense that it looks pretty plain).  There is in fact no trace of '.so' or '-fPIC' in the make.  What is needed is a pared-down makefile like the one in easy-ust.  I think I have figured out the correct outline, except for the tracepoint_dlopen problem.  But since the package's demo-trace runs smack into the same error, I'm suspecting the fault may not be mine.  Googling for this error turns up mostly cases where -shared was omitted from the lib*.so gcc call, resulting in pieces of static libraries being imported into dynamic ones.   This is not what's going on here.
>
>> > /usr/bin/ld: warning: hidden symbol 'tracepoint_dlopen' in sample.o is referenced by DSO ./libtp.so
>> >
>> > lttng-ust/tests/demo/demo-trace, although built by lttng-ust's make, also has the tracepoint_dlopen problem.  This now looks like a bug introduced somewhen since the demos were written (and last tested, it seems).
>>
>> I don't see this warning and error here. Which release are you using?
>
>    lttng-modules 2.1.1+ (74b9312, 2013-02-27)
>    lttng-tools 2.1.1+ (e58727c, 2013-03-01)
>    lttng-ust 2.1.1+ (009769c, 2013-03-05)
>    userspace-rcu 0.7.6+ (108a92e, 2013-02-22)
>

I can confirm I'm able to reproduce the problem with these versions.

>    (All are moderately dated by now, but none of the later commit comments seem pertinent)
>

This revision fixed the "undefined symbol: tracepoint_dlopen" problem:
https://bugs.lttng.org/projects/lttng-ust/repository/revisions/558b9d86247004f8e9bbaf8c982f3b2b182093d1

>   If I run lttng-ust/tests/demo/demo-trace, I get:
>
> ./demo: symbol lookup error: .libs/liblttng-ust-provider-ust-tests-demo3.so: undefined symbol: tracepoint_dlopen
>
>    All that demo-trace does is LD_PRELOAD .libs/liblttng-ust-provider-ust-tests-demo.so and .libs/liblttng-ust-provider-ust-tests-demo3.so before running ./demo
>
>    The make of lttng-ust, when it compiled demo.o, only warned that struct mmsghdr was declared inside a parameter list (/usr/include/x86_64-linux-gnu/bits/socket.h so it's not even an lttng problem).
>
>    Are you saying you can't reproduce this?  Your demo-trace runs and generates events?
>
>    Meanwhile I'll dive in and try to untangle what TRACEPOINT_PROBE_DYNAMIC_LINKAGE does.
>
> Daniel U. Thibault
> R & D pour la défense Canada - Valcartier (RDDC Valcartier) / Defence R&D Canada - Valcartier (DRDC Valcartier)
> Cyber sécurité pour les missions essentielles (CME) / Mission Critical Cyber Security (MCCS)
> Protection des systèmes et contremesures (PSC) / Systems Protection & Countermeasures (SPC)
> 2459 route de la Bravoure
> Québec, QC  G3J 1X5
> CANADA
> Vox : (418) 844-4000 x4245
> Fax : (418) 844-4538
> NAC : 918V QSDJ <http://www.travelgis.com/map.asp?addr=918V%20QSDJ>
> Gouvernement du Canada / Government of Canada
> <http://www.valcartier.drdc-rddc.gc.ca/>



More information about the lttng-dev mailing list