Skip to content

Commit

Permalink
Unite libbpf includes
Browse files Browse the repository at this point in the history
Currently we include headers from local libbpf subpackage,
which does not work if user specify LIBBPF_INCLUDE_DIR.

Adding HAVE_EXTERNAL_LIBBPF macro, that gets defined when
user specifies libbpf header path. This macro is checked
in bcc_libbpf_inc.h and proper files are included.

Using bcc_libbpf_inc.h in place of libbpf includes.

Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri authored and yonghong-song committed Feb 27, 2020
1 parent 18da40c commit 1e7862f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
14 changes: 8 additions & 6 deletions src/cc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_MAJOR_VERSION=${CMAKE_MATCH_1}")

include(static_libstdc++)

if(LIBBPF_FOUND)
# We need to include the libbpf packaged source to get the
# headers location, becaseu they are installed under 'bpf'
# directory, but the libbpf code references them localy

include_directories(${LIBBPF_INCLUDE_DIR}/bpf)
if(LIBBPF_INCLUDE_DIR)
# Add user libbpf include and notify compilation
# that we are using external libbpf. It's checked
# in src/cc/libbpf.h and proper files are included.
include_directories(${LIBBPF_INCLUDE_DIR})
add_definitions(-DHAVE_EXTERNAL_LIBBPF)
endif()

if(LIBBPF_FOUND)
set(extract_dir ${CMAKE_CURRENT_BINARY_DIR}/libbpf_a_extract)
execute_process(COMMAND sh -c "mkdir -p ${extract_dir} && cd ${extract_dir} && ${CMAKE_AR} x ${LIBBPF_STATIC_LIBRARIES}")
file(GLOB libbpf_sources "${extract_dir}/*.o")
Expand Down
3 changes: 1 addition & 2 deletions src/cc/bcc_btf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#include <string.h>
#include "linux/btf.h"
#include "libbpf.h"
#include "libbpf/src/libbpf.h"
#include "libbpf/src/btf.h"
#include "bcc_libbpf_inc.h"
#include <vector>

#define BCC_MAX_ERRNO 4095
Expand Down
11 changes: 11 additions & 0 deletions src/cc/bcc_libbpf_inc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#ifdef HAVE_EXTERNAL_LIBBPF
# include <bpf/bpf.h>
# include <bpf/btf.h>
# include <bpf/libbpf.h>
#else
# include "libbpf/src/bpf.h"
# include "libbpf/src/btf.h"
# include "libbpf/src/libbpf.h"
#endif
2 changes: 1 addition & 1 deletion src/cc/bpf_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include "exported_files.h"
#include "libbpf.h"
#include "bcc_btf.h"
#include "libbpf/src/bpf.h"
#include "bcc_libbpf_inc.h"

namespace ebpf {

Expand Down
2 changes: 1 addition & 1 deletion src/cc/frontends/clang/b_frontend_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "loader.h"
#include "table_storage.h"
#include "arch_helper.h"
#include "libbpf/src/bpf.h"
#include "bcc_libbpf_inc.h"

#include "libbpf.h"

Expand Down
3 changes: 1 addition & 2 deletions src/cc/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
// TODO: Remove this when CentOS 6 support is not needed anymore
#include "setns.h"

#include "libbpf/src/bpf.h"
#include "libbpf/src/libbpf.h"
#include "bcc_libbpf_inc.h"

// TODO: remove these defines when linux-libc-dev exports them properly

Expand Down

0 comments on commit 1e7862f

Please sign in to comment.