From 1f225be2e51f0ff7376846d5631fd6287eb03d14 Mon Sep 17 00:00:00 2001 From: ngoto Date: Sun, 18 Nov 2012 08:24:24 +0000 Subject: [PATCH] * configure.in, Makefile.in, common.mk: support DTrace on Solaris 10, based on r26235 by Yugui. On Solaris 10, low optimization level may also be needed, e.g. optflags="-xO1" or "-xO0" with Oracle SolarisStudio 12.3 cc. * configure.in (--enable-dtrace): new option to enable/disable DTrace support. By default, trying to enable if dtrace command is found on the system. It is disabled when cross compiling. * configure.in (RUBY_DTRACE_POSTPROCESS): new macro. checks whether the dtrace on the system needs postprocessing with "dtrace -G". The postprocessing is needed on Solaris 10 and other platforms. * configure.in (RUBY_DTRACE_BSD_BROKEN): new macro. checks whether the dtrace supports USDT. * configure.in (DTRACE): move after RUBY_DTRACE_POSTPROCESS. * configure.in (LD): On Solaris, /usr/ccs/bin/ld is preferred. * configure.in, Makefile.in, common.mk (DTRACE_OBJ): new macro for DTrace probe object generated by postprocessing with "dtrace -G". * Makefile.in, common.mk (probes.$(OBJEXT)): DTrace probe object generated by the postprocessing. New file probes.stamp is for rebuilding related objects that may be modified by "dtrace -G". * configure.in, Makefile.in, common.mk (DTRACE_GLOMMED_OBJ): new macro for DTrace static library hacks. * configure.in, Makefile.in (LIBRUBY_A_OBJS): ditto. * Makefile.in, common.mk (ruby-glommed.$(OBJEXT)): new target with rule for DTrace static library hacks. * common.mk (DTRACE_DEPENDENT_OBJS): objects depended on probes.h. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 39 ++++++++++++++++++ Makefile.in | 28 +++++++++++-- common.mk | 19 +++++++-- configure.in | 111 ++++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 176 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 99681a2089..0ae387bed6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,42 @@ +Sun Nov 18 16:33:00 2012 Naohisa Goto + + * configure.in, Makefile.in, common.mk: support DTrace on Solaris 10, + based on r26235 by Yugui. On Solaris 10, low optimization level + may also be needed, e.g. optflags="-xO1" or "-xO0" with Oracle + SolarisStudio 12.3 cc. + + * configure.in (--enable-dtrace): new option to enable/disable + DTrace support. By default, trying to enable if dtrace command + is found on the system. It is disabled when cross compiling. + + * configure.in (RUBY_DTRACE_POSTPROCESS): new macro. checks whether + the dtrace on the system needs postprocessing with "dtrace -G". + The postprocessing is needed on Solaris 10 and other platforms. + + * configure.in (RUBY_DTRACE_BSD_BROKEN): new macro. checks whether + the dtrace supports USDT. + + * configure.in (DTRACE): move after RUBY_DTRACE_POSTPROCESS. + + * configure.in (LD): On Solaris, /usr/ccs/bin/ld is preferred. + + * configure.in, Makefile.in, common.mk (DTRACE_OBJ): new macro for + DTrace probe object generated by postprocessing with "dtrace -G". + + * Makefile.in, common.mk (probes.$(OBJEXT)): DTrace probe object + generated by the postprocessing. New file probes.stamp is for + rebuilding related objects that may be modified by "dtrace -G". + + * configure.in, Makefile.in, common.mk (DTRACE_GLOMMED_OBJ): new + macro for DTrace static library hacks. + + * configure.in, Makefile.in (LIBRUBY_A_OBJS): ditto. + + * Makefile.in, common.mk (ruby-glommed.$(OBJEXT)): new target with + rule for DTrace static library hacks. + + * common.mk (DTRACE_DEPENDENT_OBJS): objects depended on probes.h. + Sun Nov 18 09:31:47 2012 Tadayoshi Funaba * complex.c (read_comp): mathn compliant. diff --git a/Makefile.in b/Makefile.in index 9df9dcbb04..46033d0c07 100644 --- a/Makefile.in +++ b/Makefile.in @@ -119,6 +119,7 @@ LIBRUBYARG = @LIBRUBYARG@ LIBRUBYARG_STATIC = @LIBRUBYARG_STATIC@ LIBRUBYARG_SHARED = @LIBRUBYARG_SHARED@ LIBRUBY_RELATIVE = @LIBRUBY_RELATIVE@ +LIBRUBY_A_OBJS = @LIBRUBY_A_OBJS@ THREAD_MODEL = @THREAD_MODEL@ @@ -149,6 +150,8 @@ VCS = @VCS@ VCSUP = @VCSUP@ DTRACE = @DTRACE@ DTRACE_EXT = @DTRACE_EXT@ +DTRACE_OBJ = @DTRACE_OBJ@ +DTRACE_GLOMMED_OBJ = @DTRACE_GLOMMED_OBJ@ OBJEXT = @OBJEXT@ ASMEXT = S @@ -184,7 +187,7 @@ all: miniruby$(EXEEXT): @-if test -f $@; then $(MV) -f $@ $@.old; $(RM) $@.old; fi $(ECHO) linking $@ - $(Q) $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) $(MAINLIBS) $(NORMALMAINOBJ) $(MINIOBJS) $(COMMONOBJS) $(DMYEXT) $(LIBS) $(OUTFLAG)$@ + $(Q) $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) $(MAINLIBS) $(NORMALMAINOBJ) $(MINIOBJS) $(COMMONOBJS) $(DMYEXT) $(DTRACE_OBJ) $(LIBS) $(OUTFLAG)$@ $(PROGRAM): @$(RM) $@ @@ -198,7 +201,7 @@ $(PROGRAM): $(LIBRUBY_A): @$(RM) $@ $(ECHO) linking static-library $@ - $(Q) $(AR) $(ARFLAGS) $@ $(OBJS) $(DMYEXT) + $(Q) $(AR) $(ARFLAGS) $@ $(LIBRUBY_A_OBJS) $(DMYEXT) @-$(RANLIB) $@ 2> /dev/null || true $(ECHO) verifying static-library $@ @$(PURIFY) $(CC) $(XLDFLAGS) $(MAINOBJ) $(LIBRUBY_A) $(MAINLIBS) $(EXTLIBS) $(LIBS) $(OUTFLAG)conftest$(EXEEXT) $(LDFLAGS) @@ -207,7 +210,7 @@ $(LIBRUBY_A): $(LIBRUBY_SO): @-$(PRE_LIBRUBY_UPDATE) $(ECHO) linking shared-library $@ - $(Q) $(LDSHARED) $(DLDFLAGS) $(OBJS) $(DLDOBJS) $(SOLIBS) $(EXTSOLIBS) $(OUTFLAG)$@ + $(Q) $(LDSHARED) $(DLDFLAGS) $(OBJS) $(DLDOBJS) $(DTRACE_OBJ) $(SOLIBS) $(EXTSOLIBS) $(OUTFLAG)$@ -$(Q) $(OBJCOPY) -w -L '$(SYMBOL_PREFIX)Init_*' -L '$(SYMBOL_PREFIX)*_threadptr_*' $@ @-$(MINIRUBY) -e 'ARGV.each{|link| File.delete link if File.exist? link; \ File.symlink "$(LIBRUBY_SO)", link}' \ @@ -334,6 +337,25 @@ probes.h: probes.$(DTRACE_EXT) $(Q) sed -e 's/RUBY_/RUBY_DTRACE_/g' -e 's/PROBES_H_TMP/PROBES_H/g' $@.tmp > $@ $(Q) $(RM) $@.tmp +probes.@OBJEXT@: $(srcdir)/probes.d + @$(ECHO) processing probes in object files + $(Q) stamp="$*.stamp"; \ + if test -f "$$stamp" -o -f "$@"; then \ + $(RM) $(DTRACE_DEPENDENT_OBJS) "$$stamp"; \ + for o in $(DTRACE_DEPENDENT_OBJS); do \ + echo "rebuilding $$o which was modified by \"dtrace -G\""; \ + $(MAKE) "$$o"; \ + done; \ + fi; \ + touch "$$stamp" + $(Q) $(DTRACE) -G -s $(srcdir)/probes.d -o $@ $(DTRACE_DEPENDENT_OBJS) + +# DTrace static library hacks described here: +# http://mail.opensolaris.org/pipermail/dtrace-discuss/2005-August/000207.html +ruby-glommed.$(OBJEXT): + @$(ECHO) generating a glommed object with DTrace probes for static library + $(Q) $(LD) -r -o $@ $(OBJS) $(DTRACE_OBJ) + clean-local:: $(Q)$(RM) ext/extinit.c ext/extinit.$(OBJEXT) ext/ripper/y.output \ enc/encinit.c enc/encinit.$(OBJEXT) diff --git a/common.mk b/common.mk index 3a47897625..9d34d28a64 100644 --- a/common.mk +++ b/common.mk @@ -189,7 +189,7 @@ loadpath: $(PREP) PHONY $(PREP): $(MKFILES) -miniruby$(EXEEXT): config.status $(ALLOBJS) $(ARCHFILE) +miniruby$(EXEEXT): config.status $(ALLOBJS) $(ARCHFILE) $(DTRACE_OBJ) objs: $(ALLOBJS) @@ -214,7 +214,7 @@ wprogram: showflags $(WPROGRAM) $(PROGRAM) $(WPROGRAM): $(LIBRUBY) $(MAINOBJ) $(OBJS) $(EXTOBJS) $(SETUP) $(PREP) -$(LIBRUBY_A): $(OBJS) $(MAINOBJ) $(DMYEXT) $(ARCHFILE) +$(LIBRUBY_A): $(OBJS) $(MAINOBJ) $(DTRACE_OBJ) $(DTRACE_GLOMMED_OBJ) $(DMYEXT) $(ARCHFILE) $(LIBRUBY_SO): $(OBJS) $(DLDOBJS) $(LIBRUBY_A) $(PREP) $(LIBRUBY_SO_UPDATE) $(BUILTIN_ENCOBJS) @@ -435,7 +435,7 @@ clean: clean-ext clean-local clean-enc clean-golf clean-rdoc clean-capi clean-ex clean-local:: PHONY $(Q)$(RM) $(OBJS) $(MINIOBJS) $(MAINOBJ) $(LIBRUBY_A) $(LIBRUBY_SO) $(LIBRUBY) $(LIBRUBY_ALIASES) $(Q)$(RM) $(PROGRAM) $(WPROGRAM) miniruby$(EXEEXT) dmyext.$(OBJEXT) $(ARCHFILE) .*.time - $(Q)$(RM) y.tab.c y.output encdb.h transdb.h prelude.c config.log rbconfig.rb $(ruby_pc) probes.h + $(Q)$(RM) y.tab.c y.output encdb.h transdb.h prelude.c config.log rbconfig.rb $(ruby_pc) probes.h probes.$(OBJEXT) probes.stamp ruby-glommed.$(OBJEXT) clean-ext:: PHONY clean-golf: PHONY $(Q)$(RM) $(GORUBY)$(EXEEXT) $(GOLFOBJS) @@ -814,6 +814,19 @@ newline.$(OBJEXT): $(NEWLINE_C) {$(VPATH)}defines.h \ {$(VPATH)}intern.h {$(VPATH)}missing.h {$(VPATH)}st.h \ {$(VPATH)}transcode_data.h {$(VPATH)}ruby.h {$(VPATH)}config.h {$(VPATH)}subst.h +DTRACE_DEPENDENT_OBJS = array.$(OBJEXT) \ + eval.$(OBJEXT) \ + gc.$(OBJEXT) \ + hash.$(OBJEXT) \ + load.$(OBJEXT) \ + object.$(OBJEXT) \ + parse.$(OBJEXT) \ + string.$(OBJEXT) \ + vm.$(OBJEXT) + +probes.$(OBJEXT): $(DTRACE_DEPENDENT_OBJS) +ruby-glommed.$(OBJEXT): $(OBJS) $(DTRACE_OBJ) + $(OBJS): {$(VPATH)}config.h {$(VPATH)}missing.h INSNS2VMOPT = --srcdir="$(srcdir)" diff --git a/configure.in b/configure.in index 8560bee456..2afe75498f 100644 --- a/configure.in +++ b/configure.in @@ -378,7 +378,9 @@ AC_PROG_CXX RUBY_MINGW32 AC_PROG_GCC_TRADITIONAL AC_SUBST(GCC) -AC_CHECK_TOOL([LD], [ld], [ld]) +AS_CASE(["$target_os"], +[solaris*], [AC_PATH_TOOL([LD], [ld], [/usr/ccs/bin/ld], [/usr/ccs/bin:$PATH])], +[AC_CHECK_TOOL([LD], [ld], [ld])]) AC_SUBST(LD) if test "$GCC" = yes; then linker_flag=-Wl, @@ -388,20 +390,6 @@ else linker_flag= fi -AC_CHECK_PROG([DTRACE], [${ac_tool_prefix}dtrace], [${ac_tool_prefix}dtrace]) -if test "$cross_compiling:$ac_cv_prog_DTRACE" = no: -a -n "$ac_tool_prefix"; then - AC_CHECK_PROG([DTRACE], [dtrace], [dtrace]) -fi -AS_CASE(["$target_os"], -[freebsd*], [DTRACE=] -) -if test -n "$DTRACE"; then - DTRACE_EXT=d -else - DTRACE_EXT=dmyh -fi -AC_SUBST(DTRACE_EXT) - RUBY_PROG_GNU_LD RUBY_CPPOUTFILE @@ -476,6 +464,54 @@ fi MAKEDIRS="$MKDIR_P" AC_SUBST(MAKEDIRS) +AC_DEFUN([RUBY_DTRACE_POSTPROCESS], +[AC_CACHE_CHECK(whether $DTRACE needs post processing, rb_cv_prog_dtrace_g, +[ + echo "int main(void){ return 0; }" > conftest.c + echo "provider conftest{};" > conftest_provider.d + $CC $CFLAGS -c -o conftest.o conftest.c + if $DTRACE -G -s conftest_provider.d conftest.o 2>/dev/null; then + rb_cv_prog_dtrace_g=yes + $1 + else + rb_cv_prog_dtrace_g=no + $2 + fi + rm -f conftest.o conftest.c conftest_provider.d conftest_provider.o +]) +]) + +AC_DEFUN([RUBY_DTRACE_BSD_BROKEN], +[AC_CACHE_CHECK(whether dtrace USDT is broken, rb_cv_dtrace_bsd_broken, +[ + cat < conftest.c +#define _DTRACE_VERSION 1 +#include "conftest_provider.h" +int main(void) +{ + if (CONFTEST_FIRE_ENABLED()) CONFTEST_FIRE(); + return 0; +} +EOF + echo "provider conftest{ probe fire(); };" > conftest_provider.d + $DTRACE -h -o conftest_provider.h -s conftest_provider.d + $CC $CFLAGS -c -o conftest.o conftest.c + if $DTRACE -G -o conftest_provider.o -s conftest_provider.d conftest.o >/dev/null 2>/dev/null; then + rb_cv_dtrace_bsd_broken=no + $2 + else + rb_cv_dtrace_bsd_broken=yes + $1 + fi + rm -f conftest.[co] conftest_provider.[dho] +]) +]) + +AC_CHECK_PROG([DTRACE], [${ac_tool_prefix}dtrace], [${ac_tool_prefix}dtrace]) +if test "$cross_compiling:$ac_cv_prog_DTRACE" = no: -a -n "$ac_tool_prefix"; then + AC_CHECK_PROG([DTRACE], [dtrace], [dtrace]) +fi + AC_CHECK_PROGS(DOT, dot) AC_CHECK_PROGS(DOXYGEN, doxygen) AS_CASE(["${host_os}"], [nacl], [AC_PATH_PROG(PYTHON, python)]) @@ -2693,6 +2729,51 @@ if test "$EXEEXT" = .exe; then AC_SUBST(EXECUTABLE_EXTS) fi +AC_ARG_ENABLE(dtrace, + AS_HELP_STRING([--enable-dtrace], + [enable DTrace for tracing ruby's internal.]), + [enable_dtrace=$enableval], [enable_dtrace=auto]) + +if test "${enable_dtrace}" = "auto"; then + if test x"$DTRACE" != x -a x"$cross_compiling" != xyes; then + RUBY_DTRACE_POSTPROCESS() + if test "$rb_cv_prog_dtrace_g" = 'yes'; then + RUBY_DTRACE_BSD_BROKEN([enable_dtrace=no], [enable_dtrace=yes]) + else + enable_dtrace=yes + AS_CASE(["$target_os"], + [freebsd*], [enable_dtrace=no] + ) + fi + else + enable_dtrace=no + fi +fi + +LIBRUBY_A_OBJS='$(OBJS)' +if test "${enable_dtrace}" = "yes"; then + if test -z "$DTRACE"; then + AC_MSG_ERROR([dtrace(1) is missing]) + elif test "$cross_compiling" = yes; then + AC_MSG_ERROR([--enable-dtrace, however, cross compiling]) + else + RUBY_DTRACE_POSTPROCESS() + if test "$rb_cv_prog_dtrace_g" = 'yes'; then + RUBY_DTRACE_BSD_BROKEN([AC_MSG_ERROR([--enable-dtrace, however, USDT is broken])], []) + DTRACE_OBJ='probes.$(OBJEXT)' + DTRACE_GLOMMED_OBJ='ruby-glommed.$(OBJEXT)' + LIBRUBY_A_OBJS='$(DTRACE_GLOMMED_OBJ)' + fi + fi + DTRACE_EXT=d +else + DTRACE_EXT=dmyh +fi +AC_SUBST(DTRACE_EXT) +AC_SUBST(DTRACE_OBJ) +AC_SUBST(DTRACE_GLOMMED_OBJ) +AC_SUBST(LIBRUBY_A_OBJS) + } { # build section