This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
[PATCH] Pass -Wno-tautological-compare when building kernel modules and dyninst DSO
- From: "Yichun Zhang (agentzh)" <agentzh at gmail dot com>
- To: systemtap at sourceware dot org
- Cc: "Yichun Zhang (agentzh)" <agentzh at gmail dot com>
- Date: Thu, 23 Aug 2018 16:39:40 -0700
- Subject: [PATCH] Pass -Wno-tautological-compare when building kernel modules and dyninst DSO
- References: <20180804084025.87239-1-agentzh@gmail.com>
Currently we always turn on -Wall and -Werror when compiling the kernel
module and the dyninst DSO. This causes compile-time errors when the user
input stap scripts contain inefficiencies like `a == a` or `a != a`, which
can be common for automatically generated stap code from naive tools.
---
buildrun.cxx | 5 +-
testsuite/systemtap.base/tautological_cmp.exp | 78 +++++++++++++++++++++++++++
2 files changed, 81 insertions(+), 2 deletions(-)
create mode 100644 testsuite/systemtap.base/tautological_cmp.exp
diff --git a/buildrun.cxx b/buildrun.cxx
index 0e94ebcbd..79b355123 100644
--- a/buildrun.cxx
+++ b/buildrun.cxx
@@ -222,7 +222,7 @@ compile_dyninst (systemtap_session& s)
"gcc", "--std=gnu99", s.translated_source, "-o", module,
"-fvisibility=hidden", "-O2", "-I" + s.runtime_path, "-D__DYNINST__",
"-Wall", WERROR, "-Wno-unused", "-Wno-strict-aliasing",
- "-pthread", "-lrt", "-fPIC", "-shared",
+ "-Wno-tautological-compare", "-pthread", "-lrt", "-fPIC", "-shared",
};
// BZ855981/948279. Since dyninst/runtime.h includes __sync_* calls,
@@ -507,7 +507,8 @@ compile_pass (systemtap_session& s)
o << "EXTRA_CFLAGS += $(call cc-option,-fno-ipa-icf)" << endl;
// Assumes linux 2.6 kbuild
- o << "EXTRA_CFLAGS += -Wno-unused " << WERROR << endl;
+ o << "EXTRA_CFLAGS += -Wno-unused -Wno-tautological-compare " << WERROR
+ << endl;
#if CHECK_POINTER_ARITH_PR5947
o << "EXTRA_CFLAGS += -Wpointer-arith" << endl;
#endif
diff --git a/testsuite/systemtap.base/tautological_cmp.exp b/testsuite/systemtap.base/tautological_cmp.exp
new file mode 100644
index 000000000..a1bbd8b1f
--- /dev/null
+++ b/testsuite/systemtap.base/tautological_cmp.exp
@@ -0,0 +1,78 @@
+set test "tautological_cmp"
+set testpath "$srcdir/$subdir"
+
+if {! [installtest_p]} { untested "$test"; return }
+
+# --- TEST 1 ---
+
+set subtest1 "TEST 1: q == q"
+foreach runtime [get_runtime_list] {
+ if {$runtime eq ""} { set runtime "kernel" }
+ set test_name "$subtest1 ($runtime)"
+
+ set cmd "stap -e 'probe begin \{ a = 32; println (a == a); exit() \}' --runtime=$runtime"
+ send_log "executing: $cmd\n"
+ set pipe [open "| sh -c {$cmd}" r]
+ set out [read $pipe]
+ set is_err 0
+ if {[catch {close $pipe} stderr] != 0} { set is_err 1 }
+
+ set exp_out "1\n"
+ regsub -all -- {\n} $exp_out {\n} escaped_exp_out
+ if {$out eq $exp_out} {
+ pass "${test_name}: stdout matches \"$escaped_exp_out\""
+ } else {
+ fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
+ }
+
+ if {$is_err} {
+ fail "${test_name}: exit code not zero"
+ } else {
+ pass "${test_name}: exit code is zero"
+ }
+
+ set no_stderr_pat "-W(?:error=)?tautological-compare\\y"
+ regsub -all -- {\n} $no_stderr_pat {\n} escaped_no_stderr_pat
+ if {[regexp -linestop -- $no_stderr_pat $stderr]} {
+ fail "${test_name}: stderr should NOT match \"$escaped_no_stderr_pat\" but got \"$stderr\""
+ } else {
+ pass "${test_name}: stderr should NOT matches \"$escaped_no_stderr_pat\""
+ }
+}
+
+# --- TEST 2 ---
+
+set subtest2 "TEST 2: q != q"
+foreach runtime [get_runtime_list] {
+ if {$runtime eq ""} { set runtime "kernel" }
+ set test_name "$subtest2 ($runtime)"
+
+ set cmd "stap -e 'probe begin \{ a = 32; println (a != a); exit() \}' --runtime=$runtime"
+ send_log "executing: $cmd\n"
+ set pipe [open "| sh -c {$cmd}" r]
+ set out [read $pipe]
+ set is_err 0
+ if {[catch {close $pipe} stderr] != 0} { set is_err 1 }
+
+ set exp_out "0\n"
+ regsub -all -- {\n} $exp_out {\n} escaped_exp_out
+ if {$out eq $exp_out} {
+ pass "${test_name}: stdout matches \"$escaped_exp_out\""
+ } else {
+ fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
+ }
+
+ if {$is_err} {
+ fail "${test_name}: exit code not zero"
+ } else {
+ pass "${test_name}: exit code is zero"
+ }
+
+ set no_stderr_pat "-W(?:error=)?tautological-compare\\y"
+ regsub -all -- {\n} $no_stderr_pat {\n} escaped_no_stderr_pat
+ if {[regexp -linestop -- $no_stderr_pat $stderr]} {
+ fail "${test_name}: stderr should NOT match \"$escaped_no_stderr_pat\" but got \"$stderr\""
+ } else {
+ pass "${test_name}: stderr should NOT matches \"$escaped_no_stderr_pat\""
+ }
+}
--
2.11.0.295.gd7dffce