From 3e73216a32a2b01916eb8c555a41579bd69a47aa Mon Sep 17 00:00:00 2001
From: Li Wang
Date: Mon, 27 Nov 2023 14:54:47 +0800
Subject: [PATCH] systemtap_git: fix used uninitialized error
bpf-translate.cxx: error: 'this_column_size' may be used uninitialized in this function [-Werror=maybe-uninitialized]
bpf-translate.cxx: error: 'num' may be used uninitialized in this function [-Werror=maybe-uninitialized]
(From OE-Core rev: 11da43b58e19583a9bc16044309610cfb2e86469)
Signed-off-by: Li Wang
Signed-off-by: Steve Sakoman
---
...x-Prevent-Werror-maybe-uninitialized.patch | 53 +++++++++++++++++++
.../recipes-kernel/systemtap/systemtap_git.bb | 1 +
2 files changed, 54 insertions(+)
create mode 100644 meta/recipes-kernel/systemtap/systemtap/0001-bpf-translate.cxx-Prevent-Werror-maybe-uninitialized.patch
diff --git a/meta/recipes-kernel/systemtap/systemtap/0001-bpf-translate.cxx-Prevent-Werror-maybe-uninitialized.patch b/meta/recipes-kernel/systemtap/systemtap/0001-bpf-translate.cxx-Prevent-Werror-maybe-uninitialized.patch
new file mode 100644
index 0000000000..130eefab5d
--- /dev/null
+++ b/meta/recipes-kernel/systemtap/systemtap/0001-bpf-translate.cxx-Prevent-Werror-maybe-uninitialized.patch
@@ -0,0 +1,53 @@
+From df3425f51a512f65522522daf1f78c7fab0a63fd Mon Sep 17 00:00:00 2001
+From: Aaron Merey
+Date: Fri, 25 Feb 2022 19:18:29 -0500
+Subject: [PATCH] bpf-translate.cxx: Prevent -Werror=maybe-uninitialized
+
+Two variables in bpf-translate.cxx can trigger -Werror=maybe-uninitialized.
+The code is designed so that uninitialized uses are not actually possible,
+but to convince gcc of this we move a throw statement and initialize one
+of the variables with a value.
+
+Upstream-Status: Backport [https://sourceware.org/git/?p=systemtap.git;a=commit;h=df3425f51a512f65522522daf1f78c7fab0a63fd]
+
+Signed-off-by: Li Wang
+---
+ bpf-translate.cxx | 8 +++++---
+ 1 file changed, 5 insertions(+), 3 deletions(-)
+
+diff --git a/bpf-translate.cxx b/bpf-translate.cxx
+index 3f45c721f..1b63d6078 100644
+--- a/bpf-translate.cxx
++++ b/bpf-translate.cxx
+@@ -1203,7 +1203,7 @@ bpf_unparser::emit_asm_arg (const asm_stmt &stmt, const std::string &arg,
+ {
+ /* arg is a register number */
+ std::string reg = arg[0] == 'r' ? arg.substr(1) : arg;
+- unsigned long num;
++ unsigned long num = ULONG_MAX;
+ bool parsed = false;
+ try {
+ num = stoul(reg, 0, 0);
+@@ -1941,8 +1941,6 @@ bpf_unparser::visit_foreach_loop(foreach_loop* s)
+ for (unsigned k = 0; k < arraydecl->index_types.size(); k++)
+ {
+ auto type = arraydecl->index_types[k];
+- if (type != pe_long && type != pe_string)
+- throw SEMANTIC_ERROR(_("unhandled foreach index type"), s->tok);
+ int this_column_size;
+ // PR23875: foreach should handle string keys
+ if (type == pe_long)
+@@ -1953,6 +1951,10 @@ bpf_unparser::visit_foreach_loop(foreach_loop* s)
+ {
+ this_column_size = BPF_MAXSTRINGLEN;
+ }
++ else
++ {
++ throw SEMANTIC_ERROR(_("unhandled foreach index type"), s->tok);
++ }
+ if (info.sort_column == k + 1) // record sort column
+ {
+ info.sort_column_size = this_column_size;
+--
+2.25.1
+
diff --git a/meta/recipes-kernel/systemtap/systemtap_git.bb b/meta/recipes-kernel/systemtap/systemtap_git.bb
index ce86d5274d..c84fc27001 100644
--- a/meta/recipes-kernel/systemtap/systemtap_git.bb
+++ b/meta/recipes-kernel/systemtap/systemtap_git.bb
@@ -9,6 +9,7 @@ require systemtap_git.inc
SRC_URI += "file://0001-improve-reproducibility-for-c-compiling.patch \
file://0001-staprun-address-ncurses-6.3-failures.patch \
file://0001-gcc12-c-compatibility-re-tweak-for-rhel6-use-functio.patch \
+ file://0001-bpf-translate.cxx-Prevent-Werror-maybe-uninitialized.patch \
"
DEPENDS = "elfutils"