Blame SOURCES/bcc-0.25.0-Fix-clang-15-int-to-pointer-conversion-errors.patch

818e97
From 9ae3908ae38b3e8d8e36a52c0e5664c453d4c015 Mon Sep 17 00:00:00 2001
818e97
From: Jerome Marchand <jmarchan@redhat.com>
818e97
Date: Wed, 26 Oct 2022 14:41:54 +0200
818e97
Subject: [PATCH 2/2] Fix clang 15 int to pointer conversion errors
818e97
818e97
Since version 15, clang issues error for implicit conversion of
818e97
integer to pointer. Several tools are broken. This patch add explicit
818e97
pointer cast where needed.
818e97
818e97
Fixes the following errors:
818e97
/virtual/main.c:37:18: error: incompatible integer to pointer conversion initializing 'struct request *' with an expression of type 'unsigned long' [-Wint-conversion]
818e97
 struct request *req = ctx->di;
818e97
                 ^     ~~~~~~~
818e97
/virtual/main.c:49:18: error: incompatible integer to pointer conversion initializing 'struct request *' with an expression of type 'unsigned long' [-Wint-conversion]
818e97
 struct request *req = ctx->di;
818e97
                 ^     ~~~~~~~
818e97
2 errors generated.
818e97
818e97
/virtual/main.c:73:19: error: incompatible integer to pointer conversion initializing 'struct pt_regs *' with an expression of type 'unsigned long' [-Wint-conversion]
818e97
 struct pt_regs * __ctx = ctx->di;
818e97
                  ^       ~~~~~~~
818e97
/virtual/main.c:100:240: error: incompatible integer to pointer conversion passing 'u64' (aka 'unsigned long long') to parameter of type 'const void *' [-Wint-conversion]
818e97
    data.ppid = ({ typeof(pid_t) _val; __builtin_memset(&_val, 0, sizeof(_val)); bpf_probe_read(&_val, sizeof(_val), (u64)&({ typeof(struct task_struct *) _val; __builtin_memset(&_val, 0, sizeof(_val)); bpf_probe_read(&_val, sizeof(_val), (u64)&task->real_parent); _val; })->tgid); _val; });
818e97
                                                                                                                                                                                                                                               ^~~~~~~~~~~~~~~~~~~~~~~
818e97
/virtual/main.c:100:118: error: incompatible integer to pointer conversion passing 'u64' (aka 'unsigned long long') to parameter of type 'const void *' [-Wint-conversion]
818e97
    data.ppid = ({ typeof(pid_t) _val; __builtin_memset(&_val, 0, sizeof(_val)); bpf_probe_read(&_val, sizeof(_val), (u64)&({ typeof(struct task_struct *) _val; __builtin_memset(&_val, 0, sizeof(_val)); bpf_probe_read(&_val, sizeof(_val), (u64)&task->real_parent); _val; })->tgid); _val; });
818e97
                                                                                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
818e97
818e97
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
818e97
---
818e97
 src/cc/frontends/clang/b_frontend_action.cc | 18 +++++++++---------
818e97
 1 file changed, 9 insertions(+), 9 deletions(-)
818e97
818e97
diff --git a/src/cc/frontends/clang/b_frontend_action.cc b/src/cc/frontends/clang/b_frontend_action.cc
818e97
index dbeba3e4..c0582464 100644
818e97
--- a/src/cc/frontends/clang/b_frontend_action.cc
818e97
+++ b/src/cc/frontends/clang/b_frontend_action.cc
818e97
@@ -517,9 +517,9 @@ bool ProbeVisitor::VisitUnaryOperator(UnaryOperator *E) {
818e97
   string pre, post;
818e97
   pre = "({ typeof(" + E->getType().getAsString() + ") _val; __builtin_memset(&_val, 0, sizeof(_val));";
818e97
   if (cannot_fall_back_safely)
818e97
-    pre += " bpf_probe_read_kernel(&_val, sizeof(_val), (u64)";
818e97
+    pre += " bpf_probe_read_kernel(&_val, sizeof(_val), (void *)";
818e97
   else
818e97
-    pre += " bpf_probe_read(&_val, sizeof(_val), (u64)";
818e97
+    pre += " bpf_probe_read(&_val, sizeof(_val), (void *)";
818e97
   post = "); _val; })";
818e97
   rewriter_.ReplaceText(expansionLoc(E->getOperatorLoc()), 1, pre);
818e97
   rewriter_.InsertTextAfterToken(expansionLoc(GET_ENDLOC(sub)), post);
818e97
@@ -581,9 +581,9 @@ bool ProbeVisitor::VisitMemberExpr(MemberExpr *E) {
818e97
   string pre, post;
818e97
   pre = "({ typeof(" + E->getType().getAsString() + ") _val; __builtin_memset(&_val, 0, sizeof(_val));";
818e97
   if (cannot_fall_back_safely)
818e97
-    pre += " bpf_probe_read_kernel(&_val, sizeof(_val), (u64)&";
818e97
+    pre += " bpf_probe_read_kernel(&_val, sizeof(_val), (void *)&";
818e97
   else
818e97
-    pre += " bpf_probe_read(&_val, sizeof(_val), (u64)&";
818e97
+    pre += " bpf_probe_read(&_val, sizeof(_val), (void *)&";
818e97
   post = rhs + "); _val; })";
818e97
   rewriter_.InsertText(expansionLoc(GET_BEGINLOC(E)), pre);
818e97
   rewriter_.ReplaceText(expansionRange(SourceRange(member, GET_ENDLOC(E))), post);
818e97
@@ -635,9 +635,9 @@ bool ProbeVisitor::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
818e97
 
818e97
   pre = "({ typeof(" + E->getType().getAsString() + ") _val; __builtin_memset(&_val, 0, sizeof(_val));";
818e97
   if (cannot_fall_back_safely)
818e97
-    pre += " bpf_probe_read_kernel(&_val, sizeof(_val), (u64)((";
818e97
+    pre += " bpf_probe_read_kernel(&_val, sizeof(_val), (void *)((";
818e97
   else
818e97
-    pre += " bpf_probe_read(&_val, sizeof(_val), (u64)((";
818e97
+    pre += " bpf_probe_read(&_val, sizeof(_val), (void *)((";
818e97
   if (isMemberDereference(base)) {
818e97
     pre += "&";
818e97
     // If the base of the array subscript is a member dereference, we'll rewrite
818e97
@@ -747,8 +747,8 @@ void BTypeVisitor::genParamDirectAssign(FunctionDecl *D, string& preamble,
818e97
       arg->addAttr(UnavailableAttr::CreateImplicit(C, "ptregs"));
818e97
       size_t d = idx - 1;
818e97
       const char *reg = calling_conv_regs[d];
818e97
-      preamble += " " + text + " = " + fn_args_[0]->getName().str() + "->" +
818e97
-                  string(reg) + ";";
818e97
+      preamble += " " + text + " = (" + arg->getType().getAsString() + ")" +
818e97
+                  fn_args_[0]->getName().str() + "->" + string(reg) + ";";
818e97
     }
818e97
   }
818e97
 }
818e97
@@ -762,7 +762,7 @@ void BTypeVisitor::genParamIndirectAssign(FunctionDecl *D, string& preamble,
818e97
 
818e97
     if (idx == 0) {
818e97
       new_ctx = "__" + arg->getName().str();
818e97
-      preamble += " struct pt_regs * " + new_ctx + " = " +
818e97
+      preamble += " struct pt_regs * " + new_ctx + " = (void *)" +
818e97
                   arg->getName().str() + "->" +
818e97
                   string(calling_conv_regs[0]) + ";";
818e97
     } else {
818e97
-- 
818e97
2.38.1
818e97