bpf-developer-tutorial icon indicating copy to clipboard operation
bpf-developer-tutorial copied to clipboard

Failed to compile the bpf code in tutorial 1

Open handewo opened this issue 1 year ago • 1 comments

OS: Rocky Linux 9 ecc version: 0.3.4

> $ ./ecc minimal.bpf.c
INFO [ecc_rs::bpf_compiler] Compiling bpf object...
INFO [ecc_rs::bpf_compiler] $ "clang" CommandArgs { inner: ["-g", "-O2", "-target", "bpf", "-Wno-unknown-attributes", "-D__TARGET_ARCH_x86", "-idirafter", "/usr/bin/../lib/clang/18/include", "-idirafter", "/usr/local/include", "-idirafter", "/usr/include", "-I/tmp/.tmpDVfSiQ/include", "-I/tmp/.tmpDVfSiQ/include/vmlinux/x86", "-I/home/rick/eunomia", "-c", "minimal.bpf.c", "-o", "minimal.bpf.o"] }
INFO [ecc_rs::bpf_compiler]
ERROR [ecc_rs::bpf_compiler] In file included from minimal.bpf.c:3:
In file included from /tmp/.tmpDVfSiQ/include/bpf/bpf_helpers.h:11:
/tmp/.tmpDVfSiQ/include/bpf/bpf_helper_defs.h:78:90: error: unknown type name '__u64'
   78 | static long (* const bpf_map_update_elem)(void *map, const void *key, const void *value, __u64 flags) = (void *) 2;
      |                                                                                          ^
/tmp/.tmpDVfSiQ/include/bpf/bpf_helper_defs.h:102:49: error: unknown type name '__u32'
  102 | static long (* const bpf_probe_read)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 4;
      |                                                 ^

ecc compile successfully after change include as below:

/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
#define BPF_NO_GLOBAL_DATA
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>

handewo avatar Apr 24 '25 03:04 handewo

> $ dnf list installed|grep bpf
bpftool.x86_64                        7.4.0-503.38.1.el9_5            @baseos
bpftrace.x86_64                       0.21.1-1.el9                    @appstream
libbpf.x86_64                         2:1.4.0-1.el9                   @baseos
libbpf-devel.x86_64                   2:1.4.0-1.el9                   @crb

handewo avatar Apr 24 '25 03:04 handewo