[DTrace-devel] [PATCH] Address various compiler warnings

Kris Van Hees kris.van.hees at oracle.com
Mon Sep 14 12:51:52 PDT 2020


The compilation reported many compiler warnings, often due to our
"#ifdef FIXME" or other (sometimes temporarily) orphaned code.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 bpf/get_bvar.c                    |  7 ++++++-
 include/dtrace/fasttrap.h         |  1 -
 include/dtrace/fasttrap_defines.h | 22 ----------------------
 libdtrace/Build                   |  3 ++-
 libdtrace/dt_cc.c                 | 14 +++-----------
 libdtrace/dt_cg.c                 | 15 +++++++++++----
 libdtrace/dt_consume.c            | 30 +++++++++++++++++-------------
 libdtrace/dt_dof.c                | 10 ++++++++++
 libdtrace/dt_list.h               |  2 +-
 libdtrace/dt_options.c            |  2 ++
 libdtrace/dt_subr.c               |  2 --
 libdtrace/dt_work.c               | 10 ++++------
 libproc/Build                     |  2 ++
 13 files changed, 58 insertions(+), 62 deletions(-)
 delete mode 100644 include/dtrace/fasttrap_defines.h

diff --git a/bpf/get_bvar.c b/bpf/get_bvar.c
index 9f091080..0cac46d5 100644
--- a/bpf/get_bvar.c
+++ b/bpf/get_bvar.c
@@ -3,6 +3,7 @@
  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
  */
 #include <linux/bpf.h>
+#include <stddef.h>
 #include <stdint.h>
 #include <bpf-helpers.h>
 #include <dtrace/conf.h>
@@ -58,8 +59,12 @@ noinline uint64_t dt_get_bvar(dt_mstate_t *mst, uint32_t id)
 	}
 	case DIF_VAR_CURCPU: {
 		uint32_t	key = 0;
+		void		*val = bpf_map_lookup_elem(&cpuinfo, &key);
 
-		return bpf_map_lookup_elem(&cpuinfo, &key);
+		if (val == NULL)
+			return (uint64_t)NULL;	/* FIXME */
+
+		return (uint64_t)val;
 	}
 	default:
 		/* Not implemented yet. */
diff --git a/include/dtrace/fasttrap.h b/include/dtrace/fasttrap.h
index 82877991..6654889a 100644
--- a/include/dtrace/fasttrap.h
+++ b/include/dtrace/fasttrap.h
@@ -14,7 +14,6 @@
 #define _DTRACE_FASTTRAP_H
 
 #include <dtrace/universal.h>
-#include <dtrace/fasttrap_defines.h>
 
 typedef enum fasttrap_probe_type {
 	DTFTP_NONE = 0,
diff --git a/include/dtrace/fasttrap_defines.h b/include/dtrace/fasttrap_defines.h
deleted file mode 100644
index a0d5e5fa..00000000
--- a/include/dtrace/fasttrap_defines.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed under the Universal Permissive License v 1.0 as shown at
- * http://oss.oracle.com/licenses/upl.
- *
- * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
- */
-
-/*
- * Note: The contents of this file are private to the implementation of the
- * DTrace subsystem and are subject to change at any time without notice.
- */
-
-#ifndef _DTRACE_FASTTRAP_DEFINES_H
-#define _DTRACE_FASTTRAP_DEFINES_H
-
-#include <dtrace/universal.h>
-
-enum fasttrap_probe_type;
-struct fasttrap_probe_spec;
-struct fasttrap_instr_query;
-
-#endif /* _DTRACE_FASTTRAP_DEFINES_H */
diff --git a/libdtrace/Build b/libdtrace/Build
index e453a84e..cfde8a1c 100644
--- a/libdtrace/Build
+++ b/libdtrace/Build
@@ -41,8 +41,9 @@ libdtrace_VERSCRIPT := libdtrace.ver
 libdtrace_LIBSOURCES := libdtrace-build libproc libport
 libdtrace_SECONDARY := libproc libport libbpf
 
-# Disable C99 variadic macro warnings for this file
+# Disable certain warnings for these files
 dt_consume.c_CFLAGS := -Wno-pedantic
+dt_debug.c_CFLAGS := -Wno-prio-ctor-dtor
 dt_dis.c_CFLAGS := -Wno-pedantic
 dt_proc.c_CFLAGS := -Wno-pedantic
 
diff --git a/libdtrace/dt_cc.c b/libdtrace/dt_cc.c
index 34245649..de554cf1 100644
--- a/libdtrace/dt_cc.c
+++ b/libdtrace/dt_cc.c
@@ -95,16 +95,6 @@
 
 extern int yylineno;
 
-#ifdef FIXME
-static const dtrace_diftype_t dt_void_rtype = {
-	DIF_TYPE_CTF, CTF_K_INTEGER, 0, 0, 0
-};
-#endif
-
-static const dtrace_diftype_t dt_int_rtype = {
-	DIF_TYPE_CTF, CTF_K_INTEGER, 0, 0, sizeof (uint64_t)
-};
-
 /*ARGSUSED*/
 static int
 dt_idreset(dt_idhash_t *dhp, dt_ident_t *idp, void *ignored)
@@ -142,6 +132,7 @@ dt_stmt_create(dtrace_hdl_t *dtp, dtrace_ecbdesc_t *edp,
 	return (sdp);
 }
 
+#ifdef FIXME
 /*
  * Utility function to determine if a given action description is destructive.
  * The dtdo_destructive bit is set for us by the DIF assembler (see dt_as.c).
@@ -152,17 +143,18 @@ dt_action_destructive(const dtrace_actdesc_t *ap)
 	return (DTRACEACT_ISDESTRUCTIVE(ap->dtad_kind) || (ap->dtad_kind ==
 	    DTRACEACT_DIFEXPR && ap->dtad_difo->dtdo_destructive));
 }
+#endif
 
 static void
 dt_stmt_append(dtrace_stmtdesc_t *sdp, const dt_node_t *dnp)
 {
+#ifdef FIXME
 	dtrace_ecbdesc_t *edp = sdp->dtsd_ecbdesc;
 	dtrace_actdesc_t *ap, *tap;
 	int commit = 0;
 	int speculate = 0;
 	int datarec = 0;
 
-#ifdef FIXME
 	/*
 	 * Make sure that the new statement jibes with the rest of the ECB.
 	 */
diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 63b14f06..13ae7e2a 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -913,7 +913,9 @@ static void
 dt_cg_act_stack(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind)
 {
 	dt_node_t *arg = dnp->dn_args;
+#ifdef FIXME
 	uint32_t nframes = 0;
+#endif
 
 	if (arg != NULL) {
 		if (!dt_node_is_posconst(arg)) {
@@ -921,7 +923,9 @@ dt_cg_act_stack(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind)
 				"be a non-zero positive integer constant\n");
 		}
 
+#ifdef FIXME
 		nframes = (uint32_t)arg->dn_value;
+#endif
 	}
 }
 
@@ -982,8 +986,10 @@ dt_cg_act_ustack(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind)
 {
 	dt_node_t *arg0 = dnp->dn_args;
 	dt_node_t *arg1 = arg0 != NULL ? arg0->dn_list : NULL;
+#ifdef FIXME
 	uint32_t nframes = 0;
 	uint32_t strsize = 0;
+#endif
 
 	if (arg0 != NULL) {
 		if (!dt_node_is_posconst(arg0)) {
@@ -992,7 +998,9 @@ dt_cg_act_ustack(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind)
 				"constant\n");
 		}
 
+#ifdef FIXME
 		nframes = (uint32_t)arg0->dn_value;
+#endif
 	}
 
 	if (arg1 != NULL) {
@@ -1003,7 +1011,9 @@ dt_cg_act_ustack(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind)
 				"must be a positive integer constant\n");
 		}
 
+#ifdef FIXME
 		strsize = (uint32_t)arg1->dn_value;
+#endif
 	}
 }
 
@@ -2147,7 +2157,6 @@ dt_cg_logical_neg(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
 static void
 dt_cg_asgn_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
 {
-	struct bpf_insn instr;
 	dt_ident_t *idp;
 
 	/*
@@ -2161,6 +2170,7 @@ dt_cg_asgn_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
 		ctf_membinfo_t ctm;
 		dt_xlator_t *dxp = idp->di_data;
 		dt_node_t *mnp, dn, mn;
+		struct bpf_insn instr;
 		int r1, r2;
 
 		/*
@@ -3096,7 +3106,6 @@ if ((idp = dnp->dn_ident)->di_kind != DT_IDENT_FUNC)
 void
 dt_cg(dt_pcb_t *pcb, dt_node_t *dnp)
 {
-	struct bpf_insn	instr;
 	dt_xlator_t	*dxp = NULL;
 	dt_node_t	*act;
 
@@ -3135,8 +3144,6 @@ dt_cg(dt_pcb_t *pcb, dt_node_t *dnp)
 		dxp->dx_ident->di_id = dt_regset_alloc(pcb->pcb_regs);
 		dt_cg_node(dnp, &pcb->pcb_ir, pcb->pcb_regs);
 	} else if (dnp->dn_kind == DT_NODE_CLAUSE) {
-		dt_irlist_t	*dlp = &pcb->pcb_ir;
-
 		dt_cg_prologue(pcb, dnp->dn_pred);
 
 		for (act = dnp->dn_acts; act != NULL; act = act->dn_list) {
diff --git a/libdtrace/dt_consume.c b/libdtrace/dt_consume.c
index 07ee454b..a2dffc5c 100644
--- a/libdtrace/dt_consume.c
+++ b/libdtrace/dt_consume.c
@@ -367,7 +367,7 @@ dt_flowindent(dtrace_hdl_t *dtp, dtrace_probedata_t *data, dtrace_epid_t last,
 	      dtrace_epid_t next)
 {
 	dtrace_probedesc_t	*pd = data->dtpda_pdesc, *npd;
-	dtrace_datadesc_t	*dd = data->dtpda_ddesc, *ndd;
+	dtrace_datadesc_t	*ndd;
 	dtrace_flowkind_t	flow = DTRACEFLOW_NONE;
 	const char		*p = pd->prv;
 	const char		*n = pd->prb;
@@ -431,7 +431,6 @@ dt_flowindent(dtrace_hdl_t *dtp, dtrace_probedata_t *data, dtrace_epid_t last,
 			flow = DTRACEFLOW_NONE;
 	}
 
-out:
 	if (flow == DTRACEFLOW_ENTRY || flow == DTRACEFLOW_RETURN)
 		data->dtpda_prefix = str;
 	else
@@ -969,6 +968,7 @@ dt_print_bytes(dtrace_hdl_t *dtp, FILE *fp, caddr_t addr,
         return (dt_print_rawbytes(dtp, fp, addr, nbytes));
 }
 
+#ifdef FIXME
 static int
 dt_print_tracemem(dtrace_hdl_t *dtp, FILE *fp, const dtrace_recdesc_t *rec,
     uint_t nrecs, const caddr_t buf)
@@ -1016,6 +1016,7 @@ dt_print_tracemem(dtrace_hdl_t *dtp, FILE *fp, const dtrace_recdesc_t *rec,
 
 	return (nconsumed);
 }
+#endif
 
 int
 dt_print_stack(dtrace_hdl_t *dtp, FILE *fp, const char *format,
@@ -1419,6 +1420,7 @@ dt_print_pcap(dtrace_hdl_t *dtp, FILE *fp, dtrace_recdesc_t *rec,
 	return (0);
 }
 
+#ifdef FIXME
 typedef struct dt_normal {
 	dtrace_aggvarid_t dtnd_id;
 	uint64_t dtnd_normal;
@@ -1612,6 +1614,7 @@ dt_trunc(dtrace_hdl_t *dtp, caddr_t base, dtrace_recdesc_t *rec)
 
 	return (0);
 }
+#endif
 
 static int
 dt_print_datum(dtrace_hdl_t *dtp, FILE *fp, dtrace_recdesc_t *rec,
@@ -1901,10 +1904,10 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,
 	data += sizeof(struct perf_event_header);
 
 	if (hdr->type == PERF_RECORD_SAMPLE) {
-		char			*ptr = data;
-		uint32_t		size, epid, tag;
-		int			i;
-		int			done = 0;
+		char		*ptr = data;
+		dtrace_epid_t	epid;
+		uint32_t	size;
+		int		i;
 
 		/*
 		 * struct {
@@ -1931,7 +1934,9 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,
 		size -= sizeof(uint32_t);
 
 		epid = ((uint32_t *)data)[0];
-		tag = ((uint32_t *)data)[1];
+#ifdef FIXME
+		tag = ((uint32_t *)data)[1];		/* for future use */
+#endif
 
 		/*
 		 * Fill in the epid and address of the epid in the buffer.  We
@@ -1980,9 +1985,6 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,
 			    const void *buf, size_t);
 
 			rec = &pdat->dtpda_ddesc->dtdd_recs[i];
-			if (rec->dtrd_action == DTRACEACT_EXIT)
-				done = 1;
-
 			pdat->dtpda_data = data + rec->dtrd_offset;
 			rval = (*rfunc)(pdat, rec, arg);
 
@@ -1999,11 +2001,11 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,
 			case DTRACEACT_PRINTF:
 				func = dtrace_fprintf;
 				break;
-/*
+#ifdef FIXME
 			case DTRACEACT_PRINTA:
 				func = dtrace_fprinta;
 				break;
-*/
+#endif
 			case DTRACEACT_SYSTEM:
 				func = dtrace_system;
 				break;
@@ -2046,6 +2048,7 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,
 
 		return DTRACE_WORKSTATUS_OKAY;
 	} else if (hdr->type == PERF_RECORD_LOST) {
+#ifdef FIXME
 		uint64_t	lost;
 
 		/*
@@ -2057,6 +2060,7 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,
 		 * and data points to the 'id' member at this point.
 		 */
 		lost = *(uint64_t *)(data + sizeof(uint64_t));
+#endif
 
 		/* FIXME: To be implemented */
 		return DTRACE_WORKSTATUS_ERROR;
@@ -2233,7 +2237,7 @@ dt_consume_begin_error(const dtrace_errdata_t *data, void *arg)
  * that we only process ERROR enablings _not_ induced by BEGIN enablings in the
  * second pass.
  */
-static int
+static dtrace_workstatus_t
 dt_consume_begin(dtrace_hdl_t *dtp, FILE *fp, struct epoll_event *events,
 		 int cnt, dtrace_consume_probe_f *pf, dtrace_consume_rec_f *rf,
 		 void *arg)
diff --git a/libdtrace/dt_dof.c b/libdtrace/dt_dof.c
index 090d6736..0b8ad9de 100644
--- a/libdtrace/dt_dof.c
+++ b/libdtrace/dt_dof.c
@@ -555,11 +555,15 @@ dtrace_dof_create(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, uint_t flags)
 
 	const dtrace_ecbdesc_t *edp, *last;
 	const dtrace_probedesc_t *pdp;
+#ifdef FIXME
 	const dtrace_actdesc_t *ap;
+#endif
 	const dt_stmt_t *stp;
 
 	uint_t maxacts = 0;
+#ifdef FIXME
 	uint_t maxfmt = 0;
+#endif
 
 	dt_provider_t *pvp;
 	dt_xlator_t *dxp;
@@ -569,7 +573,9 @@ dtrace_dof_create(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, uint_t flags)
 	dof_hdr_t h;
 
 	dt_buf_t dof;
+#ifdef FIXME
 	char *fmt;
+#endif
 	uint_t i;
 
 	if (flags & ~DTRACE_D_MASK) {
@@ -614,7 +620,9 @@ dtrace_dof_create(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, uint_t flags)
 #endif
 
 	dofa = alloca(sizeof (dof_actdesc_t) * maxacts);
+#ifdef FIXME
 	fmt = alloca(maxfmt + 1);
+#endif
 
 	ddo->ddo_strsec = dof_add_lsect(ddo, NULL, DOF_SECT_STRTAB, 1, 0, 0, 0);
 	(void) dof_add_string(ddo, "");
@@ -642,9 +650,11 @@ dtrace_dof_create(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, uint_t flags)
 		dof_secidx_t probesec = DOF_SECIDX_NONE;
 		dof_secidx_t actsec = DOF_SECIDX_NONE;
 
+#ifdef FIXME
 		const dt_stmt_t *next = stp;
 		dtrace_stmtdesc_t *sdp = stp->ds_desc;
 		dof_stridx_t strndx = 0;
+#endif
 		dof_probedesc_t dofp;
 		dof_ecbdesc_t dofe;
 		uint_t i;
diff --git a/libdtrace/dt_list.h b/libdtrace/dt_list.h
index cac83819..49b290f5 100644
--- a/libdtrace/dt_list.h
+++ b/libdtrace/dt_list.h
@@ -20,7 +20,7 @@ typedef struct dt_list {
 #define	dt_list_prev(elem)	((void *)(((dt_list_t *)(elem))->dl_prev))
 #define	dt_list_next(elem)	((void *)(((dt_list_t *)(elem))->dl_next))
 
-#define dt_in_list(l, e)	((l)->dl_next == (e) || dt_list_prev(e))
+#define dt_in_list(l, e)	(dt_list_next(l) == (e) || dt_list_prev(e))
 
 extern void dt_list_append(dt_list_t *, void *);
 extern void dt_list_prepend(dt_list_t *, void *);
diff --git a/libdtrace/dt_options.c b/libdtrace/dt_options.c
index 74a1e8fc..53c9507a 100644
--- a/libdtrace/dt_options.c
+++ b/libdtrace/dt_options.c
@@ -944,6 +944,7 @@ dt_opt_bufresize(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
 int
 dt_options_load(dtrace_hdl_t *dtp)
 {
+#ifdef FIXME
 	dof_hdr_t hdr, *dof;
 	dof_sec_t *sec = NULL;  /* gcc -Wmaybe-uninitialized */
 	size_t offs;
@@ -996,6 +997,7 @@ dt_options_load(dtrace_hdl_t *dtp)
 
 		dtp->dt_options[opt->dofo_option] = opt->dofo_value;
 	}
+#endif
 
 	return (0);
 }
diff --git a/libdtrace/dt_subr.c b/libdtrace/dt_subr.c
index 4f180292..a4bed523 100644
--- a/libdtrace/dt_subr.c
+++ b/libdtrace/dt_subr.c
@@ -694,8 +694,6 @@ dt_zalloc(dtrace_hdl_t *dtp, size_t size)
 void *
 dt_calloc(dtrace_hdl_t *dtp, size_t cnt, size_t size)
 {
-	void *data;
-
 	if (cnt == 0 || size == 0)
 		return NULL;
 
diff --git a/libdtrace/dt_work.c b/libdtrace/dt_work.c
index 85ca2699..02246219 100644
--- a/libdtrace/dt_work.c
+++ b/libdtrace/dt_work.c
@@ -143,12 +143,11 @@ dtrace_status(dtrace_hdl_t *dtp)
 int
 dtrace_go(dtrace_hdl_t *dtp, uint_t cflags)
 {
-	void		*dof;
 	size_t		size;
 	int		err;
 
 	if (dtp->dt_active)
-		return (dt_set_errno(dtp, EINVAL));
+		return dt_set_errno(dtp, EINVAL);
 
 	/*
 	 * If a dtrace:::ERROR program and callback are registered, enable the
@@ -160,7 +159,7 @@ dtrace_go(dtrace_hdl_t *dtp, uint_t cflags)
 	if (dtp->dt_errprog != NULL &&
 	    dtrace_program_exec(dtp, dtp->dt_errprog, NULL) == -1 && (
 	    dtp->dt_errno != ENOTTY || dtp->dt_vector == NULL))
-		return (-1); /* dt_errno has been set for us */
+		return -1;		/* dt_errno has been set for us */
 
 	/*
 	 * Create the global BPF maps.  This is done only once regardless of
@@ -210,9 +209,9 @@ dtrace_go(dtrace_hdl_t *dtp, uint_t cflags)
 
 #if 0
 	if (dt_options_load(dtp) == -1)
-		return (dt_set_errno(dtp, errno));
+		return dt_set_errno(dtp, errno);
 
-	return (dt_aggregate_go(dtp));
+	return dt_aggregate_go(dtp);
 #else
 	return 0;
 #endif
@@ -305,7 +304,6 @@ dtrace_workstatus_t
 dtrace_work(dtrace_hdl_t *dtp, FILE *fp, dtrace_consume_probe_f *pfunc,
 	    dtrace_consume_rec_f *rfunc, void *arg)
 {
-	int			status = dtrace_status(dtp);
 	dtrace_workstatus_t	rval;
 
 	switch (dtrace_status(dtp)) {
diff --git a/libproc/Build b/libproc/Build
index 996194bc..34b93578 100644
--- a/libproc/Build
+++ b/libproc/Build
@@ -10,6 +10,8 @@ libproc_DIR := $(current-dir)
 libproc_SOURCES = Pcontrol.c elfish.c elfish_64.c elfish_32.c Psymtab.c rtld_db.c rtld_offsets.c wrap.c isadep_dispatch.c $(ARCHINC)/isadep.c
 libproc_SRCDEPS := $(objdir)/rtld_offsets.stamp
 
+rtld_offsets.c_CFLAGS := -Wno-prio-ctor-dtor
+
 $(objdir)/rtld_offsets.h $(libproc_DIR)rtld_offsets.c: $(objdir)/rtld_offsets.stamp
 
 $(objdir)/rtld_offsets.stamp: include/sys/glibc_internal_link.h $(libproc_DIR)mkoffsets.sh
-- 
2.28.0




More information about the DTrace-devel mailing list