首页 > 解决方案 > Systemtap (stap) 探测失败并显示“此语句可能会通过 [-Werror=implicit-fallthrough=]”

问题描述

从 5.2 到 5.3.5 的内核更新后,我的 SystemTAP(stap)探测失败,并出现以下错误

/usr/share/systemtap/runtime/map-gen.c: In function ‘hash_si’:
/usr/share/systemtap/runtime/map-gen.c:114:28: error: this statement may fall through [-Werror=implicit-fallthrough=]
  114 |                 case 3: k1 ^= tail[2] << 16; \
      |                         ~~~^~~~~~~~~~~~~~~~
/usr/share/systemtap/runtime/map-gen.c:131:19: note: in expansion of macro ‘MURMUR_STRING’
  131 | #define KEY1_HASH MURMUR_STRING(key1)
      |                   ^~~~~~~~~~~~~
/usr/share/systemtap/runtime/map-gen.c:664:9: note: in expansion of macro ‘KEY1_HASH’
  664 |         KEY1_HASH;
      |         ^~~~~~~~~
/usr/share/systemtap/runtime/map-gen.c:115:17: note: here
  115 |                 case 2: k1 ^= tail[1] << 8; \
      |                 ^~~~

为什么?

标签: systemtap

解决方案


目前尚不清楚为什么会在内核更新后发生这种情况,因为它似乎更常见的是 gcc/工具链更改。它看起来与先前的问题相关/相似:

在任何情况下,都可以通过对 systemtap 运行时代码的小修改来在本地解决它以禁用警告。在文件中:

  • /usr/share/systemtap/runtime/vsprintf.c
  • /usr/share/systemtap/runtime/map-gen.c

在每个文件的开头插入以下两行

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"

和文件末尾的这一行:

#pragma GCC diagnostic pop

编辑:为 systemtap发布错误https://sourceware.org/bugzilla/show_bug.cgi?id=25267

编辑:如果您不介意重新编译 systemtap,一个更干净的修复方法是修改runtime.cxx如下:

diff --git a/buildrun.cxx b/buildrun.cxx
index 505902bc5..b29eeb797 100644
--- a/buildrun.cxx
+++ b/buildrun.cxx
@@ -235,6 +235,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",
+      "-Wno-error=implicit-fallthrough", "-Wno-error=strict-prototypes",
       "-pthread", "-lrt", "-fPIC", "-shared",
     };

然后重新编译并重新安装。这可以解决这两个 systemtap 错误:


推荐阅读