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

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