Mike Gerdts
2007-Dec-06 14:22 UTC
[dtrace-discuss] New _drti.o to allow USDT probes in ON libraries
While looking into adding USDT probes to libnsl''s rpc calls, I ran into problems with lint complaining[1] that fprintf, close, and a few other libc function references had found their way into libnsl. This was a result of those symbols appearing in rpc_provider.o, generated with: dtrace -G -s ../rpc/rpc_provider.d -o pics/rpc_provider.o Which under the covers does ld -o pics/rpc_provider.o -r -Blocal -Breduce /dev/fd/3 \ /usr/lib/dtrace/drti.o If we take a look at dtri.o: $ /usr/xpg4/bin/nm -u /usr/lib/dtrace/drti.o | grep FUNC [27] | 0| 0|FUNC |GLOB |0 |UNDEF |___errno [36] | 0| 0|FUNC |GLOB |0 |UNDEF |close [31] | 0| 0|FUNC |GLOB |0 |UNDEF |dlinfo [24] | 0| 0|FUNC |GLOB |0 |UNDEF |fprintf [23] | 0| 0|FUNC |GLOB |0 |UNDEF |getenv [35] | 0| 0|FUNC |GLOB |0 |UNDEF |ioctl [34] | 0| 0|FUNC |GLOB |0 |UNDEF |open64 [33] | 0| 0|FUNC |GLOB |0 |UNDEF |snprintf [28] | 0| 0|FUNC |GLOB |0 |UNDEF |strerror [26] | 0| 0|FUNC |GLOB |0 |UNDEF |strlen [32] | 0| 0|FUNC |GLOB |0 |UNDEF |strrchr [25] | 0| 0|FUNC |GLOB |0 |UNDEF |vfprintf Looking into this, I found my way to Adam''s description of _init at http://blogs.sun.com/ahl/entry/the_mysteries_of_init . This explains a lot about how USDT probes get registered with the kernel, and is the overhead that I figured must exist at startup of an instrumented program. To make lint happy[1], It seems as though an alternate drti.o that uses the libc synonyms is needed. To do this, I''ve modified libdtrace/Makefile.com to build _drti.o with (among others): +../common/$(_DRTISRC): ../common/$(DRTISRC) + echo ''/* Automatically generated - do not edit */'' > $@ + cat `echo $@ | sed ''s,/_,/,''` >> $@ + +$(_DRTIOBJ): ../common/$(_DRTISRC) + $(COMPILE.c) -DUSE_LIBC_SYNONYMS -o $@ \ + ../common/`echo $@ | sed ''s/\.o$$/\.c/''` + $(POST_PROCESS_O) And drti.c with: --- a/usr/src/lib/libdtrace/common/drti.c Tue Nov 20 23:14:54 2007 -0800 +++ b/usr/src/lib/libdtrace/common/drti.c Wed Dec 05 22:11:41 2007 -0600 @@ -25,6 +25,10 @@ */ #pragma ident "%Z%%M% %I% %E% SMI" + +#ifdef USE_LIBC_SYNONYMS +#include <c_synonyms.h> +#endif #include <unistd.h> #include <fcntl.h> I''ve also made modifications to libtrace to allow dtrace(1M) to accept -xlibcsynonyms, which triggers it to link with _drti.o rather than drti.o. This makes it so that lint no longer complains about libnsl with the added probes. Does this sound like a reasonable path to take? 1. http://www.opensolaris.org/jive/thread.jspa?messageID=182635#182635 -- Mike Gerdts http://mgerdts.blogspot.com/
Adam Leventhal
2007-Dec-07 17:40 UTC
[dtrace-discuss] New _drti.o to allow USDT probes in ON libraries
> To make lint happy[1], It seems as though an alternate drti.o that > uses the libc synonyms is needed. To do this, I''ve modified > libdtrace/Makefile.com to build _drti.o with (among others):It''s not lint that''s complaining -- it''s check_fnames(1). Does anyone know the intended purpose of this check and if it''s being applied correctly in this case?> I''ve also made modifications to libtrace to allow dtrace(1M) to accept > -xlibcsynonyms, which triggers it to link with _drti.o rather than > drti.o. This makes it so that lint no longer complains about libnsl > with the added probes.Is there something wrong with just modifying dtri.c to always use the synonyms?> Does this sound like a reasonable path to take?Sort of, but I''d like to get these questions answered first. - ahl On Thu, Dec 06, 2007 at 08:22:11AM -0600, Mike Gerdts wrote:> While looking into adding USDT probes to libnsl''s rpc calls, I ran > into problems with lint complaining[1] that fprintf, close, and a few > other libc function references had found their way into libnsl. This > was a result of those symbols appearing in rpc_provider.o, generated > with: > > dtrace -G -s ../rpc/rpc_provider.d -o pics/rpc_provider.o > > Which under the covers does > > ld -o pics/rpc_provider.o -r -Blocal -Breduce /dev/fd/3 \ > /usr/lib/dtrace/drti.o > > If we take a look at dtri.o: > > $ /usr/xpg4/bin/nm -u /usr/lib/dtrace/drti.o | grep FUNC > [27] | 0| 0|FUNC |GLOB |0 |UNDEF |___errno > [36] | 0| 0|FUNC |GLOB |0 |UNDEF |close > [31] | 0| 0|FUNC |GLOB |0 |UNDEF |dlinfo > [24] | 0| 0|FUNC |GLOB |0 |UNDEF |fprintf > [23] | 0| 0|FUNC |GLOB |0 |UNDEF |getenv > [35] | 0| 0|FUNC |GLOB |0 |UNDEF |ioctl > [34] | 0| 0|FUNC |GLOB |0 |UNDEF |open64 > [33] | 0| 0|FUNC |GLOB |0 |UNDEF |snprintf > [28] | 0| 0|FUNC |GLOB |0 |UNDEF |strerror > [26] | 0| 0|FUNC |GLOB |0 |UNDEF |strlen > [32] | 0| 0|FUNC |GLOB |0 |UNDEF |strrchr > [25] | 0| 0|FUNC |GLOB |0 |UNDEF |vfprintf > > Looking into this, I found my way to Adam''s description of _init at > http://blogs.sun.com/ahl/entry/the_mysteries_of_init . This explains > a lot about how USDT probes get registered with the kernel, and is the > overhead that I figured must exist at startup of an instrumented > program. > > To make lint happy[1], It seems as though an alternate drti.o that > uses the libc synonyms is needed. To do this, I''ve modified > libdtrace/Makefile.com to build _drti.o with (among others): > > +../common/$(_DRTISRC): ../common/$(DRTISRC) > + echo ''/* Automatically generated - do not edit */'' > $@ > + cat `echo $@ | sed ''s,/_,/,''` >> $@ > + > +$(_DRTIOBJ): ../common/$(_DRTISRC) > + $(COMPILE.c) -DUSE_LIBC_SYNONYMS -o $@ \ > + ../common/`echo $@ | sed ''s/\.o$$/\.c/''` > + $(POST_PROCESS_O) > > And drti.c with: > > --- a/usr/src/lib/libdtrace/common/drti.c Tue Nov 20 23:14:54 2007 -0800 > +++ b/usr/src/lib/libdtrace/common/drti.c Wed Dec 05 22:11:41 2007 -0600 > @@ -25,6 +25,10 @@ > */ > > #pragma ident "%Z%%M% %I% %E% SMI" > + > +#ifdef USE_LIBC_SYNONYMS > +#include <c_synonyms.h> > +#endif > > #include <unistd.h> > #include <fcntl.h> > > > I''ve also made modifications to libtrace to allow dtrace(1M) to accept > -xlibcsynonyms, which triggers it to link with _drti.o rather than > drti.o. This makes it so that lint no longer complains about libnsl > with the added probes. > > Does this sound like a reasonable path to take? > > > 1. http://www.opensolaris.org/jive/thread.jspa?messageID=182635#182635 > -- > Mike Gerdts > http://mgerdts.blogspot.com/ > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org-- Adam Leventhal, FishWorks http://blogs.sun.com/ahl
Mike Gerdts
2007-Dec-08 02:19 UTC
[dtrace-discuss] New _drti.o to allow USDT probes in ON libraries
On Dec 7, 2007 11:40 AM, Adam Leventhal <ahl at eng.sun.com> wrote:> > I''ve also made modifications to libtrace to allow dtrace(1M) to accept > > -xlibcsynonyms, which triggers it to link with _drti.o rather than > > drti.o. This makes it so that lint no longer complains about libnsl > > with the added probes. > > Is there something wrong with just modifying dtri.c to always use the > synonyms?I would be good with that - I just am not clear on the stability of the synonyms. Since drti.o gets statically linked with third-party code, is using the synonyms in drti.o appropriate? -- Mike Gerdts http://mgerdts.blogspot.com/