FreeBSD dtrace probe support
authorBen Gamari <ben@smart-cactus.org>
Mon, 16 Oct 2017 19:27:48 +0000 (15:27 -0400)
committerBen Gamari <ben@smart-cactus.org>
Mon, 16 Oct 2017 21:24:49 +0000 (17:24 -0400)
Reviewers: austin, hvr, erikd, simonmar, bgamari

Reviewed By: bgamari

Subscribers: snowleopard, raichoo, rwbarton, thomie, erikd

Differential Revision: https://phabricator.haskell.org/D3994

configure.ac
rts/RtsProbes.d
rts/ghc.mk

index 0416e83..d32ede2 100644 (file)
@@ -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
index 277a494..efbe653 100644 (file)
 # 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"
 
index 924a048..57db297 100644 (file)
@@ -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"