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

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