[commit: ghc] master: FreeBSD dtrace probe support (5dab544)

git at git.haskell.org git at git.haskell.org
Mon Oct 16 21:26:52 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/5dab54428229a8d4f1658c4ad94f616b211851fe/ghc

>---------------------------------------------------------------

commit 5dab54428229a8d4f1658c4ad94f616b211851fe
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Mon Oct 16 15:27:48 2017 -0400

    FreeBSD dtrace probe support
    
    Reviewers: austin, hvr, erikd, simonmar, bgamari
    
    Reviewed By: bgamari
    
    Subscribers: snowleopard, raichoo, rwbarton, thomie, erikd
    
    Differential Revision: https://phabricator.haskell.org/D3994


>---------------------------------------------------------------

5dab54428229a8d4f1658c4ad94f616b211851fe
 configure.ac    |  4 +++-
 rts/RtsProbes.d |  7 +++++++
 rts/ghc.mk      | 40 +++++++++++++++++++++++++++++++++-------
 3 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/configure.ac b/configure.ac
index 0416e83..d32ede2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -794,7 +794,9 @@ dnl ** check for dtrace (currently only implemented for Mac OS X)
 HaveDtrace=NO
 AC_PATH_PROG(DtraceCmd,dtrace)
 if test -n "$DtraceCmd"; then
-  if test "x$TargetOS_CPP-$TargetVendor_CPP" = "xdarwin-apple" -o "x$TargetOS_CPP-$TargetVendor_CPP" = "xsolaris2-unknown"; then
+  if test "x$TargetOS_CPP-$TargetVendor_CPP" = "xdarwin-apple" \
+		-o "x$TargetOS_CPP-$TargetVendor_CPP" = "xfreebsd-portbld" \
+		-o "x$TargetOS_CPP-$TargetVendor_CPP" = "xsolaris2-unknown"; then
     HaveDtrace=YES
   fi
 fi
diff --git a/rts/RtsProbes.d b/rts/RtsProbes.d
index 277a494..efbe653 100644
--- a/rts/RtsProbes.d
+++ b/rts/RtsProbes.d
@@ -12,6 +12,13 @@
 # endif
 #endif
 
+#if defined(__FreeBSD__)
+/* we need this otherwise dtrace complains about redeclared int types
+ * TODO: find a better way to do this
+ */
+#define _INTTYPES_H_
+#endif
+
 #include "HsFFI.h"
 #include "rts/EventLogFormat.h"
 
diff --git a/rts/ghc.mk b/rts/ghc.mk
index 924a048..57db297 100644
--- a/rts/ghc.mk
+++ b/rts/ghc.mk
@@ -134,6 +134,13 @@ endif
 endif
 endif
 
+
+ifeq "$(USE_DTRACE)" "YES"
+ifneq "$(findstring $(TargetOS_CPP), linux solaris2 freebsd)" ""
+NEED_DTRACE_PROBES_OBJ = YES
+endif
+endif
+
 #-----------------------------------------------------------------------------
 # Building one way
 define build-rts-way # args: $1 = way
@@ -170,10 +177,6 @@ rts_$1_CMM_OBJS = $$(patsubst rts/%.cmm,rts/dist/build/%.$$($1_osuf),$$(rts_CMM_
 
 rts_$1_OBJS = $$(rts_$1_C_OBJS) $$(rts_$1_S_OBJS) $$(rts_$1_CMM_OBJS)
 
-ifneq "$$(findstring linux solaris2, $(TargetOS_CPP))" ""
-NEED_DTRACE_PROBES_OBJ = YES
-endif
-
 ifeq "$(USE_DTRACE)" "YES"
 ifeq "$(NEED_DTRACE_PROBES_OBJ)" "YES"
 # On Darwin we don't need to generate binary containing probes defined
@@ -181,7 +184,7 @@ ifeq "$(NEED_DTRACE_PROBES_OBJ)" "YES"
 # from the DTrace probes definitions
 rts_$1_DTRACE_OBJS = rts/dist/build/RtsProbes.$$($1_osuf)
 
-rts/dist/build/RtsProbes.$$($1_osuf) : $$(rts_$1_OBJS)
+$$(rts_$1_DTRACE_OBJS) : $$(rts_$1_OBJS)
 	$(DTRACE) -G -C $$(addprefix -I,$$(GHC_INCLUDE_DIRS)) -DDTRACE -s rts/RtsProbes.d -o \
 		$$@ $$(rts_$1_OBJS)
 endif
@@ -248,9 +251,32 @@ $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/dist/libs.depend $$(
 	  $$(rts_$1_DTRACE_OBJS) -o $$@
 endif
 else
-$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS)
+
+ifeq "$(USE_DTRACE)" "YES"
+ifeq "$(NEED_DTRACE_PROBES_OBJ)" "YES"
+rts_$1_LINKED_OBJS = rts/dist/build/RTS.$$($1_osuf)
+
+$$(rts_$1_LINKED_OBJS) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS)
+	"$$(RM)" $$(RM_OPTS) $$@
+
+	# When linking an archive the linker will only include the object files that
+	# are actually needed during linking. It therefore does not include the dtrace
+	# specific code for initializing the probes. By creating a single object that
+	# also includes the probe object code we force the linker to include the
+	# probes when linking the static runtime.
+	$(LD) -r -o $$(rts_$1_LINKED_OBJS) $$(rts_$1_DTRACE_OBJS) $$(rts_$1_OBJS)
+else
+rts_$1_LINKED_OBJS = $$(rts_$1_OBJS)
+endif
+else
+rts_$1_LINKED_OBJS = $$(rts_$1_OBJS)
+endif
+
+
+$$(rts_$1_LIB) : $$(rts_$1_LINKED_OBJS)
 	"$$(RM)" $$(RM_OPTS) $$@
-	echo $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR_STAGE1)" \
+
+	echo $$(rts_$1_LINKED_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR_STAGE1)" \
 		$$(AR_OPTS_STAGE1) $$(EXTRA_AR_ARGS_STAGE1) $$@
 
 ifneq "$$(UseSystemLibFFI)" "YES"



More information about the ghc-commits mailing list