Search code examples
compiler-errorsalpine-linuxbpfbcc-bpf

Building bcc in alpine, "does not name a type" error


I'm trying to build bcc bcc Alpine.

This is the Dockerfile I wrote to compile bcc:

FROM alpine:3.7

RUN apk add --update \
  git \
  llvm-dev \
  llvm-static \
  clang-dev \
  clang-static \
  cmake \
  flex-dev \
  bison \
  luajit-dev \
  build-base \
  iperf \
  linux-headers \
  elfutils-dev \
  zlib-dev \
  python-dev

RUN ln -s /usr/lib/cmake/llvm5/ /usr/lib/cmake/llvm; \
    ln -s /usr/include/llvm5/llvm-c/ /usr/include/llvm-c; \
    ln -s /usr/include/llvm5/llvm/ /usr/include/llvm

RUN git clone https://github.com/iovisor/bcc.git

WORKDIR /bcc/build

RUN cmake .. -DCMAKE_INSTALL_PREFIX=/usr

Unfortunately, when running make I stumble upon the following error:

# make
[  1%] [FLEX][Lexer] Building scanner with flex 2.6.4
lexer.ll:110: warning, -s option given but default rule can be matched
[  2%] [BISON][Parser] Building parser with bison 3.0.4
parser.yy:19.9-17: warning: deprecated directive, use ‘%define api.namespace ebpf::cc’ [-Wdeprecated]
 %define namespace "ebpf::cc"
         ^^^^^^^^^
parser.yy:19.9-17: warning: %define variable 'api.namespace' requires '{...}' values [-Wdeprecated]
 %define namespace "ebpf::cc"
         ^^^^^^^^^
parser.yy:20.9-25: warning: %define variable 'parser_class_name' requires '{...}' values [-Wdeprecated]
 %define parser_class_name "BisonParser"
         ^^^^^^^^^^^^^^^^^
Scanning dependencies of target b_frontend
[  3%] Building CXX object src/cc/frontends/b/CMakeFiles/b_frontend.dir/loader.cc.o
[  4%] Building CXX object src/cc/frontends/b/CMakeFiles/b_frontend.dir/codegen_llvm.cc.o
[  5%] Building CXX object src/cc/frontends/b/CMakeFiles/b_frontend.dir/node.cc.o
[  6%] Building CXX object src/cc/frontends/b/CMakeFiles/b_frontend.dir/parser.cc.o
[  7%] Building CXX object src/cc/frontends/b/CMakeFiles/b_frontend.dir/printer.cc.o
[  8%] Building CXX object src/cc/frontends/b/CMakeFiles/b_frontend.dir/type_check.cc.o
[  9%] Building CXX object src/cc/frontends/b/CMakeFiles/b_frontend.dir/parser.yy.cc.o
[ 10%] Building CXX object src/cc/frontends/b/CMakeFiles/b_frontend.dir/lexer.ll.cc.o
[ 11%] Linking CXX static library libb_frontend.a
[ 11%] Built target b_frontend
Scanning dependencies of target bcc-loader-static
[ 12%] Building CXX object src/cc/CMakeFiles/bcc-loader-static.dir/bcc_syms.cc.o
[ 13%] Building C object src/cc/CMakeFiles/bcc-loader-static.dir/bcc_elf.c.o
[ 14%] Building C object src/cc/CMakeFiles/bcc-loader-static.dir/bcc_perf_map.c.o
[ 15%] Building C object src/cc/CMakeFiles/bcc-loader-static.dir/bcc_proc.c.o
[ 17%] Building CXX object src/cc/CMakeFiles/bcc-loader-static.dir/ns_guard.cc.o
[ 18%] Building CXX object src/cc/CMakeFiles/bcc-loader-static.dir/common.cc.o
[ 19%] Linking CXX static library libbcc-loader-static.a
[ 19%] Built target bcc-loader-static
Scanning dependencies of target bpf-static
[ 20%] Building C object src/cc/CMakeFiles/bpf-static.dir/libbpf.c.o
[ 21%] Building C object src/cc/CMakeFiles/bpf-static.dir/perf_reader.c.o
/bcc/src/cc/perf_reader.c: In function 'read_data_head':
/bcc/src/cc/perf_reader.c:213:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   uint64_t data_head = *((volatile uint64_t *)&perf_header->data_head);
   ^~~~~~~~
[ 22%] Linking C static library libbpf.a
[ 22%] Built target bpf-static
Scanning dependencies of target api-static
[ 23%] Building CXX object src/cc/api/CMakeFiles/api-static.dir/BPF.cc.o
In file included from /bcc/src/cc/usdt.h:23:0,
                 from /bcc/src/cc/api/BPF.cc:35:
/bcc/src/cc/ns_guard.h:35:3: error: 'ino_t' does not name a type
   ino_t target_ino() const { return target_ino_; }
   ^~~~~
/bcc/src/cc/ns_guard.h:40:3: error: 'ino_t' does not name a type
   ino_t target_ino_;
   ^~~~~
In file included from /bcc/src/cc/api/BPF.cc:35:0:
/bcc/src/cc/usdt.h: In member function 'ino_t USDT::Context::inode() const':
/bcc/src/cc/usdt.h:259:52: error: 'class ProcMountNS' has no member named 'target_ino'; did you mean 'target_fd_'?
   ino_t inode() const { return mount_ns_instance_->target_ino(); }
                                                    ^~~~~~~~~~
make[2]: *** [src/cc/api/CMakeFiles/api-static.dir/build.make:63: src/cc/api/CMakeFiles/api-static.dir/BPF.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:334: src/cc/api/CMakeFiles/api-static.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
#

How do I get around this issue?


Solution

  • Somewhat figured it out.

    ino_t was not available in src/cc/ns_guard.h. I added include that defined ino_t:

    #include <sys/types.h>
    

    There were other obstacles in building bcc on Alpine though:

    • in file tests/cc/test_c_api.cc I had to comment out this section:

      if (dlinfo(dlhdl, RTLD_DI_ORIGIN, &libpath) < 0) {
        fprintf(stderr, "Unable to find origin of libz.so.1: %s\n", dlerror());
        return -1;
      }
      

      because for some reason RTLD_DI_ORIGIN is not present in /usr/include/dlfcn.h:

      cat /usr/include/dlfcn.h | grep RTLD_DI_ORIGIN
      
    • install a couple of missing packages (I updated original Dockerfile in question to have them included).