summaryrefslogtreecommitdiffstats
path: root/dynamic-layers
diff options
context:
space:
mode:
authorMatteo Croce <mcroce@microsoft.com>2021-03-09 19:04:58 +0100
committerKhem Raj <raj.khem@gmail.com>2021-03-10 18:09:24 -0800
commit64386310b425bb6eb51c1f4c4590af5ed5435ea9 (patch)
treed65df8dc35e046c82c3ba01d790d11a6c919f764 /dynamic-layers
parent9007cf073e40c429fa5e729dda114e4248a99b57 (diff)
downloadmeta-clang-64386310b425bb6eb51c1f4c4590af5ed5435ea9.tar.gz
bcc: link with dynamic libbpf
Link bcc dynamically against libbpf. This reduces the size of libbcc.so from 68 MB to 3 MB. Backport some patches from upstream which are needed for the actual dynamic linking. Signed-off-by: Matteo Croce <mcroce@microsoft.com>
Diffstat (limited to 'dynamic-layers')
-rw-r--r--dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0001-cmake-link-dynamically-to-libclang-cpp-if-found-and-.patch68
-rw-r--r--dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0002-cmake-always-link-to-packaged-libbpf-if-CMAKE_USE_LI.patch239
-rw-r--r--dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0003-Remove-libbcc-no-libbpf-shared-library-change-libbcc.patch156
-rw-r--r--dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0004-cmake-look-for-either-static-or-dynamic-libraries.patch69
-rw-r--r--dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc_0.17.0.bb11
5 files changed, 542 insertions, 1 deletions
diff --git a/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0001-cmake-link-dynamically-to-libclang-cpp-if-found-and-.patch b/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0001-cmake-link-dynamically-to-libclang-cpp-if-found-and-.patch
new file mode 100644
index 0000000..74b2e27
--- /dev/null
+++ b/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0001-cmake-link-dynamically-to-libclang-cpp-if-found-and-.patch
@@ -0,0 +1,68 @@
1From f14f69d996ffc1c61dd523b839271d4a51328e4d Mon Sep 17 00:00:00 2001
2From: Luca Boccassi <bluca@debian.org>
3Date: Fri, 1 Jan 2021 19:04:37 +0000
4Subject: [PATCH 1/3] cmake: link dynamically to libclang-cpp if found and
5 ENABLE_LLVM_SHARED is set
6
7ENABLE_LLVM_SHARED allows to dynamically link against libLLVM, but
8libclang is still unconditionally linked statically.
9Search for libclang-cpp.so, and if it is found and ENABLE_LLVM_SHARED
10is set dynamically link against it.
11Also expand the libstdc++ static linking check to include this new
12condition.
13---
14 CMakeLists.txt | 1 +
15 cmake/clang_libs.cmake | 4 ++++
16 cmake/static_libstdc++.cmake | 2 +-
17 3 files changed, 6 insertions(+), 1 deletion(-)
18
19diff --git a/CMakeLists.txt b/CMakeLists.txt
20index 74fe4f19..b2e334e9 100644
21--- a/CMakeLists.txt
22+++ b/CMakeLists.txt
23@@ -76,6 +76,7 @@ find_library(libclangRewrite NAMES clangRewrite clang-cpp HINTS ${CLANG_SEARCH})
24 find_library(libclangSema NAMES clangSema clang-cpp HINTS ${CLANG_SEARCH})
25 find_library(libclangSerialization NAMES clangSerialization clang-cpp HINTS ${CLANG_SEARCH})
26 find_library(libclangASTMatchers NAMES clangASTMatchers clang-cpp HINTS ${CLANG_SEARCH})
27+find_library(libclang-shared libclang-cpp.so HINTS ${CLANG_SEARCH})
28 if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")
29 message(FATAL_ERROR "Unable to find clang libraries")
30 endif()
31diff --git a/cmake/clang_libs.cmake b/cmake/clang_libs.cmake
32index c33b635c..3f1523b7 100644
33--- a/cmake/clang_libs.cmake
34+++ b/cmake/clang_libs.cmake
35@@ -26,6 +26,9 @@ llvm_map_components_to_libnames(_llvm_libs ${llvm_raw_libs})
36 llvm_expand_dependencies(llvm_libs ${_llvm_libs})
37 endif()
38
39+if(ENABLE_LLVM_SHARED AND NOT libclang-shared STREQUAL "libclang-shared-NOTFOUND")
40+set(clang_libs ${libclang-shared})
41+else()
42 # order is important
43 set(clang_libs
44 ${libclangFrontend}
45@@ -46,6 +49,7 @@ list(APPEND clang_libs
46 ${libclangAST}
47 ${libclangLex}
48 ${libclangBasic})
49+endif()
50
51 # prune unused llvm static library stuff when linking into the new .so
52 set(_exclude_flags)
53diff --git a/cmake/static_libstdc++.cmake b/cmake/static_libstdc++.cmake
54index 3c8ac179..787ed9ad 100644
55--- a/cmake/static_libstdc++.cmake
56+++ b/cmake/static_libstdc++.cmake
57@@ -1,7 +1,7 @@
58 # only turn on static-libstdc++ if also linking statically against clang
59 string(REGEX MATCH ".*[.]a$" LIBCLANG_ISSTATIC "${libclangBasic}")
60 # if gcc 4.9 or higher is used, static libstdc++ is a good option
61-if (CMAKE_COMPILER_IS_GNUCC AND LIBCLANG_ISSTATIC)
62+if (CMAKE_COMPILER_IS_GNUCC AND LIBCLANG_ISSTATIC AND (NOT ENABLE_LLVM_SHARED OR libclang-shared STREQUAL "libclang-shared-NOTFOUND"))
63 execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
64 if (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
65 execute_process(COMMAND ${CMAKE_C_COMPILER} -print-libgcc-file-name OUTPUT_VARIABLE GCC_LIB)
66--
672.29.2
68
diff --git a/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0002-cmake-always-link-to-packaged-libbpf-if-CMAKE_USE_LI.patch b/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0002-cmake-always-link-to-packaged-libbpf-if-CMAKE_USE_LI.patch
new file mode 100644
index 0000000..0269fa4
--- /dev/null
+++ b/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0002-cmake-always-link-to-packaged-libbpf-if-CMAKE_USE_LI.patch
@@ -0,0 +1,239 @@
1From ab9a9dadf294f69e024a8b58c983a6c2085c223a Mon Sep 17 00:00:00 2001
2From: Luca Boccassi <bluca@debian.org>
3Date: Fri, 8 Jan 2021 16:58:56 +0000
4Subject: [PATCH 2/3] cmake: always link to packaged libbpf if
5 CMAKE_USE_LIBBPF_PACKAGE is set (#3210)
6
7Some of the executables still link to the local static versions
8even if the user requested CMAKE_USE_LIBBPF_PACKAGE. Fix this by
9using bcc-shared-no-libbpf more widely if the variable is set.
10
11Skip the git submodule and the extraction commands if the user
12set CMAKE_USE_LIBBPF_PACKAGE
13---
14 CMakeLists.txt | 2 +-
15 examples/cpp/CMakeLists.txt | 59 ++++++++----------------------
16 examples/cpp/pyperf/CMakeLists.txt | 5 +++
17 introspection/CMakeLists.txt | 8 +++-
18 src/cc/CMakeLists.txt | 29 ++++++++++-----
19 tests/cc/CMakeLists.txt | 22 +++++++----
20 6 files changed, 61 insertions(+), 64 deletions(-)
21
22diff --git a/CMakeLists.txt b/CMakeLists.txt
23index b2e334e9..b68571ea 100644
24--- a/CMakeLists.txt
25+++ b/CMakeLists.txt
26@@ -14,7 +14,7 @@ endif()
27 enable_testing()
28
29 # populate submodules (libbpf)
30-if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/cc/libbpf/src)
31+if(NOT CMAKE_USE_LIBBPF_PACKAGE AND NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/cc/libbpf/src)
32 execute_process(COMMAND git submodule update --init --recursive
33 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
34 endif()
35diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt
36index dae0e9ce..dd343245 100644
37--- a/examples/cpp/CMakeLists.txt
38+++ b/examples/cpp/CMakeLists.txt
39@@ -11,49 +11,20 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
40
41 option(INSTALL_CPP_EXAMPLES "Install C++ examples. Those binaries are statically linked and can take plenty of disk space" OFF)
42
43-add_executable(HelloWorld HelloWorld.cc)
44-target_link_libraries(HelloWorld bcc-static)
45-
46-add_executable(CPUDistribution CPUDistribution.cc)
47-target_link_libraries(CPUDistribution bcc-static)
48-
49-add_executable(RecordMySQLQuery RecordMySQLQuery.cc)
50-target_link_libraries(RecordMySQLQuery bcc-static)
51-
52-add_executable(TCPSendStack TCPSendStack.cc)
53-target_link_libraries(TCPSendStack bcc-static)
54-
55-add_executable(RandomRead RandomRead.cc)
56-target_link_libraries(RandomRead bcc-static)
57-
58-add_executable(LLCStat LLCStat.cc)
59-target_link_libraries(LLCStat bcc-static)
60-
61-add_executable(FollyRequestContextSwitch FollyRequestContextSwitch.cc)
62-target_link_libraries(FollyRequestContextSwitch bcc-static)
63-
64-add_executable(UseExternalMap UseExternalMap.cc)
65-target_link_libraries(UseExternalMap bcc-static)
66-
67-add_executable(CGroupTest CGroupTest.cc)
68-target_link_libraries(CGroupTest bcc-static)
69-
70-add_executable(TaskIterator TaskIterator.cc)
71-target_link_libraries(TaskIterator bcc-static)
72-
73-add_executable(SkLocalStorageIterator SkLocalStorageIterator.cc)
74-target_link_libraries(SkLocalStorageIterator bcc-static)
75-
76-if(INSTALL_CPP_EXAMPLES)
77- install (TARGETS HelloWorld DESTINATION share/bcc/examples/cpp)
78- install (TARGETS CPUDistribution DESTINATION share/bcc/examples/cpp)
79- install (TARGETS RecordMySQLQuery DESTINATION share/bcc/examples/cpp)
80- install (TARGETS TCPSendStack DESTINATION share/bcc/examples/cpp)
81- install (TARGETS RandomRead DESTINATION share/bcc/examples/cpp)
82- install (TARGETS LLCStat DESTINATION share/bcc/examples/cpp)
83- install (TARGETS FollyRequestContextSwitch DESTINATION share/bcc/examples/cpp)
84- install (TARGETS UseExternalMap DESTINATION share/bcc/examples/cpp)
85- install (TARGETS CGroupTest DESTINATION share/bcc/examples/cpp)
86-endif(INSTALL_CPP_EXAMPLES)
87+file(GLOB EXAMPLES *.cc)
88+foreach(EXAMPLE ${EXAMPLES})
89+ get_filename_component(NAME ${EXAMPLE} NAME_WE)
90+ add_executable(${NAME} ${EXAMPLE})
91+
92+ if(NOT CMAKE_USE_LIBBPF_PACKAGE)
93+ target_link_libraries(${NAME} bcc-static)
94+ else()
95+ target_link_libraries(${NAME} bcc-shared-no-libbpf)
96+ endif()
97+
98+ if(INSTALL_CPP_EXAMPLES)
99+ install (TARGETS ${NAME} DESTINATION share/bcc/examples/cpp)
100+ endif(INSTALL_CPP_EXAMPLES)
101+endforeach()
102
103 add_subdirectory(pyperf)
104diff --git a/examples/cpp/pyperf/CMakeLists.txt b/examples/cpp/pyperf/CMakeLists.txt
105index 6f963c66..97420806 100644
106--- a/examples/cpp/pyperf/CMakeLists.txt
107+++ b/examples/cpp/pyperf/CMakeLists.txt
108@@ -7,6 +7,11 @@ include_directories(${CMAKE_SOURCE_DIR}/src/cc/libbpf/include/uapi)
109
110 add_executable(PyPerf PyPerf.cc PyPerfUtil.cc PyPerfBPFProgram.cc PyPerfLoggingHelper.cc PyPerfDefaultPrinter.cc Py36Offsets.cc)
111 target_link_libraries(PyPerf bcc-static)
112+if(NOT CMAKE_USE_LIBBPF_PACKAGE)
113+ target_link_libraries(PyPerf bcc-static)
114+else()
115+ target_link_libraries(PyPerf bcc-shared-no-libbpf)
116+endif()
117
118 if(INSTALL_CPP_EXAMPLES)
119 install (TARGETS PyPerf DESTINATION share/bcc/examples/cpp)
120diff --git a/introspection/CMakeLists.txt b/introspection/CMakeLists.txt
121index 4328ee11..6c83f0c8 100644
122--- a/introspection/CMakeLists.txt
123+++ b/introspection/CMakeLists.txt
124@@ -8,7 +8,13 @@ include_directories(${CMAKE_SOURCE_DIR}/src/cc/libbpf/include/uapi)
125 option(INSTALL_INTROSPECTION "Install BPF introspection tools" ON)
126 option(BPS_LINK_RT "Pass -lrt to linker when linking bps tool" ON)
127
128-set(bps_libs_to_link bpf-static elf z)
129+# Note that the order matters! bpf-static first, the rest later
130+if(CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
131+set(bps_libs_to_link bpf-shared ${LIBBPF_LIBRARIES})
132+else()
133+set(bps_libs_to_link bpf-static)
134+endif()
135+list(APPEND bps_libs_to_link elf z)
136 if(BPS_LINK_RT)
137 list(APPEND bps_libs_to_link rt)
138 endif()
139diff --git a/src/cc/CMakeLists.txt b/src/cc/CMakeLists.txt
140index 4021c662..c8ea63aa 100644
141--- a/src/cc/CMakeLists.txt
142+++ b/src/cc/CMakeLists.txt
143@@ -10,8 +10,12 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/frontends/clang)
144 include_directories(${LLVM_INCLUDE_DIRS})
145 include_directories(${LIBELF_INCLUDE_DIRS})
146 # todo: if check for kernel version
147-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include)
148-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include/uapi)
149+if (CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
150+ include_directories(${LIBBPF_INCLUDE_DIRS})
151+else()
152+ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include)
153+ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include/uapi)
154+endif()
155
156 # add_definitions has a problem parsing "-D_GLIBCXX_USE_CXX11_ABI=0", this is safer
157 separate_arguments(LLVM_DEFINITIONS)
158@@ -41,21 +45,26 @@ if(LIBBPF_INCLUDE_DIR)
159 add_definitions(-DHAVE_EXTERNAL_LIBBPF)
160 endif()
161
162-if(LIBBPF_FOUND)
163- set(extract_dir ${CMAKE_CURRENT_BINARY_DIR}/libbpf_a_extract)
164- execute_process(COMMAND sh -c "mkdir -p ${extract_dir} && cd ${extract_dir} && ${CMAKE_AR} x ${LIBBPF_STATIC_LIBRARIES}")
165- file(GLOB libbpf_sources "${extract_dir}/*.o")
166-else()
167- file(GLOB libbpf_sources "libbpf/src/*.c")
168-endif()
169+if(NOT CMAKE_USE_LIBBPF_PACKAGE)
170+ if(LIBBPF_FOUND)
171+ set(extract_dir ${CMAKE_CURRENT_BINARY_DIR}/libbpf_a_extract)
172+ execute_process(COMMAND sh -c "mkdir -p ${extract_dir} && cd ${extract_dir} && ${CMAKE_AR} x ${LIBBPF_STATIC_LIBRARIES}")
173+ file(GLOB libbpf_sources "${extract_dir}/*.o")
174+ else()
175+ file(GLOB libbpf_sources "libbpf/src/*.c")
176+ endif()
177
178-set(libbpf_uapi libbpf/include/uapi/linux/)
179+ set(libbpf_uapi libbpf/include/uapi/linux/)
180+endif()
181
182 add_library(bpf-static STATIC libbpf.c perf_reader.c ${libbpf_sources})
183 set_target_properties(bpf-static PROPERTIES OUTPUT_NAME bcc_bpf)
184 add_library(bpf-shared SHARED libbpf.c perf_reader.c ${libbpf_sources})
185 set_target_properties(bpf-shared PROPERTIES VERSION ${REVISION_LAST} SOVERSION 0)
186 set_target_properties(bpf-shared PROPERTIES OUTPUT_NAME bcc_bpf)
187+if(CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
188+ target_link_libraries(bpf-shared ${LIBBPF_LIBRARIES})
189+endif()
190
191 set(bcc_common_sources bcc_common.cc bpf_module.cc bcc_btf.cc exported_files.cc)
192 if (${LLVM_PACKAGE_VERSION} VERSION_EQUAL 6 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 6)
193diff --git a/tests/cc/CMakeLists.txt b/tests/cc/CMakeLists.txt
194index 528f1bda..b2fba5e3 100644
195--- a/tests/cc/CMakeLists.txt
196+++ b/tests/cc/CMakeLists.txt
197@@ -7,7 +7,11 @@ include_directories(${CMAKE_SOURCE_DIR}/src/cc/libbpf/include/uapi)
198 include_directories(${CMAKE_SOURCE_DIR}/tests/python/include)
199
200 add_executable(test_static test_static.c)
201-target_link_libraries(test_static bcc-static)
202+if(NOT CMAKE_USE_LIBBPF_PACKAGE)
203+ target_link_libraries(test_static bcc-static)
204+else()
205+ target_link_libraries(test_static bcc-shared-no-libbpf)
206+endif()
207
208 add_test(NAME c_test_static COMMAND ${TEST_WRAPPER} c_test_static sudo ${CMAKE_CURRENT_BINARY_DIR}/test_static)
209
210@@ -35,17 +39,19 @@ set(TEST_LIBBCC_SOURCES
211 utils.cc
212 test_parse_tracepoint.cc)
213
214-add_executable(test_libbcc ${TEST_LIBBCC_SOURCES})
215-
216 file(COPY dummy_proc_map.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
217 add_library(usdt_test_lib SHARED usdt_test_lib.cc)
218
219-add_dependencies(test_libbcc bcc-shared)
220-target_link_libraries(test_libbcc ${PROJECT_BINARY_DIR}/src/cc/libbcc.so dl usdt_test_lib)
221-set_target_properties(test_libbcc PROPERTIES INSTALL_RPATH ${PROJECT_BINARY_DIR}/src/cc)
222-target_compile_definitions(test_libbcc PRIVATE -DLIBBCC_NAME=\"libbcc.so\")
223+if(NOT CMAKE_USE_LIBBPF_PACKAGE)
224+ add_executable(test_libbcc ${TEST_LIBBCC_SOURCES})
225+ add_dependencies(test_libbcc bcc-shared)
226
227-add_test(NAME test_libbcc COMMAND ${TEST_WRAPPER} c_test_all sudo ${CMAKE_CURRENT_BINARY_DIR}/test_libbcc)
228+ target_link_libraries(test_libbcc ${PROJECT_BINARY_DIR}/src/cc/libbcc.so dl usdt_test_lib)
229+ set_target_properties(test_libbcc PROPERTIES INSTALL_RPATH ${PROJECT_BINARY_DIR}/src/cc)
230+ target_compile_definitions(test_libbcc PRIVATE -DLIBBCC_NAME=\"libbcc.so\")
231+
232+ add_test(NAME test_libbcc COMMAND ${TEST_WRAPPER} c_test_all sudo ${CMAKE_CURRENT_BINARY_DIR}/test_libbcc)
233+endif()
234
235 if(LIBBPF_FOUND)
236 add_executable(test_libbcc_no_libbpf ${TEST_LIBBCC_SOURCES})
237--
2382.29.2
239
diff --git a/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0003-Remove-libbcc-no-libbpf-shared-library-change-libbcc.patch b/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0003-Remove-libbcc-no-libbpf-shared-library-change-libbcc.patch
new file mode 100644
index 0000000..25e744f
--- /dev/null
+++ b/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0003-Remove-libbcc-no-libbpf-shared-library-change-libbcc.patch
@@ -0,0 +1,156 @@
1From c7509c9e6377a374ca28d73960d505e129aace7b Mon Sep 17 00:00:00 2001
2From: Luca Boccassi <bluca@debian.org>
3Date: Fri, 8 Jan 2021 17:04:03 +0000
4Subject: [PATCH 3/3] Remove libbcc-no-libbpf shared library, change libbcc
5 linkage instead
6
7The current upstream split does not work very well, as the SONAME is mangled so
8nothing recognises it. Applications link against libbcc, not libbcc_no_bpf.
9Remove it entirely, and switch the libbcc.so to dynamically
10link with libbpf if CMAKE_USE_LIBBPF_PACKAGE is set.
11---
12 examples/cpp/CMakeLists.txt | 2 +-
13 examples/cpp/pyperf/CMakeLists.txt | 2 +-
14 src/cc/CMakeLists.txt | 36 +++++++++++++-----------------
15 tests/cc/CMakeLists.txt | 8 +++----
16 4 files changed, 21 insertions(+), 27 deletions(-)
17
18diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt
19index dd343245..45b30280 100644
20--- a/examples/cpp/CMakeLists.txt
21+++ b/examples/cpp/CMakeLists.txt
22@@ -19,7 +19,7 @@ foreach(EXAMPLE ${EXAMPLES})
23 if(NOT CMAKE_USE_LIBBPF_PACKAGE)
24 target_link_libraries(${NAME} bcc-static)
25 else()
26- target_link_libraries(${NAME} bcc-shared-no-libbpf)
27+ target_link_libraries(${NAME} bcc-shared)
28 endif()
29
30 if(INSTALL_CPP_EXAMPLES)
31diff --git a/examples/cpp/pyperf/CMakeLists.txt b/examples/cpp/pyperf/CMakeLists.txt
32index 97420806..618b4e75 100644
33--- a/examples/cpp/pyperf/CMakeLists.txt
34+++ b/examples/cpp/pyperf/CMakeLists.txt
35@@ -10,7 +10,7 @@ target_link_libraries(PyPerf bcc-static)
36 if(NOT CMAKE_USE_LIBBPF_PACKAGE)
37 target_link_libraries(PyPerf bcc-static)
38 else()
39- target_link_libraries(PyPerf bcc-shared-no-libbpf)
40+ target_link_libraries(PyPerf bcc-shared)
41 endif()
42
43 if(INSTALL_CPP_EXAMPLES)
44diff --git a/src/cc/CMakeLists.txt b/src/cc/CMakeLists.txt
45index c8ea63aa..931de2d9 100644
46--- a/src/cc/CMakeLists.txt
47+++ b/src/cc/CMakeLists.txt
48@@ -83,6 +83,9 @@ set(bcc_sym_sources bcc_syms.cc bcc_elf.c bcc_perf_map.c bcc_proc.c)
49 set(bcc_common_headers libbpf.h perf_reader.h "${CMAKE_CURRENT_BINARY_DIR}/bcc_version.h")
50 set(bcc_table_headers file_desc.h table_desc.h table_storage.h)
51 set(bcc_api_headers bcc_common.h bpf_module.h bcc_exception.h bcc_syms.h bcc_proc.h bcc_elf.h)
52+if(LIBBPF_FOUND)
53+ set(bcc_common_sources ${bcc_common_sources} libbpf.c perf_reader.c)
54+endif()
55
56 if(ENABLE_CLANG_JIT)
57 add_library(bcc-shared SHARED
58@@ -91,16 +94,6 @@ add_library(bcc-shared SHARED
59 set_target_properties(bcc-shared PROPERTIES VERSION ${REVISION_LAST} SOVERSION 0)
60 set_target_properties(bcc-shared PROPERTIES OUTPUT_NAME bcc)
61
62-# If there's libbpf detected we build the libbcc-no-libbpf.so library, that
63-# dynamicaly links libbpf.so, in comparison to static link in libbcc.so.
64-if(LIBBPF_FOUND)
65- add_library(bcc-shared-no-libbpf SHARED
66- link_all.cc ${bcc_common_sources} ${bcc_table_sources} ${bcc_sym_sources}
67- ${bcc_util_sources} libbpf.c perf_reader.c)
68- set_target_properties(bcc-shared-no-libbpf PROPERTIES VERSION ${REVISION_LAST} SOVERSION 0)
69- set_target_properties(bcc-shared-no-libbpf PROPERTIES OUTPUT_NAME bcc-no-libbpf)
70-endif()
71-
72 if(ENABLE_USDT)
73 set(bcc_usdt_sources usdt/usdt.cc usdt/usdt_args.cc)
74 # else undefined
75@@ -123,18 +116,25 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${llvm_lib_exclude_f
76 set(bcc_common_libs b_frontend clang_frontend
77 -Wl,--whole-archive ${clang_libs} ${llvm_libs} -Wl,--no-whole-archive
78 ${LIBELF_LIBRARIES})
79-set(bcc_common_libs_for_a ${bcc_common_libs} bpf-static)
80-set(bcc_common_libs_for_s ${bcc_common_libs} bpf-static)
81-set(bcc_common_libs_for_n ${bcc_common_libs})
82-set(bcc_common_libs_for_lua b_frontend clang_frontend bpf-static
83+set(bcc_common_libs_for_a ${bcc_common_libs})
84+set(bcc_common_libs_for_s ${bcc_common_libs})
85+set(bcc_common_libs_for_lua b_frontend clang_frontend
86 ${clang_libs} ${llvm_libs} ${LIBELF_LIBRARIES})
87+if(LIBBPF_FOUND)
88+ list(APPEND bcc_common_libs_for_a ${LIBBPF_LIBRARIES})
89+ list(APPEND bcc_common_libs_for_s ${LIBBPF_LIBRARIES})
90+ list(APPEND bcc_common_libs_for_lua ${LIBBPF_LIBRARIES})
91+else()
92+ list(APPEND bcc_common_libs_for_a bpf-static)
93+ list(APPEND bcc_common_libs_for_s bpf-static)
94+ list(APPEND bcc_common_libs_for_lua bpf-static)
95+endif()
96
97 if(ENABLE_CPP_API)
98 add_subdirectory(api)
99 list(APPEND bcc_common_libs_for_a api-static)
100 # Keep all API functions
101 list(APPEND bcc_common_libs_for_s -Wl,--whole-archive api-static -Wl,--no-whole-archive)
102- list(APPEND bcc_common_libs_for_n -Wl,--whole-archive api-static -Wl,--no-whole-archive)
103 endif()
104
105 if(ENABLE_USDT)
106@@ -142,7 +142,6 @@ if(ENABLE_USDT)
107 add_subdirectory(usdt)
108 list(APPEND bcc_common_libs_for_a usdt-static)
109 list(APPEND bcc_common_libs_for_s usdt-static)
110- list(APPEND bcc_common_libs_for_n usdt-static)
111 list(APPEND bcc_common_libs_for_lua usdt-static)
112 endif()
113
114@@ -153,11 +152,6 @@ target_link_libraries(bcc-shared ${bcc_common_libs_for_s})
115 target_link_libraries(bcc-static ${bcc_common_libs_for_a} bcc-loader-static)
116 set(bcc-lua-static ${bcc-lua-static} ${bcc_common_libs_for_lua})
117
118-if(LIBBPF_FOUND)
119- target_link_libraries(bcc-shared-no-libbpf ${bcc_common_libs_for_n} ${LIBBPF_LIBRARIES})
120- install(TARGETS bcc-shared-no-libbpf LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
121-endif()
122-
123 install(TARGETS bcc-shared bcc-static bcc-loader-static bpf-static LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
124 install(FILES ${bcc_table_headers} DESTINATION include/bcc)
125 install(FILES ${bcc_api_headers} DESTINATION include/bcc)
126diff --git a/tests/cc/CMakeLists.txt b/tests/cc/CMakeLists.txt
127index b2fba5e3..58493248 100644
128--- a/tests/cc/CMakeLists.txt
129+++ b/tests/cc/CMakeLists.txt
130@@ -10,7 +10,7 @@ add_executable(test_static test_static.c)
131 if(NOT CMAKE_USE_LIBBPF_PACKAGE)
132 target_link_libraries(test_static bcc-static)
133 else()
134- target_link_libraries(test_static bcc-shared-no-libbpf)
135+ target_link_libraries(test_static bcc-shared)
136 endif()
137
138 add_test(NAME c_test_static COMMAND ${TEST_WRAPPER} c_test_static sudo ${CMAKE_CURRENT_BINARY_DIR}/test_static)
139@@ -55,11 +55,11 @@ endif()
140
141 if(LIBBPF_FOUND)
142 add_executable(test_libbcc_no_libbpf ${TEST_LIBBCC_SOURCES})
143- add_dependencies(test_libbcc_no_libbpf bcc-shared-no-libbpf)
144+ add_dependencies(test_libbcc_no_libbpf bcc-shared)
145
146- target_link_libraries(test_libbcc_no_libbpf ${PROJECT_BINARY_DIR}/src/cc/libbcc-no-libbpf.so dl usdt_test_lib ${LIBBPF_LIBRARIES})
147+ target_link_libraries(test_libbcc_no_libbpf ${PROJECT_BINARY_DIR}/src/cc/libbcc.so dl usdt_test_lib ${LIBBPF_LIBRARIES})
148 set_target_properties(test_libbcc_no_libbpf PROPERTIES INSTALL_RPATH ${PROJECT_BINARY_DIR}/src/cc)
149- target_compile_definitions(test_libbcc_no_libbpf PRIVATE -DLIBBCC_NAME=\"libbcc-no-libbpf.so\")
150+ target_compile_definitions(test_libbcc_no_libbpf PRIVATE -DLIBBCC_NAME=\"libbcc.so\")
151
152 add_test(NAME test_libbcc_no_libbpf COMMAND ${TEST_WRAPPER} c_test_all_no_libbpf sudo ${CMAKE_CURRENT_BINARY_DIR}/test_libbcc_no_libbpf)
153 endif()
154--
1552.29.2
156
diff --git a/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0004-cmake-look-for-either-static-or-dynamic-libraries.patch b/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0004-cmake-look-for-either-static-or-dynamic-libraries.patch
new file mode 100644
index 0000000..31bcbcd
--- /dev/null
+++ b/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0004-cmake-look-for-either-static-or-dynamic-libraries.patch
@@ -0,0 +1,69 @@
1From 6b4222cd41b3f5e833307aeff2b10c6b084d3f4f Mon Sep 17 00:00:00 2001
2From: Matteo Croce <mcroce@microsoft.com>
3Date: Wed, 27 Jan 2021 00:26:39 +0100
4Subject: [PATCH] cmake: look for either static or dynamic libraries
5
6On some distro, static libraries are shipped in a separate package.
7Look for either a static or dynamic libbpf, and only fail if neither is found.
8---
9 cmake/FindLibBpf.cmake | 23 ++++++++++++++++-------
10 1 file changed, 16 insertions(+), 7 deletions(-)
11
12diff --git a/cmake/FindLibBpf.cmake b/cmake/FindLibBpf.cmake
13index 75683ae3d..dc10dcee4 100644
14--- a/cmake/FindLibBpf.cmake
15+++ b/cmake/FindLibBpf.cmake
16@@ -28,9 +28,9 @@ find_path (LIBBPF_INCLUDE_DIR
17 /sw/include
18 ENV CPATH)
19
20-find_library (LIBBPF_STATIC_LIBRARIES
21+find_library (LIBBPF_LIBRARIES
22 NAMES
23- libbpf.a
24+ bpf
25 PATHS
26 /usr/lib
27 /usr/local/lib
28@@ -38,10 +38,13 @@ find_library (LIBBPF_STATIC_LIBRARIES
29 /sw/lib
30 ENV LIBRARY_PATH
31 ENV LD_LIBRARY_PATH)
32+if(LIBBPF_LIBRARIES)
33+list(APPEND PATHS LIBBPF_LIBRARIES)
34+endif()
35
36-find_library (LIBBPF_LIBRARIES
37+find_library (LIBBPF_STATIC_LIBRARIES
38 NAMES
39- bpf
40+ libbpf.a
41 PATHS
42 /usr/lib
43 /usr/local/lib
44@@ -49,13 +52,19 @@ find_library (LIBBPF_LIBRARIES
45 /sw/lib
46 ENV LIBRARY_PATH
47 ENV LD_LIBRARY_PATH)
48+if(LIBBPF_STATIC_LIBRARIES)
49+list(APPEND PATHS LIBBPF_STATIC_LIBRARIES)
50+endif()
51
52+if(LIBBPF_STATIC_LIBRARIES OR LIBBPF_LIBRARIES)
53 include (FindPackageHandleStandardArgs)
54
55 # handle the QUIETLY and REQUIRED arguments and set LIBBPF_FOUND to TRUE if all listed variables are TRUE
56 FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibBpf "Please install the libbpf development package"
57- LIBBPF_LIBRARIES
58- LIBBPF_STATIC_LIBRARIES
59+ ${PATHS}
60 LIBBPF_INCLUDE_DIR)
61
62-mark_as_advanced(LIBBPF_INCLUDE_DIR LIBBPF_STATIC_LIBRARIES LIBBPF_LIBRARIES)
63+mark_as_advanced(LIBBPF_INCLUDE_DIR ${PATHS})
64+else()
65+message(Please install the libbpf development package)
66+endif()
67--
682.29.2
69
diff --git a/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc_0.17.0.bb b/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc_0.17.0.bb
index 5366db9..8953fd4 100644
--- a/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc_0.17.0.bb
+++ b/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc_0.17.0.bb
@@ -18,14 +18,22 @@ LUAJIT_powerpc64 = ""
18 18
19RDEPENDS_${PN} += "bash python3 python3-core python3-setuptools xz" 19RDEPENDS_${PN} += "bash python3 python3-core python3-setuptools xz"
20 20
21SRC_URI = "gitsm://github.com/iovisor/bcc \ 21# Don't fetch submodules otherwise we fetch an older, vendored libbpf version
22# We use a dynamic libbpf library instead
23SRC_URI = "git://github.com/iovisor/bcc \
22 file://0001-python-CMakeLists.txt-Remove-check-for-host-etc-debi.patch \ 24 file://0001-python-CMakeLists.txt-Remove-check-for-host-etc-debi.patch \
23 file://0001-tools-trace.py-Fix-failing-to-exit.patch \ 25 file://0001-tools-trace.py-Fix-failing-to-exit.patch \
24 file://0001-CMakeLists.txt-override-the-PY_CMD_ESCAPED.patch \ 26 file://0001-CMakeLists.txt-override-the-PY_CMD_ESCAPED.patch \
25 file://0001-fix-compilation-issues-with-latest-llvm12-trunk.patch \ 27 file://0001-fix-compilation-issues-with-latest-llvm12-trunk.patch \
26 file://0002-fix-compilation-error-with-latest-llvm12-trunk.patch \ 28 file://0002-fix-compilation-error-with-latest-llvm12-trunk.patch \
29 file://0001-cmake-link-dynamically-to-libclang-cpp-if-found-and-.patch \
30 file://0002-cmake-always-link-to-packaged-libbpf-if-CMAKE_USE_LI.patch \
31 file://0003-Remove-libbcc-no-libbpf-shared-library-change-libbcc.patch \
32 file://0004-cmake-look-for-either-static-or-dynamic-libraries.patch \
27 " 33 "
28 34
35DEPENDS += "libbpf"
36
29SRCREV = "ad5b82a5196b222ed2cdc738d8444e8c9546a77f" 37SRCREV = "ad5b82a5196b222ed2cdc738d8444e8c9546a77f"
30 38
31S = "${WORKDIR}/git" 39S = "${WORKDIR}/git"
@@ -39,6 +47,7 @@ EXTRA_OECMAKE = " \
39 -DLLVM_PACKAGE_VERSION=${LLVMVERSION} \ 47 -DLLVM_PACKAGE_VERSION=${LLVMVERSION} \
40 -DPYTHON_CMD=${PYTHON} \ 48 -DPYTHON_CMD=${PYTHON} \
41 -DPYTHON_FLAGS=--install-lib=${PYTHON_SITEPACKAGES_DIR} \ 49 -DPYTHON_FLAGS=--install-lib=${PYTHON_SITEPACKAGES_DIR} \
50 -DCMAKE_USE_LIBBPF_PACKAGE=ON \
42" 51"
43 52
44do_install_append() { 53do_install_append() {