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

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