Skip to content

Commit

Permalink
dt_pid: fix building with upstream binutils
Browse files Browse the repository at this point in the history
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@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
nickalcock authored and kvanhees committed Feb 22, 2024
1 parent ee75f90 commit de8ebd9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Makeconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down Expand Up @@ -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; \
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -225,10 +225,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))
$(eval $(call check-bpfc-option-rule,BPFV3,-mcpu=v3))

help-overrides::
Expand Down
26 changes: 26 additions & 0 deletions include/disasm.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion libdtrace/dt_pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit de8ebd9

Please sign in to comment.