public inbox for dtrace@lists.linux.dev
 help / color / mirror / Atom feed
From: Nick Alcock <nick.alcock@oracle.com>
To: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Cc: sam@gentoo.org
Subject: [PATCH 03/14] configure, build: make valgrind optional
Date: Thu, 24 Oct 2024 12:37:47 +0100	[thread overview]
Message-ID: <20241024113758.182050-4-nick.alcock@oracle.com> (raw)
In-Reply-To: <20241024113758.182050-1-nick.alcock@oracle.com>

We fail building if <valgrind/valgrind.h> is not available, which is
ridiculous given that the only reason we need it is to make valgrind go away
at suitable moments to let us drop uprobes.

A suitable new configure check (using a new check-header-macro-rule
function) lets us check for <valgrind/valgrind.h> and disable it if not
present: as usual, defining HAVE_VALGRIND or passing it to configure will
also suffice to override the check (though since the code this enables
doesn't require any part of valgrind at runtime, I don't see why one would
ever need to do so).

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
Bug: https://github.com/oracle/dtrace-utils/issues/80
---
 Makeconfig          | 36 ++++++++++++++++++++++++++++++++++++
 configure           |  1 +
 libdtrace/dt_work.c | 18 +++++++++++++++---
 3 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/Makeconfig b/Makeconfig
index 346078598624..752bd79b01fc 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -163,6 +163,41 @@ $(CONFIG_H): $(objdir)/.config/config.$(1).h
 $(CONFIG_MK): $(objdir)/.config/config.$(1).mk
 endef
 
+# Generate a makefile rule to check for the presence of MACRO
+# in HEADER and emit an appropriate header file fragment into a file
+# under $(objdir)/.config.
+#
+# The first argument must be suitable for a filename fragment,
+# for a makefile rule name and for a #define.
+#
+# Syntax: $(call check-header-macro-rule,name,macro,header)
+define check-header-macro-rule
+$(objdir)/.config/config.$(1).h $(objdir)/.config/config.$(1).mk: $(objdir)/.config/.dir.stamp
+	case x$(HAVE_$(1)) in \
+	xyes) echo '#define HAVE_$(1) 1' > $(objdir)/.config/config.$(1).h; \
+	     echo 'HAVE_$(1)=y' > $(objdir)/.config/config.$(1).mk;; \
+	xno) echo '/* #undef HAVE_$(1) */' > $(objdir)/.config/config.$(1).h; \
+	     echo '# HAVE_$(1) undefined' > $(objdir)/.config/config.$(1).mk;; \
+	*) if printf '#include <%s.h>\n#ifndef %s\n#error %s not found.\n#endif' "$(3)" "$(2)" "$(2)" | \
+	       $(CC) $(filter-out --coverage,$(CFLAGS) $(LDFLAGS)) -Iinclude -D_GNU_SOURCE -Werror=implicit-function-declaration -c -o /dev/null -x c - >/dev/null 2>&1; then \
+	       echo '#define HAVE_$(1) 1' > $(objdir)/.config/config.$(1).h; \
+	       echo 'HAVE_$(1)=y' > $(objdir)/.config/config.$(1).mk; \
+	   else \
+	       echo '/* #undef HAVE_$(1) */' > $(objdir)/.config/config.$(1).h; \
+	       echo '# HAVE_$(1) undefined' > $(objdir)/.config/config.$(1).mk; \
+	   fi;; \
+	*) echo "HAVE_$(1) must be yes or no, not $(HAVE_$(1))" >&2; \
+	   false;; \
+	esac
+	rm -f $(CONFIG_H)
+	rm -f $(CONFIG_MK)
+
+$(eval $(call make-override-help,HAVE_$(1), presence of preprocessor macro $(2) in $(3).h))
+
+$(CONFIG_H): $(objdir)/.config/config.$(1).h
+$(CONFIG_MK): $(objdir)/.config/config.$(1).mk
+endef
+
 # Generate a makefile rule to check for support for OPTION in BPFC and emit an
 # appropriate header file fragment into a file under $(objdir)/.config.
 #
@@ -229,6 +264,7 @@ $(eval $(call check-header-rule,DIS1,disassembler(NULL),disasm))
 $(eval $(call check-header-rule,DIS4,disassembler(0,0,0,NULL),disasm))
 $(eval $(call check-header-rule,INITDISINFO3,init_disassemble_info(NULL,NULL,NULL),disasm))
 $(eval $(call check-header-rule,INITDISINFO4,init_disassemble_info(NULL,NULL,NULL,NULL),disasm))
+$(eval $(call check-header-macro-rule,VALGRIND,VALGRIND_NON_SIMD_CALL0,valgrind/valgrind))
 $(eval $(call check-bpfc-option-rule,BPFV3,-mcpu=v3))
 $(eval $(call check-bpfc-option-rule,BPFMASM,-masm=normal))
 
diff --git a/configure b/configure
index 42e496b97a7d..0c9fb309c494 100755
--- a/configure
+++ b/configure
@@ -169,6 +169,7 @@ for option in "$@"; do
         HAVE_FUSE_NUMA=*) write_config_var FUSE_NUMA "$option";;
         HAVE_CLOSE_RANGE=*) write_config_var CLOSE_RANGE "$option";;
         HAVE_GETTID=*) write_config_var GETTID "$option";;
+        HAVE_VALGRIND=*) write_config_var VALGRIND "$option";;
         HAVE_BPFV3=*) write_config_var BPFV3 "$option";;
         HAVE_BPFMASM=*) write_config_var BPFMASM "$option";;
 	*) echo "Unknown option $option" >&2
diff --git a/libdtrace/dt_work.c b/libdtrace/dt_work.c
index 11335345a6d7..c6de15414481 100644
--- a/libdtrace/dt_work.c
+++ b/libdtrace/dt_work.c
@@ -13,7 +13,9 @@
 #include <port.h>
 #include <linux/perf_event.h>
 #include <sys/epoll.h>
+#ifdef HAVE_VALGRIND
 #include <valgrind/valgrind.h>
+#endif
 #include <dt_impl.h>
 #include <dt_aggregate.h>
 #include <dt_peb.h>
@@ -187,9 +189,11 @@ beginend_child(void *arg) {
 	read(args->tochild[0], &cmd, sizeof(cmd));
 	if (cmd != CMD_BEGIN)
 		exit(1);
-	if (RUNNING_ON_VALGRIND)
+#ifdef HAVE_VALGRIND
+        if (RUNNING_ON_VALGRIND)
 		VALGRIND_NON_SIMD_CALL0(BEGIN_probe);
 	else
+#endif
 		BEGIN_probe();
 	cmd++;
 	write(args->frchild[1], &cmd, sizeof(cmd));
@@ -198,9 +202,11 @@ beginend_child(void *arg) {
 	read(args->tochild[0], &cmd, sizeof(cmd));
 	if (cmd != CMD_END)
 		exit(1);
+#ifdef HAVE_VALGRIND
 	if (RUNNING_ON_VALGRIND)
 		VALGRIND_NON_SIMD_CALL0(END_probe);
 	else
+#endif
 		END_probe();
 	cmd++;
 	write(args->frchild[1], &cmd, sizeof(cmd));
@@ -300,9 +306,12 @@ dtrace_go(dtrace_hdl_t *dtp, uint_t cflags)
 		}
 		if (cmd != CMD_BEGIN + 1)
 			return -1;
-	} else if (RUNNING_ON_VALGRIND)
+	}
+#ifdef HAVE_VALGRIND
+	else if (RUNNING_ON_VALGRIND)
 		VALGRIND_NON_SIMD_CALL0(BEGIN_probe);
 	else
+#endif
 		BEGIN_probe();
 
 	dtp->dt_active = 1;
@@ -344,9 +353,12 @@ dtrace_stop(dtrace_hdl_t *dtp)
 			return -1;
 		pthread_join(args->thr, NULL);
 		dt_free(dtp, args);
-	} else if (RUNNING_ON_VALGRIND)
+	}
+#ifdef HAVE_VALGRIND
+	else if (RUNNING_ON_VALGRIND)
 		VALGRIND_NON_SIMD_CALL0(END_probe);
 	else
+#endif
 		END_probe();
 
 	dtp->dt_stopped = 1;
-- 
2.46.0.278.g36e3a12567


  parent reply	other threads:[~2024-10-24 11:38 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-24 11:37 [PATCH 00/14] gentoo, manpage, and assorted other small fixes Nick Alcock
2024-10-24 11:37 ` [PATCH 01/14] No longer depend on libsystemd Nick Alcock
2024-10-25  2:21   ` Kris Van Hees
2024-10-28 16:14     ` Nick Alcock
2024-10-24 11:37 ` [PATCH 02/14] pkgconfig: drop spaces in variable decls Nick Alcock
2024-10-25  2:22   ` Kris Van Hees
2024-10-28 16:16     ` Nick Alcock
2024-10-24 11:37 ` Nick Alcock [this message]
2024-10-25  2:30   ` [PATCH 03/14] configure, build: make valgrind optional Kris Van Hees
2024-10-28 16:38     ` Nick Alcock
2024-10-24 11:37 ` [PATCH 04/14] build: substitute LIBDIR in pkg-config files Nick Alcock
2024-10-25  2:32   ` Kris Van Hees
2024-10-24 11:37 ` [PATCH 05/14] probe: get the size of the hash-lookup key right Nick Alcock
2024-10-25  2:40   ` Kris Van Hees
2024-10-28 17:14     ` Nick Alcock
2024-10-24 11:37 ` [PATCH 06/14] configure: fix dreadful behaviour of MANDIR / --mandir Nick Alcock
2024-10-25  2:41   ` Kris Van Hees
2024-10-24 11:37 ` [PATCH 07/14] man: the synopsis is ended with .YS, not .SY Nick Alcock
2024-10-25  2:49   ` Kris Van Hees
2024-10-24 11:37 ` [PATCH 08/14] man: use \- for option dashes, not - Nick Alcock
2024-10-25  2:49   ` Kris Van Hees
2024-10-24 11:37 ` [PATCH 09/14] man: drop blank lines Nick Alcock
2024-10-25  2:50   ` Kris Van Hees
2024-10-24 11:37 ` [PATCH 10/14] man: fix blank line in environment variables list Nick Alcock
2024-10-25  2:50   ` Kris Van Hees
2024-10-24 11:37 ` [PATCH 11/14] dtprobed: fix parser child timeout Nick Alcock
2024-10-25  2:54   ` Kris Van Hees
2024-10-24 11:37 ` [PATCH 12/14] man: add manpage for dtprobed(8) Nick Alcock
2024-10-25  2:53   ` Kris Van Hees
2024-10-28 17:18     ` Nick Alcock
2024-10-24 11:37 ` [PATCH 13/14] man: drop double-\fB at the start of every option line Nick Alcock
2024-10-25  2:55   ` Kris Van Hees
2024-10-24 11:37 ` [PATCH 14/14] man: \fP-ize Nick Alcock
2024-10-25  2:55   ` Kris Van Hees

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241024113758.182050-4-nick.alcock@oracle.com \
    --to=nick.alcock@oracle.com \
    --cc=dtrace-devel@oss.oracle.com \
    --cc=dtrace@lists.linux.dev \
    --cc=sam@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox