Systemtap (stap) 探测失败 "this statement may fall through [-Werror=implicit-fallthrough=]"

Systemtap (stap) probes fail with "this statement may fall through [-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; \
      |                 ^~~~

为什么?

不清楚为什么在内核更新后会发生这种情况,因为它似乎更通常是 gcc/toolchain 更改。它看起来是 related/similar 之前的问题:

在任何情况下,它都可以在本地解决,对 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 错误:

这很可能是由于自 5.3 内核版本以来在内核构建中启用了 -Werror=implicit-fallthru(这也会影响外部模块):https://lwn.net/Articles/794944/ - 换句话说,systemtap 上游需要一些工作以正确支持 5.3。

推测您链接的其他 -Wimplicit-fallthru 修复都是针对 systemtap 的用户空间部分的,这些部分是使用不同的编译器设置编译的(旧内核版本很可能在构建中禁用了 -Wimplicit-fallthru)。