Skip to content

Commit 21507cd

Browse files
anakryikoacmel
authored andcommitted
pahole: add libbpf as submodule under lib/bpf
This change allows to use libbpf definitions and APIs from pahole. Signed-off-by: Andrii Nakryiko <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Martin KaFai Lau <[email protected]> Cc: Yonghong Song <[email protected]> Cc: [email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent c25ada5 commit 21507cd

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "lib/bpf"]
2+
path = lib/bpf
3+
url = https://github.com/libbpf/libbpf

CMakeLists.txt

+47-2
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,60 @@ add_definitions(-D_GNU_SOURCE -DDWARVES_VERSION="v1.12")
3131
find_package(DWARF REQUIRED)
3232
find_package(ZLIB REQUIRED)
3333

34+
# make sure git submodule(s) are checked out
35+
find_package(Git QUIET)
36+
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
37+
# Update submodules as needed
38+
option(GIT_SUBMODULE "Check submodules during build" ON)
39+
if(GIT_SUBMODULE)
40+
message(STATUS "Submodule update")
41+
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
42+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
43+
RESULT_VARIABLE GIT_SUBMOD_RESULT)
44+
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
45+
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
46+
else()
47+
message(STATUS "Submodule update - done")
48+
endif()
49+
endif()
50+
endif()
51+
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/lib/bpf/src/btf.h")
52+
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
53+
endif()
54+
3455
_set_fancy(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${__LIB}" "libdir")
3556

57+
# libbpf uses reallocarray, which is not available in all versions of glibc
58+
# libbpf's include/tools/libc_compat.h provides implementation, but needs
59+
# COMPACT_NEED_REALLOCARRAY to be set
60+
INCLUDE(CheckCSourceCompiles)
61+
CHECK_C_SOURCE_COMPILES(
62+
"
63+
#define _GNU_SOURCE
64+
#include <stdlib.h>
65+
int main(void)
66+
{
67+
return !!reallocarray(NULL, 1, 1);
68+
}
69+
" HAVE_REALLOCARRAY_SUPPORT)
70+
if (NOT HAVE_REALLOCARRAY_SUPPORT)
71+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOMPAT_NEED_REALLOCARRAY")
72+
endif()
73+
74+
file(GLOB libbpf_sources "lib/bpf/src/*.c")
75+
add_library(bpf STATIC ${libbpf_sources})
76+
set_target_properties(bpf PROPERTIES OUTPUT_NAME bpf)
77+
target_include_directories(bpf PRIVATE
78+
${CMAKE_CURRENT_SOURCE_DIR}/lib/bpf/include
79+
${CMAKE_CURRENT_SOURCE_DIR}/lib/bpf/include/uapi)
80+
3681
set(dwarves_LIB_SRCS dwarves.c dwarves_fprintf.c gobuffer strings
3782
ctf_encoder.c ctf_loader.c libctf.c btf_encoder.c btf_loader.c libbtf.c
3883
dwarf_loader.c dutil.c elf_symtab.c rbtree.c)
3984
add_library(dwarves SHARED ${dwarves_LIB_SRCS})
4085
set_target_properties(dwarves PROPERTIES VERSION 1.0.0 SOVERSION 1)
4186
set_target_properties(dwarves PROPERTIES INTERFACE_LINK_LIBRARIES "")
42-
target_link_libraries(dwarves ${DWARF_LIBRARIES} ${ZLIB_LIBRARIES})
87+
target_link_libraries(dwarves ${DWARF_LIBRARIES} ${ZLIB_LIBRARIES} bpf)
4388

4489
set(dwarves_emit_LIB_SRCS dwarves_emit.c)
4590
add_library(dwarves_emit SHARED ${dwarves_emit_LIB_SRCS})
@@ -75,7 +120,7 @@ set(pglobal_SRCS pglobal.c)
75120
add_executable(pglobal ${pglobal_SRCS})
76121
target_link_libraries(pglobal dwarves)
77122

78-
set(pfunct_SRCS pfunct.c )
123+
set(pfunct_SRCS pfunct.c)
79124
add_executable(pfunct ${pfunct_SRCS})
80125
target_link_libraries(pfunct dwarves dwarves_emit ${ELF_LIBRARY})
81126

lib/bpf

Submodule bpf added at b19c6dc

0 commit comments

Comments
 (0)