In my previous note on this mailing list, forget the bit about LD_PRELOAD being beholden to the remaining library search. I got fooled into thinking that for unrelated reasons. Turns out LD_PRELOAD loads the so regardless of the search's outcome: it's just added to the list of dependencies to load (traversal is breadth-first, it turns out), and its initializer called last.
Here is a suggested updated lttng-ust/doc/examples/easy-ust/Makefile which fixes a minor problem (missing LDFLAGS preventing make from succeeding out-of-the-box) and adds additional targets demonstrating other ways tracepoints can be compiled into an application. Please review this for any factual errors. - - - BEGIN - - - # Copyright (C) 2011-2012 Matthew Khouzam <[email protected]> # Copyright (C) 2012 Mathieu Desnoyers <[email protected]> # # THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED # OR IMPLIED. ANY USE IS AT YOUR OWN RISK. # # Permission is hereby granted to use or copy this program for any # purpose, provided the above notices are retained on all copies. # Permission to modify the code and to distribute modified code is # granted, provided the above notices are retained, and a notice that # the code was modified is included with the above copyright notice. # # This makefile is not using automake so that people can see how to make # simply. It builds a sample program in any one of four (really three) ways: # # ("static", default) with a statically embedded tracepoint provider probe, # through inclusion. # # ("staticlib") with a statically embedded tracepoint provider probe, through # a static library (libtp.a). The resulting samplestaticlib binary is identical # to the samplestatic binary. # # ("dynamic", "dynamicfull") with a dynamically loaded shared library # (libtp.so). The only difference between these two is that "dynamicfull" sets # the TRACEPOINT_PROBE_DYNAMIC_LINKAGE define in order to avoid needing to be # linked statically with the shared library. # # Currently, an instrumented application that would use a dynamically linked # (as opposed to dynamically loaded) tracepoint provider shared library would # still dynamically load it (using the dlopen() system call), so the difference # is pointless. # # The dynamic samples must use LD_PRELOAD to run because the trace provider # shared library (libtp.so) is not in the library search path; to obviate this # requirement, you can either install your trace provider shared library in # the library search path (e.g. /usr/local/lib) or add a DT_RUNPATH tag to your # sample so it looks in its own directory for missing libraries (look for the # commented-out "$(CC) ... -Wl,-rpath,\$ORIGIN,--enable-new-dtags" lines in # the "dynamic" and "dynamicfull" targets). The latter option does have the # disadvantage that the dynamic linker will look for all the required libraries # (libdl.so, libc.so, liblttng-ust.so, etc.) in sample's directory first. # # The "html" target helps for documentation (req. code2html). AR = ar CC = gcc LIBS = -ldl -llttng-ust # On Linux #LIBS = -lc -llttng-ust # On BSD CFLAGS = -I. LDFLAGS = -L/usr/local/lib SOFLAGS = -fPIC SOVERSION_MAJOR = 1 SOVERSION_MINOR = 0 # default make is "all" all: static static: sample.o tp.o $(CC) -o sample$@ $^ $(LDFLAGS) $(LIBS) @echo " Use './sample$@' to run sample$@" staticlib: sample.o libtp.a $(CC) -o sample$@ $^ $(LDFLAGS) $(LIBS) -L. @echo " Use './sample$@' to run sample$@" dynamic: sample.o libtp.so # $(CC) -o sample$@ $< $(LDFLAGS) $(LIBS) -L. -ltp \ # -Wl,-rpath,\$ORIGIN,--enable-new-dtags $(CC) -o sample$@ $< $(LDFLAGS) $(LIBS) -L. -ltp @echo " Use 'LD_PRELOAD=./libtp.so ./sample$@' to run sample$@" dynamicfull: sampledynamic.o libtp.so # $(CC) -o sample$@ $< $(LDFLAGS) $(LIBS) \ # -Wl,-rpath,\$ORIGIN,--enable-new-dtags $(CC) -o sample$@ $< $(LDFLAGS) $(LIBS) @echo " Use 'LD_PRELOAD=./libtp.so ./sample$@' to run sample$@" sample.o: sample.c sample_component_provider.h $(CC) $(CFLAGS) -c -o $@ $< sampledynamic.o: sample.c sample_component_provider.h $(CC) $(CFLAGS) -D TRACEPOINT_PROBE_DYNAMIC_LINKAGE -c -o $@ $< libtp.a: tp.o $(AR) -cq $@ $< libtp.so: libtp.o $(CC) -shared -Wl,-soname,$@.$(SOVERSION_MAJOR) -o \ $@.$(SOVERSION_MAJOR).$(SOVERSION_MINOR) $(LDFLAGS) $(LIBS) $< ln -sf $@.$(SOVERSION_MAJOR).$(SOVERSION_MINOR) $@.$(SOVERSION_MAJOR) ln -sf $@.$(SOVERSION_MAJOR) $@ libtp.o: tp.c sample_component_provider.h $(CC) $(CFLAGS) $(SOFLAGS) -c -o $@ $< tp.o: tp.c sample_component_provider.h $(CC) $(CFLAGS) -c -o $@ $< html: sample_component_provider.html sample.html tp.html %.html: %.c code2html -lc $< $@ %.html : %.h code2html -lc $< $@ .PHONY: clean clean: rm -f *.html rm -f *.o *.a *.so *.so.* rm -f samplestatic* sampledynamic* - - - END - - - 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/> _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
