[DTrace-devel] [PATCH 02/23] dt_pid: fix building with upstream binutils

Nick Alcock nick.alcock at oracle.com
Thu Feb 22 18:38:58 UTC 2024


Upstream libopcodes (really, libbfd) requires the inclusion of BFD's
<config.h> before it will work.  Unfortunately, BFD's <config.h> is
not installed and is in any case absolutely chock-full of things we
do not want contaminating the DTrace build.  This is basically not
necessary on Linux (though it is on many more obscure platforms),
so most Linux distros patch the check out -- but it's still there
upstream, so we should handle it.

So introduce a new <disasm.h> header that wraps <dis-asm.h> and fools it
into believing that we have included BFD's <config.h> even though we
haven't.  To avoid breaking the configury tests, Makeconfig is adjusted to
look in our include/ directory for headers, and to test against our new
<disasm.h>.

Signed-off-by: Nick Alcock <nick.alcock at oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 Makeconfig         | 14 +++++++-------
 include/disasm.h   | 26 ++++++++++++++++++++++++++
 libdtrace/dt_pid.c |  2 +-
 3 files changed, 34 insertions(+), 8 deletions(-)
 create mode 100644 include/disasm.h

diff --git a/Makeconfig b/Makeconfig
index 0f7c4364..a4f77f11 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -60,7 +60,7 @@ $(objdir)/.config/config.$(1).h $(objdir)/.config/config.$(1).mk: $(objdir)/.con
 	val="$(HAVE_$(1))"; \
 	if [[ x$(HAVE_$(1)) = x ]]; then \
 	    if printf '#include <%s.h>\nint main(void) { %s; }' "$(3)" "$(2)" | \
-	       $(CC) $(filter-out --coverage,$(CFLAGS) $(LDFLAGS)) -D_GNU_SOURCE -Werror=implicit-function-declaration -c -o /dev/null -x c - >/dev/null 2>&1; then \
+	       $(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 \
 	       val=yes; \
 	   else \
 	       val=no; \
@@ -103,7 +103,7 @@ $(objdir)/.config/config.$(1).h $(objdir)/.config/config.$(1).mk: $(objdir)/.con
 	val="$(HAVE_$(1))"; \
 	if [[ x$(HAVE_$(1)) = x ]]; then \
 	    if echo 'void $(2)(); int main(void) { $(2)(); }' | \
-	       $(CC) $(filter-out --coverage,$(CFLAGS) $(LDFLAGS)) -o /dev/null -x c - -l$(3) >/dev/null 2>&1; then \
+	       $(CC) $(filter-out --coverage,$(CFLAGS) $(LDFLAGS)) -Iinclude -o /dev/null -x c - -l$(3) >/dev/null 2>&1; then \
 	       val=yes; \
 	   else \
 	       val=no; \
@@ -144,7 +144,7 @@ $(objdir)/.config/config.$(1).h $(objdir)/.config/config.$(1).mk: $(objdir)/.con
 	xno) echo '/* #undef HAVE_$(1) */' > $(objdir)/.config/config.$(1).h; \
 	     echo '# HAVE_$(1) undefined' > $(objdir)/.config/config.$(1).mk;; \
 	*) if printf '#include <%s.h>\nint main(void) { %s; }' "$(4)" "$(2)" | \
-	       $(CC) $(filter-out --coverage,$(CFLAGS) $(LDFLAGS)) -D_GNU_SOURCE -Werror=implicit-function-declaration -o /dev/null -x c - -l$(3) >/dev/null 2>&1; then \
+	       $(CC) $(filter-out --coverage,$(CFLAGS) $(LDFLAGS)) -Iinclude -D_GNU_SOURCE -Werror=implicit-function-declaration -o /dev/null -x c - -l$(3) >/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 \
@@ -192,10 +192,10 @@ endif
 $(eval $(call check-header-rule,FUSE_NUMA,fuse_set_numa,fuse/fuse_lowlevel))
 $(eval $(call check-header-symbol-rule,CLOSE_RANGE,close_range(3,~0U,0),c,unistd))
 $(eval $(call check-header-rule,GETTID,gettid,unistd))
-$(eval $(call check-header-rule,DIS1,disassembler(NULL),dis-asm))
-$(eval $(call check-header-rule,DIS4,disassembler(0,0,0,NULL),dis-asm))
-$(eval $(call check-header-rule,INITDISINFO3,init_disassemble_info(NULL,NULL,NULL),dis-asm))
-$(eval $(call check-header-rule,INITDISINFO4,init_disassemble_info(NULL,NULL,NULL,NULL),dis-asm))
+$(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))
 
 help-overrides::
 	printf "\n" >&2
diff --git a/include/disasm.h b/include/disasm.h
new file mode 100644
index 00000000..63f43135
--- /dev/null
+++ b/include/disasm.h
@@ -0,0 +1,26 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+#ifndef _DISASM_H
+#define _DISASM_H
+
+/*
+ * An interface to BFD dis-asm.h.  This is difficult to #include because
+ * it includes headers that require bfd's config.h to be included first,
+ * which is not an installed file.  It's unnecessary on any platform
+ * DTrace works on, so we fool BFD into thinking it's installed here.
+ */
+
+#define PACKAGE fool-me-once
+#define PACKAGE_VERSION 0.666
+
+#include <dis-asm.h>
+
+#undef PACKAGE
+#undef PACKAGE_VERSION
+
+#endif
diff --git a/libdtrace/dt_pid.c b/libdtrace/dt_pid.c
index 758ab832..a6d58857 100644
--- a/libdtrace/dt_pid.c
+++ b/libdtrace/dt_pid.c
@@ -18,7 +18,7 @@
 #include <sys/ioctl.h>
 #include <sys/sysmacros.h>
 #if defined(__amd64)
-#include <dis-asm.h>
+#include <disasm.h>
 #endif
 
 #include <port.h>
-- 
2.42.0




More information about the DTrace-devel mailing list