[DTrace-devel] [PATCH 04/12] Fix the -xcpp option
Kris Van Hees
kris.van.hees at oracle.com
Wed Jul 13 19:17:41 UTC 2022
The -xcpp option should be equivalent to the -C option. The -xcpp
option set DTRACE_C_CPP in the dt_cflags, but the compiler only
ever checked the cflags passed from the command line program for
the DTRACE_C_CPP flag. As a result, only -C had the intended
behaviour whereas -xcpp was essentially ignored.
When a non-D library script is compiled and the DTRACE_C_CPP flag is
set in dt_cflags, it is also set in the cflags used by the compiler.
Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
libdtrace/dt_cc.c | 7 +++++
libdtrace/dt_dlibs.c | 8 ++++--
libdtrace/dtrace.h | 3 +-
.../options/err.D_PRAGCTL_INVAL.no-cpp.d | 26 +++++++++++++++++
test/unittest/options/tst.cpp.d | 28 +++++++++++++++++++
5 files changed, 68 insertions(+), 4 deletions(-)
create mode 100644 test/unittest/options/err.D_PRAGCTL_INVAL.no-cpp.d
create mode 100644 test/unittest/options/tst.cpp.d
diff --git a/libdtrace/dt_cc.c b/libdtrace/dt_cc.c
index fba54cb0..1383aec0 100644
--- a/libdtrace/dt_cc.c
+++ b/libdtrace/dt_cc.c
@@ -1930,6 +1930,13 @@ dt_compile(dtrace_hdl_t *dtp, int context, dtrace_probespec_t pspec, void *arg,
dt_idhash_iter(dtp->dt_globals, dt_idreset, NULL);
dt_idhash_iter(dtp->dt_tls, dt_idreset, NULL);
+ /*
+ * If the 'cpp' option was passed, treat it as equivalent to '-C',
+ * unless a D library is being compiled.
+ */
+ if (!(cflags & DTRACE_C_DLIB))
+ cflags |= dtp->dt_cflags & DTRACE_C_CPP;
+
if (fp && (cflags & DTRACE_C_CPP) && (fp = dt_preproc(dtp, fp)) == NULL)
return NULL; /* errno is set for us */
diff --git a/libdtrace/dt_dlibs.c b/libdtrace/dt_dlibs.c
index 89ea062d..48a04dff 100644
--- a/libdtrace/dt_dlibs.c
+++ b/libdtrace/dt_dlibs.c
@@ -1084,8 +1084,8 @@ dt_load_libs_dir(dtrace_hdl_t *dtp, const char *path)
goto err_close;
rv = dt_compile(dtp, DT_CTX_DPROG, DTRACE_PROBESPEC_NAME, NULL,
- DTRACE_C_EMPTY | DTRACE_C_CTL, 0, NULL, fp,
- NULL);
+ DTRACE_C_DLIB | DTRACE_C_EMPTY | DTRACE_C_CTL,
+ 0, NULL, fp, NULL);
if (rv != NULL && dtp->dt_errno &&
(dtp->dt_errno != EDT_COMPILER ||
@@ -1119,7 +1119,9 @@ dt_load_libs_dir(dtrace_hdl_t *dtp, const char *path)
}
dtp->dt_filetag = dld->dtld_library;
- pgp = dtrace_program_fcompile(dtp, fp, DTRACE_C_EMPTY, 0, NULL);
+ pgp = dtrace_program_fcompile(dtp, fp,
+ DTRACE_C_DLIB | DTRACE_C_EMPTY,
+ 0, NULL);
fclose(fp);
dtp->dt_filetag = NULL;
diff --git a/libdtrace/dtrace.h b/libdtrace/dtrace.h
index a05cc4a9..3e55f0af 100644
--- a/libdtrace/dtrace.h
+++ b/libdtrace/dtrace.h
@@ -100,8 +100,9 @@ typedef struct dtrace_proginfo {
#define DTRACE_C_DEFARG 0x0800 /* Use 0/"" as value for unspecified args */
#define DTRACE_C_NOLIBS 0x1000 /* Do not process D system libraries */
#define DTRACE_C_CTL 0x2000 /* Only process control directives */
+#define DTRACE_C_DLIB 0x4000 /* Processing a D library */
#define DTRACE_C_EPROBE 0x8000 /* Compiling default ERROR probe clause */
-#define DTRACE_C_MASK 0xbbff /* mask of all valid flags to dtrace_*compile */
+#define DTRACE_C_MASK 0xfbff /* mask of all valid flags to dtrace_*compile */
extern dtrace_prog_t *dtrace_program_strcompile(dtrace_hdl_t *dtp, const char *s,
dtrace_probespec_t spec, uint_t cflags, int argc, char *const argv[]);
diff --git a/test/unittest/options/err.D_PRAGCTL_INVAL.no-cpp.d b/test/unittest/options/err.D_PRAGCTL_INVAL.no-cpp.d
new file mode 100644
index 00000000..7dd2b516
--- /dev/null
+++ b/test/unittest/options/err.D_PRAGCTL_INVAL.no-cpp.d
@@ -0,0 +1,26 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2022, 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.
+ */
+
+/*
+ *
+ * ASSERTION: With no -xcpp option the input file is not pre-processed.
+ *
+ * SECTION: Options and Tunables/Consumer Options
+ */
+
+BEGIN
+{
+ exit(0);
+}
+
+ERROR
+{
+ exit(1);
+}
+
+#if 0
+#endif
diff --git a/test/unittest/options/tst.cpp.d b/test/unittest/options/tst.cpp.d
new file mode 100644
index 00000000..02015755
--- /dev/null
+++ b/test/unittest/options/tst.cpp.d
@@ -0,0 +1,28 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2022, 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.
+ */
+
+/*
+ *
+ * ASSERTION: The -xcpp option enables pre-processing of the input file.
+ *
+ * SECTION: Options and Tunables/Consumer Options
+ */
+
+/* @@runtest-opts: -xcpp */
+
+BEGIN
+{
+ exit(0);
+}
+
+ERROR
+{
+ exit(1);
+}
+
+#if 0
+#endif
--
2.34.1
More information about the DTrace-devel
mailing list