lizrice / learning-ebpf

Learning eBPF, published by O'Reilly - out now! Here's where you'll find a VM config for the examples, and more

Home Page:https://www.amazon.com/Learning-eBPF-Programming-Observability-Networking/dp/1098135121

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chapter 2 - hello-tail fail at line 41

jricoder opened this issue · comments

Hello, I have carefully followed the install instructions.

However, there is a fail at line 41 in hello-tail.py from Chapter 2.

b = BPF(text=program)

File "/usr/lib/python3.11/site-packages/bcc/init.py", line 476, in init
raise Exception("Failed to compile BPF module %s" % (src_file or ""))
Exception: Failed to compile BPF module

This is on Fedora 38.

The main book repo, libbf repo, and bpftool repo were cloned from source, and the 'make install" run in the nested folders.

Some online research may show that recent changes to Clang are part of this error. However, not sure other than this point here. Thank you.

Not sure if we are running into the same error but I ran into a -Wint-conversion error:

/virtual/main.c:19:20: error: incompatible pointer to integer conversion passing 'void *' to parameter of type 'u64' (aka 'unsigned long long') [-Wint-conversion]
    bpf_tail_call_((void *)bpf_pseudo_fd(1, -1), ctx, opcode);
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/virtual/include/bcc/helpers.h:552:25: note: passing argument to parameter 'map_fd' here
void bpf_tail_call_(u64 map_fd, void *ctx, int index) {
                        ^
1 error generated.
Traceback (most recent call last):
  File "/home/dan/ebpf-py/ebpf_py/tail-calls.py", line 37, in <module>
    b = BPF(text=program)
  File "/usr/lib/python3.9/site-packages/bcc/__init__.py", line 476, in __init__
    raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>

Based on the release notes for Clang15, checks for implicit casts now default to an error.

The -Wint-conversion warning diagnostic for implicit int <-> pointer conversions now defaults to an error in all C language modes. It may be downgraded to a warning with -Wno-error=int-conversion, or disabled entirely with -Wno-int-conversion.

Reading through the clang docs, I found a section on suppressing warning by using pragmas and looked through the examples in the ARM Reference Guide for usage.

I was able to suppress the error by adding a pragma at the beginning of the eBPF program:

#!/usr/bin/python3
from bcc import BPF
import ctypes as ct

program = r"""
#pragma clang diagnostic ignored "-Wint-conversion"

BPF_PROG_ARRAY(syscall, 300);

...
...

Would be interested in learning a better way to fix this.

I hope this helps!

I think @D-Netz is right about the cause - there are similar issues showing up in the BCC examples, and it looks like it has been fixed in BCC here. Next step is to see whether using a more up-to-date release of BCC fixes this example

@jricoder assuming you do have clang 15 (which you can check with clang --version) then you'll need BCC version 0.27.0 or later. Can you confirm what BCC version you saw this issue with? The package versions installed by Fedora 38 are likely different from what I tested with on Ubuntu 22.04.

I will make a note on the README about this. If you still see the issue with a newer version of BCC, please feel free to reopen this.

@D-Netz it works.

@lizrice
I'm using the latest BCC still facing the issue.
Can you look into this?
Here's the link of the issue I created:

iovisor/bcc#4898