Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up unnecessary symbol existence checks #2370

Merged
merged 15 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 0 additions & 78 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,6 @@ endif()
if(POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif()
if(STATIC_BPF_BCC)
set(CMAKE_REQUIRED_LIBRARIES bcc bcc_bpf bpf elf z)
else()
set(CMAKE_REQUIRED_LIBRARIES ${LIBBCC_LIBRARIES} ${LIBBPF_LIBRARIES})
endif(STATIC_BPF_BCC)
get_filename_component(LIBBCC_LIBDIR ${LIBBCC_LIBRARIES} DIRECTORY)
set(CMAKE_REQUIRED_LINK_OPTIONS -L${LIBBCC_LIBDIR})

check_symbol_exists(bcc_elf_foreach_sym "${LIBBCC_INCLUDE_DIRS}/bcc/bcc_elf.h" HAVE_BCC_ELF_FOREACH_SYM)
check_symbol_exists(bpf_attach_kfunc "${LIBBCC_INCLUDE_DIRS}/bcc/libbpf.h" HAVE_BCC_KFUNC)
check_symbol_exists(bcc_usdt_addsem_probe "${LIBBCC_INCLUDE_DIRS}/bcc/bcc_usdt.h" HAVE_BCC_USDT_ADDSEM)
check_symbol_exists(bcc_procutils_which_so "${LIBBCC_INCLUDE_DIRS}/bcc/bcc_proc.h" HAVE_BCC_WHICH_SO)

set(CMAKE_REQUIRED_LIBRARIES)
set(CMAKE_REQUIRED_LINK_OPTIONS)

if(${LIBBFD_FOUND} AND ${LIBOPCODES_FOUND})
set(HAVE_BFD_DISASM TRUE)
Expand Down Expand Up @@ -215,38 +200,6 @@ if(HAVE_NAME_TO_HANDLE_AT)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_NAME_TO_HANDLE_AT=1)
endif(HAVE_NAME_TO_HANDLE_AT)

if(HAVE_BCC_ELF_FOREACH_SYM)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_BCC_ELF_FOREACH_SYM)
endif(HAVE_BCC_ELF_FOREACH_SYM)

if(HAVE_BCC_USDT_ADDSEM)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_BCC_USDT_ADDSEM)
endif(HAVE_BCC_USDT_ADDSEM)

if(HAVE_BCC_WHICH_SO)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_BCC_WHICH_SO)
endif(HAVE_BCC_WHICH_SO)

if(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
endif(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)

if(LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
endif(LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)

if (HAVE_LIBBPF_MAP_BATCH)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_MAP_BATCH)
endif()

if (HAVE_LIBBPF_LINK_CREATE)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_LINK_CREATE)
endif()

if (HAVE_LIBBPF_PROG_TEST_RUN_OPTS)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_PROG_TEST_RUN_OPTS)
endif()

if(HAVE_BFD_DISASM)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_BFD_DISASM)
if(LIBBFD_DISASM_FOUR_ARGS_SIGNATURE)
Expand All @@ -257,37 +210,6 @@ if(HAVE_BFD_DISASM)
endif(LIBBFD_INIT_DISASM_INFO_FOUR_ARGS_SIGNATURE)
endif(HAVE_BFD_DISASM)

if (LIBBPF_BTF_DUMP_FOUND)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_BTF_DUMP)
if (HAVE_LIBBPF_BTF_DUMP_EMIT_TYPE_DECL)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_BTF_DUMP_EMIT_TYPE_DECL)
endif()
endif(LIBBPF_BTF_DUMP_FOUND)

if (HAVE_LIBBPF_BPF_PROG_LOAD)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_BPF_PROG_LOAD)
endif(HAVE_LIBBPF_BPF_PROG_LOAD)

if (HAVE_LIBBPF_BPF_MAP_CREATE)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_BPF_MAP_CREATE)
endif(HAVE_LIBBPF_BPF_MAP_CREATE)

if (HAVE_LIBBPF_BTF_TYPE_CNT)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_BTF_TYPE_CNT)
endif(HAVE_LIBBPF_BTF_TYPE_CNT)

if (HAVE_LIBBPF_BTF_DUMP_NEW_V0_6_0)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_BTF_DUMP_NEW_V0_6_0)
endif(HAVE_LIBBPF_BTF_DUMP_NEW_V0_6_0)

if (HAVE_LIBBPF_BTF_DUMP_NEW_DEPRECATED)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_BTF_DUMP_NEW_DEPRECATED)
endif(HAVE_LIBBPF_BTF_DUMP_NEW_DEPRECATED)

if (HAVE_LIBBPF_KPROBE_MULTI)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_KPROBE_MULTI)
endif(HAVE_LIBBPF_KPROBE_MULTI)

if (LIBDW_FOUND)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBDW)
endif ()
Expand Down
21 changes: 0 additions & 21 deletions cmake/FindLibBcc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
# LIBBCC_DEFINITIONS - Compiler switches required for using libbcc
# LIBBCC_BPF_LIBRARIES - libbcc runtime library
# LIBBCC_LOADER_LIBRARY_STATIC - libbcc helper static library (for static compilation)
# LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE
# LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE
# LIBBCC_BPF_CONTAINS_RUNTIME - whether libbcc_bpf.so has been expanded to contain everything !llvm & !clang
#
# Note that the shared libbcc binary has libbpf and bcc_loader already compiled in but
Expand Down Expand Up @@ -109,25 +107,6 @@ endif()

INCLUDE(CheckCXXSourceCompiles)
SET(CMAKE_REQUIRED_INCLUDES ${LIBBCC_INCLUDE_DIRS})
CHECK_CXX_SOURCE_COMPILES("
#include <bcc/libbpf.h>

int main(void) {
bpf_attach_kprobe(0, BPF_PROBE_ENTRY, \"\", \"\", 0, 0);
return 0;
}
" LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)

CHECK_CXX_SOURCE_COMPILES("
#include <bcc/libbpf.h>

int main(void) {
bpf_attach_uprobe(0, BPF_PROBE_ENTRY, \"\", \"\", 0, 0, 0);
return 0;
}
" LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
SET(CMAKE_REQUIRED_INCLUDES)

SET(CMAKE_REQUIRED_LIBRARIES ${LIBBCC_BPF_LIBRARIES})
include(CheckSymbolExists)
check_symbol_exists(bcc_usdt_foreach ${LIBBCC_INCLUDE_DIRS}/bcc/bcc_usdt.h LIBBCC_BPF_CONTAINS_RUNTIME)
Expand Down
69 changes: 0 additions & 69 deletions cmake/FindLibBpf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,72 +56,3 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibBpf ${LIBBPF_ERROR_MESSAGE}
LIBBPF_INCLUDE_DIRS)

mark_as_advanced(LIBBPF_INCLUDE_DIRS LIBBPF_LIBRARIES)

# We need btf_dump support, set LIBBPF_BTF_DUMP_FOUND
# when it's found.
if (KERNEL_INCLUDE_DIRS)
set(INCLUDE_KERNEL -isystem ${KERNEL_INCLUDE_DIRS})
endif ()
include(CheckSymbolExists)
# adding also elf for static build check
SET(CMAKE_REQUIRED_LIBRARIES ${LIBBPF_LIBRARIES} elf z)
# libbpf quirk, needs upstream fix
SET(CMAKE_REQUIRED_DEFINITIONS -include stdbool.h -isystem "${LIBBPF_INCLUDE_DIRS}" ${INCLUDE_KERNEL})
check_symbol_exists(btf_dump__new "${LIBBPF_INCLUDE_DIRS}/bpf/btf.h" HAVE_BTF_DUMP)
if (HAVE_BTF_DUMP)
set(LIBBPF_BTF_DUMP_FOUND TRUE)
endif ()
check_symbol_exists(btf_dump__emit_type_decl "${LIBBPF_INCLUDE_DIRS}/bpf/btf.h" HAVE_LIBBPF_BTF_DUMP_EMIT_TYPE_DECL)

check_symbol_exists(bpf_prog_load "${LIBBPF_INCLUDE_DIRS}/bpf/bpf.h" HAVE_LIBBPF_BPF_PROG_LOAD)
check_symbol_exists(bpf_map_create "${LIBBPF_INCLUDE_DIRS}/bpf/bpf.h" HAVE_LIBBPF_BPF_MAP_CREATE)
check_symbol_exists(bpf_map_lookup_batch "${LIBBPF_INCLUDE_DIRS}/bpf/bpf.h" HAVE_LIBBPF_MAP_BATCH)
check_symbol_exists(bpf_link_create "${LIBBPF_INCLUDE_DIRS}/bpf/bpf.h" HAVE_LIBBPF_LINK_CREATE)
check_symbol_exists(bpf_prog_test_run_opts "${LIBBPF_INCLUDE_DIRS}/bpf/bpf.h" HAVE_LIBBPF_PROG_TEST_RUN_OPTS)
SET(CMAKE_REQUIRED_DEFINITIONS)
SET(CMAKE_REQUIRED_LIBRARIES)

INCLUDE(CheckCXXSourceCompiles)
SET(CMAKE_REQUIRED_INCLUDES ${LIBBPF_INCLUDE_DIRS})
SET(CMAKE_REQUIRED_LIBRARIES ${LIBBPF_LIBRARIES} elf z)
CHECK_CXX_SOURCE_COMPILES("
#include <bpf/btf.h>

int main(void) {
btf__type_cnt(NULL);
return 0;
}
" HAVE_LIBBPF_BTF_TYPE_CNT)

CHECK_CXX_SOURCE_COMPILES("
#include <bpf/btf.h>

int main(void) {
const struct btf_dump_opts *opts = (const struct btf_dump_opts*) 1;

btf_dump__new(NULL, NULL, NULL, opts);
return 0;
}
" HAVE_LIBBPF_BTF_DUMP_NEW_V0_6_0)

CHECK_CXX_SOURCE_COMPILES("
#include <bpf/btf.h>

int main(void) {
btf_dump__new_deprecated(NULL, NULL, NULL, NULL);
return 0;
}
" HAVE_LIBBPF_BTF_DUMP_NEW_DEPRECATED)

CHECK_CXX_SOURCE_COMPILES("
#include <bpf/bpf.h>

int main(void) {
DECLARE_LIBBPF_OPTS(bpf_link_create_opts, opts);

opts.kprobe_multi.syms = NULL;
return 0;
}
" HAVE_LIBBPF_KPROBE_MULTI)
SET(CMAKE_REQUIRED_INCLUDES)
SET(CMAKE_REQUIRED_LIBRARIES)
5 changes: 1 addition & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,9 @@ if(STATIC_LINKING)
endif(STATIC_LINKING)


target_link_libraries(runtime ${LIBBPF_LIBRARIES})
target_link_libraries(libbpftrace parser resources runtime aot ast arch cxxdemangler_llvm)

if (LIBBPF_BTF_DUMP_FOUND)
target_link_libraries(runtime ${LIBBPF_LIBRARIES})
endif(LIBBPF_BTF_DUMP_FOUND)

if(LIBPCAP_FOUND)
target_link_libraries(libbpftrace ${LIBPCAP_LIBRARIES})
endif(LIBPCAP_FOUND)
Expand Down
6 changes: 0 additions & 6 deletions src/ast/attachpoint_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
#include <string>
#include <unordered_map>
#include <vector>

#ifdef HAVE_BCC_WHICH_SO
#include <bcc/bcc_proc.h>
#endif

#include "ast/int_parser.h"
#include "log.h"
#include "types.h"
Expand Down Expand Up @@ -388,7 +384,6 @@ AttachPointParser::State AttachPointParser::uprobe_parser(bool allow_offset,

ap_->target = "";

#ifdef HAVE_BCC_WHICH_SO
if (!has_wildcard(parts_[1]) && parts_[1].find("lib") == 0)
{
// Automatic resolution of shared library paths.
Expand All @@ -400,7 +395,6 @@ AttachPointParser::State AttachPointParser::uprobe_parser(bool allow_offset,
if (lib_path)
ap_->target = lib_path;
}
#endif

if (ap_->target.empty())
{
Expand Down
Loading