Blame SOURCES/bcc-0.25.0-Fix-bpf_pseudo_fd-type-conversion-error.patch

f869ca
From 728005aac7c23590a406ac67235d915e416bff5d Mon Sep 17 00:00:00 2001
f869ca
From: Yonghong Song <yhs@fb.com>
f869ca
Date: Sat, 13 Aug 2022 17:50:07 -0700
f869ca
Subject: [PATCH 1/2] Fix bpf_pseudo_fd() type conversion error
f869ca
f869ca
With llvm15 and llvm16, the following command line
f869ca
  sudo ./trace.py 'smp_call_function_single "%K", arg1'
f869ca
will cause error:
f869ca
  /virtual/main.c:60:36: error: incompatible integer to pointer conversion passing 'u64'
f869ca
    (aka 'unsigned long long') to parameter of type 'void *' [-Wint-conversion]
f869ca
        bpf_perf_event_output(ctx, bpf_pseudo_fd(1, -1), CUR_CPU_IDENTIFIER, &__data, sizeof(__data));
f869ca
                                   ^~~~~~~~~~~~~~~~~~~~
f869ca
  1 error generated.
f869ca
  Failed to compile BPF module <text>
f869ca
f869ca
In helpers.h, we have
f869ca
  u64 bpf_pseudo_fd(u64, u64) asm("llvm.bpf.pseudo");
f869ca
Apparently, <= llvm14 can tolerate u64 -> 'void *' conversion, but
f869ca
llvm15 by default will cause an error.
f869ca
f869ca
Let us explicitly convert bpf_pseudo_fd to 'void *' to avoid
f869ca
such errors.
f869ca
f869ca
Signed-off-by: Yonghong Song <yhs@fb.com>
f869ca
---
f869ca
 src/cc/frontends/clang/b_frontend_action.cc | 10 +++++-----
f869ca
 1 file changed, 5 insertions(+), 5 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 a4e05b16..dbeba3e4 100644
f869ca
--- a/src/cc/frontends/clang/b_frontend_action.cc
f869ca
+++ b/src/cc/frontends/clang/b_frontend_action.cc
f869ca
@@ -957,7 +957,7 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
f869ca
           string arg0 = rewriter_.getRewrittenText(expansionRange(Call->getArg(0)->getSourceRange()));
f869ca
           string args_other = rewriter_.getRewrittenText(expansionRange(SourceRange(GET_BEGINLOC(Call->getArg(1)),
f869ca
                                                            GET_ENDLOC(Call->getArg(2)))));
f869ca
-          txt = "bpf_perf_event_output(" + arg0 + ", bpf_pseudo_fd(1, " + fd + ")";
f869ca
+          txt = "bpf_perf_event_output(" + arg0 + ", (void *)bpf_pseudo_fd(1, " + fd + ")";
f869ca
           txt += ", CUR_CPU_IDENTIFIER, " + args_other + ")";
f869ca
 
f869ca
           // e.g.
f869ca
@@ -986,7 +986,7 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
f869ca
           string meta_len = rewriter_.getRewrittenText(expansionRange(Call->getArg(3)->getSourceRange()));
f869ca
           txt = "bpf_perf_event_output(" +
f869ca
             skb + ", " +
f869ca
-            "bpf_pseudo_fd(1, " + fd + "), " +
f869ca
+            "(void *)bpf_pseudo_fd(1, " + fd + "), " +
f869ca
             "((__u64)" + skb_len + " << 32) | BPF_F_CURRENT_CPU, " +
f869ca
             meta + ", " +
f869ca
             meta_len + ");";
f869ca
@@ -1006,12 +1006,12 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
f869ca
           string keyp = rewriter_.getRewrittenText(expansionRange(Call->getArg(1)->getSourceRange()));
f869ca
           string flag = rewriter_.getRewrittenText(expansionRange(Call->getArg(2)->getSourceRange()));
f869ca
           txt = "bpf_" + string(memb_name) + "(" + ctx + ", " +
f869ca
-            "bpf_pseudo_fd(1, " + fd + "), " + keyp + ", " + flag + ");";
f869ca
+            "(void *)bpf_pseudo_fd(1, " + fd + "), " + keyp + ", " + flag + ");";
f869ca
         } else if (memb_name == "ringbuf_output") {
f869ca
           string name = string(Ref->getDecl()->getName());
f869ca
           string args = rewriter_.getRewrittenText(expansionRange(SourceRange(GET_BEGINLOC(Call->getArg(0)),
f869ca
                                                            GET_ENDLOC(Call->getArg(2)))));
f869ca
-          txt = "bpf_ringbuf_output(bpf_pseudo_fd(1, " + fd + ")";
f869ca
+          txt = "bpf_ringbuf_output((void *)bpf_pseudo_fd(1, " + fd + ")";
f869ca
           txt += ", " + args + ")";
f869ca
 
f869ca
           // e.g.
f869ca
@@ -1033,7 +1033,7 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
f869ca
         } else if (memb_name == "ringbuf_reserve") {
f869ca
           string name = string(Ref->getDecl()->getName());
f869ca
           string arg0 = rewriter_.getRewrittenText(expansionRange(Call->getArg(0)->getSourceRange()));
f869ca
-          txt = "bpf_ringbuf_reserve(bpf_pseudo_fd(1, " + fd + ")";
f869ca
+          txt = "bpf_ringbuf_reserve((void *)bpf_pseudo_fd(1, " + fd + ")";
f869ca
           txt += ", " + arg0 + ", 0)"; // Flags in reserve are meaningless
f869ca
         } else if (memb_name == "ringbuf_discard") {
f869ca
           string name = string(Ref->getDecl()->getName());
f869ca
-- 
f869ca
2.38.1
f869ca