tcp*.bt scripts tried to include glibc headers, which didn't work on nixos because bpftrace tried to call clang-major with some options to get the paths, but we never told it where to find it. Give bpftrace the path directly instead of giving it a path to clang. runqlat.bt doesn't work with glibc headers and requires kernel headers which are no longer extracted, just provide its value. Note the default clang output also had some clang-internal headers, but these seem to be included anyway through libclang API without having to give them here, so we only pass the glibc ones. While here: - also backport another bpftrace patch that made the tcp*.bt tools to actually not require these includes - and add tests that we can include these. Co-authored-by: Arian van Putten <arian.vanputten@gmail.com>
95 lines
3.4 KiB
Diff
95 lines
3.4 KiB
Diff
From c1737d4ab6ab263932caa9e3ac170ebe3e28d404 Mon Sep 17 00:00:00 2001
|
|
From: Dominique Martinet <asmadeus@codewreck.org>
|
|
Date: Fri, 14 Jun 2024 21:56:46 +0900
|
|
Subject: [PATCH] clang_parser system_include_paths: allow overriding at
|
|
compile time
|
|
|
|
While bpftrace depends on libclang it can be installed without a clang
|
|
frontend, so some distributions might want to make these paths fixed as
|
|
they are unlikely to change.
|
|
|
|
In particular, this is necessary to include system libraries as used by
|
|
older versions of tcpaccept.bt (they now no longer require these since
|
|
#3152, but that illustrate this was a recurring problem)
|
|
|
|
(cherry picked from commit 5bf5f86313600b16c8c23e03b31337941cbefdd0)
|
|
---
|
|
CMakeLists.txt | 2 ++
|
|
src/CMakeLists.txt | 4 +++-
|
|
src/clang_parser.cpp | 19 +++++++++++++++----
|
|
3 files changed, 20 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
index cd620d0e56e5..ade33c503efb 100644
|
|
--- a/CMakeLists.txt
|
|
+++ b/CMakeLists.txt
|
|
@@ -21,6 +21,8 @@ set(VENDOR_GTEST OFF CACHE BOOL "Clone gtest from github")
|
|
set(BUILD_FUZZ OFF CACHE BOOL "Build bpftrace for fuzzing")
|
|
set(USE_LIBFUZZER OFF CACHE BOOL "Use libfuzzer for fuzzing")
|
|
set(FUZZ_TARGET "codegen" CACHE STRING "Fuzzing target")
|
|
+set(KERNEL_HEADERS_DIR "" CACHE PATH "Hard-code kernel headers directory")
|
|
+set(SYSTEM_INCLUDE_PATHS "auto" CACHE STRING "Hard-code system include paths (colon separated, the default value \"auto\" queries clang at runtime)")
|
|
|
|
set(ENABLE_SKB_OUTPUT ON CACHE BOOL "Enable skb_output, will include libpcap")
|
|
|
|
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
|
|
index 88f5928c8a75..eadb11207052 100644
|
|
--- a/src/CMakeLists.txt
|
|
+++ b/src/CMakeLists.txt
|
|
@@ -88,11 +88,13 @@ endif()
|
|
|
|
# compile definitions
|
|
|
|
-set(KERNEL_HEADERS_DIR "" CACHE PATH "Hard-code kernel headers directory")
|
|
if (KERNEL_HEADERS_DIR)
|
|
MESSAGE(STATUS "Using KERNEL_HEADERS_DIR=${KERNEL_HEADERS_DIR}")
|
|
target_compile_definitions(runtime PUBLIC KERNEL_HEADERS_DIR="${KERNEL_HEADERS_DIR}")
|
|
endif()
|
|
+if (NOT SYSTEM_INCLUDE_PATHS EQUAL "auto")
|
|
+ MESSAGE(STATUS "Using SYSTEM_INCLUDE_PATHS=${SYSTEM_INCLUDE_PATHS}")
|
|
+endif()
|
|
|
|
execute_process(
|
|
COMMAND git describe --abbrev=4 --dirty --tags
|
|
diff --git a/src/clang_parser.cpp b/src/clang_parser.cpp
|
|
index 8b6689454267..9367e6692eb0 100644
|
|
--- a/src/clang_parser.cpp
|
|
+++ b/src/clang_parser.cpp
|
|
@@ -882,11 +882,9 @@ std::string ClangParser::get_arch_include_path()
|
|
return "/usr/include/" + std::string(utsname.machine) + "-linux-gnu";
|
|
}
|
|
|
|
-std::vector<std::string> ClangParser::system_include_paths()
|
|
+static void query_clang_include_dirs(std::vector<std::string> &result)
|
|
{
|
|
- std::vector<std::string> result;
|
|
- try
|
|
- {
|
|
+ try {
|
|
auto clang = "clang-" + std::to_string(LLVM_VERSION_MAJOR);
|
|
auto cmd = clang + " -Wp,-v -x c -fsyntax-only /dev/null 2>&1";
|
|
auto check = exec_system(cmd.c_str());
|
|
@@ -902,6 +900,19 @@ std::vector<std::string> ClangParser::system_include_paths()
|
|
catch (std::runtime_error &)
|
|
{ // If exec_system fails, just ignore it
|
|
}
|
|
+}
|
|
+
|
|
+std::vector<std::string> ClangParser::system_include_paths()
|
|
+{
|
|
+ std::vector<std::string> result;
|
|
+ std::istringstream lines(SYSTEM_INCLUDE_PATHS);
|
|
+ std::string line;
|
|
+ while (std::getline(lines, line, ':')) {
|
|
+ if (line == "auto")
|
|
+ query_clang_include_dirs(result);
|
|
+ else
|
|
+ result.push_back(trim(line));
|
|
+ }
|
|
|
|
if (result.empty())
|
|
result = { "/usr/local/include", "/usr/include" };
|
|
--
|
|
2.45.2
|
|
|