Compare commits
No commits in common. 'i9c-beta' and 'c9' have entirely different histories.
@ -1,2 +1,2 @@
|
|||||||
dd96c1972002288a6a1105020e16391ff81f3641 SOURCES/bpftrace-0.21.1.tar.gz
|
397cba881b0b7787869c1e51adeb22c169be9168 SOURCES/bpftrace-0.17.0.tar.gz
|
||||||
974ee680e1eb103c415832d69742e194b661da5c SOURCES/cereal-1.3.2.tar.gz
|
974ee680e1eb103c415832d69742e194b661da5c SOURCES/cereal-1.3.2.tar.gz
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
SOURCES/bpftrace-0.21.1.tar.gz
|
SOURCES/bpftrace-0.17.0.tar.gz
|
||||||
SOURCES/cereal-1.3.2.tar.gz
|
SOURCES/cereal-1.3.2.tar.gz
|
||||||
|
@ -0,0 +1,160 @@
|
|||||||
|
From 79d849a3a0462ab0a33cbf208e27e28d05eab213 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Viktor Malik <viktor.malik@gmail.com>
|
||||||
|
Date: Fri, 3 Mar 2023 08:28:54 +0100
|
||||||
|
Subject: [PATCH 1/2] Parse kernel configuration
|
||||||
|
|
||||||
|
In future, it may (and will) be useful to have access to the running
|
||||||
|
kernel configuration, e.g. to add config-specific compilation options to
|
||||||
|
ClangParser.
|
||||||
|
|
||||||
|
This adds and fills a new map BPFtrace::kconfig that maps config options
|
||||||
|
to their values. Both the option name and the value are strings. The
|
||||||
|
configuration is parsed from one of two sources:
|
||||||
|
- /boot/config-$(uname -r)
|
||||||
|
- /proc/config.gz
|
||||||
|
|
||||||
|
For testing purposes, the config filename may be passed through the
|
||||||
|
BPFTRACE_KCONFIG_TEST env variable.
|
||||||
|
---
|
||||||
|
src/bpftrace.h | 1 +
|
||||||
|
src/utils.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
src/utils.h | 12 ++++++++++++
|
||||||
|
tests/utils.cpp | 19 +++++++++++++++++++
|
||||||
|
4 files changed, 82 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/src/bpftrace.h b/src/bpftrace.h
|
||||||
|
index a6a8c00b..94587bff 100644
|
||||||
|
--- a/src/bpftrace.h
|
||||||
|
+++ b/src/bpftrace.h
|
||||||
|
@@ -168,6 +168,7 @@ public:
|
||||||
|
std::map<libbpf::bpf_func_id, location> helper_use_loc_;
|
||||||
|
// mapping traceable functions to modules (or "vmlinux") that they appear in
|
||||||
|
FuncsModulesMap traceable_funcs_;
|
||||||
|
+ KConfig kconfig;
|
||||||
|
std::vector<std::unique_ptr<AttachedProbe>> attached_probes_;
|
||||||
|
|
||||||
|
std::map<std::string, std::unique_ptr<PCAPwriter>> pcap_writers;
|
||||||
|
diff --git a/src/utils.cpp b/src/utils.cpp
|
||||||
|
index 2d9c6695..54c8f054 100644
|
||||||
|
--- a/src/utils.cpp
|
||||||
|
+++ b/src/utils.cpp
|
||||||
|
@@ -28,6 +28,7 @@
|
||||||
|
#include <bcc/bcc_syms.h>
|
||||||
|
#include <bcc/bcc_usdt.h>
|
||||||
|
#include <elf.h>
|
||||||
|
+#include <zlib.h>
|
||||||
|
|
||||||
|
#include <linux/version.h>
|
||||||
|
|
||||||
|
@@ -178,6 +179,55 @@ StdioSilencer::~StdioSilencer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+KConfig::KConfig()
|
||||||
|
+{
|
||||||
|
+ std::vector<std::string> config_locs;
|
||||||
|
+
|
||||||
|
+ // Try to get the config from BPFTRACE_KCONFIG_TEST env
|
||||||
|
+ // If not set, use the set of default locations
|
||||||
|
+ const char *path_env = std::getenv("BPFTRACE_KCONFIG_TEST");
|
||||||
|
+ if (path_env)
|
||||||
|
+ config_locs = { std::string(path_env) };
|
||||||
|
+ else
|
||||||
|
+ {
|
||||||
|
+ struct utsname utsname;
|
||||||
|
+ if (uname(&utsname) < 0)
|
||||||
|
+ return;
|
||||||
|
+ config_locs = {
|
||||||
|
+ "/boot/config-" + std::string(utsname.release),
|
||||||
|
+ "/proc/config.gz",
|
||||||
|
+ };
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ for (auto &path : config_locs)
|
||||||
|
+ {
|
||||||
|
+ // gzopen/gzgets handle both uncompressed and compressed files
|
||||||
|
+ gzFile file = gzopen(path.c_str(), "r");
|
||||||
|
+ if (!file)
|
||||||
|
+ continue;
|
||||||
|
+
|
||||||
|
+ char buf[4096];
|
||||||
|
+ while (gzgets(file, buf, sizeof(buf)))
|
||||||
|
+ {
|
||||||
|
+ std::string option(buf);
|
||||||
|
+ if (option.find("CONFIG_") == 0)
|
||||||
|
+ {
|
||||||
|
+ // trim trailing '\n'
|
||||||
|
+ if (option[option.length() - 1] == '\n')
|
||||||
|
+ option = option.substr(0, option.length() - 1);
|
||||||
|
+
|
||||||
|
+ auto split = option.find("=");
|
||||||
|
+ if (split == std::string::npos)
|
||||||
|
+ continue;
|
||||||
|
+
|
||||||
|
+ config.emplace(option.substr(0, split), option.substr(split + 1));
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ gzclose(file);
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+
|
||||||
|
bool get_uint64_env_var(const std::string &str, uint64_t &dest)
|
||||||
|
{
|
||||||
|
if (const char* env_p = std::getenv(str.c_str()))
|
||||||
|
diff --git a/src/utils.h b/src/utils.h
|
||||||
|
index dccc4504..a76aa161 100644
|
||||||
|
--- a/src/utils.h
|
||||||
|
+++ b/src/utils.h
|
||||||
|
@@ -130,6 +130,18 @@ struct DeprecatedName
|
||||||
|
typedef std::unordered_map<std::string, std::unordered_set<std::string>>
|
||||||
|
FuncsModulesMap;
|
||||||
|
|
||||||
|
+struct KConfig
|
||||||
|
+{
|
||||||
|
+ KConfig();
|
||||||
|
+ bool has_value(const std::string &name, const std::string &value) const
|
||||||
|
+ {
|
||||||
|
+ auto c = config.find(name);
|
||||||
|
+ return c != config.end() && c->second == value;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ std::unordered_map<std::string, std::string> config;
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
static std::vector<DeprecatedName> DEPRECATED_LIST =
|
||||||
|
{
|
||||||
|
};
|
||||||
|
diff --git a/tests/utils.cpp b/tests/utils.cpp
|
||||||
|
index 9ca4ace5..8470745b 100644
|
||||||
|
--- a/tests/utils.cpp
|
||||||
|
+++ b/tests/utils.cpp
|
||||||
|
@@ -222,6 +222,25 @@ TEST(utils, get_cgroup_path_in_hierarchy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+TEST(utils, parse_kconfig)
|
||||||
|
+{
|
||||||
|
+ char path[] = "/tmp/configXXXXXX";
|
||||||
|
+ int fd = mkstemp(path);
|
||||||
|
+ const std::string config = "# Intro comment\n"
|
||||||
|
+ "CONFIG_YES=y\n"
|
||||||
|
+ "CONFIG_MOD=m\n"
|
||||||
|
+ "CONFIG_VAL=42\n"
|
||||||
|
+ "# CONFIG_NO is not set";
|
||||||
|
+ EXPECT_EQ(write(fd, config.c_str(), config.length()), config.length());
|
||||||
|
+ setenv("BPFTRACE_KCONFIG_TEST", path, true);
|
||||||
|
+
|
||||||
|
+ KConfig kconfig;
|
||||||
|
+ ASSERT_TRUE(kconfig.has_value("CONFIG_YES", "y"));
|
||||||
|
+ ASSERT_TRUE(kconfig.has_value("CONFIG_MOD", "m"));
|
||||||
|
+ ASSERT_TRUE(kconfig.has_value("CONFIG_VAL", "42"));
|
||||||
|
+ ASSERT_EQ(kconfig.config.find("CONFIG_NO"), kconfig.config.end());
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
} // namespace utils
|
||||||
|
} // namespace test
|
||||||
|
} // namespace bpftrace
|
||||||
|
--
|
||||||
|
2.39.2
|
||||||
|
|
@ -0,0 +1,103 @@
|
|||||||
|
From 29c5d381cd4d36b5e3ce140193729a5a4b97c31e Mon Sep 17 00:00:00 2001
|
||||||
|
From: Viktor Malik <viktor.malik@gmail.com>
|
||||||
|
Date: Mon, 6 Mar 2023 11:41:27 +0100
|
||||||
|
Subject: [PATCH 2/2] arm64: define the KASAN_SHADOW_SCALE_SHIFT macro
|
||||||
|
|
||||||
|
arm64 defines this macro from Makefile instead of defining it in a
|
||||||
|
header file as is the case for other architectures. Since we're not
|
||||||
|
running make, we need to define the macro manually via CFLAGS.
|
||||||
|
|
||||||
|
The value definition is taken from kernel's arch/arm64/Makefile and it
|
||||||
|
depends on the running kernel configuration.
|
||||||
|
|
||||||
|
This fixes the runqlat.bt tcpdrop.bt, and undump.bt tools on
|
||||||
|
aarch64+debug kernel which previously failed with:
|
||||||
|
|
||||||
|
# /usr/share/bpftrace/tools/runqlat.bt
|
||||||
|
[...]/source/arch/arm64/include/asm/memory.h:300:9: error: use of undeclared identifier 'KASAN_SHADOW_SCALE_SHIFT'
|
||||||
|
[...]
|
||||||
|
---
|
||||||
|
src/main.cpp | 3 ++-
|
||||||
|
src/utils.cpp | 23 ++++++++++++++++++-----
|
||||||
|
src/utils.h | 3 ++-
|
||||||
|
3 files changed, 22 insertions(+), 7 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/main.cpp b/src/main.cpp
|
||||||
|
index b76d1bb3..593c71be 100644
|
||||||
|
--- a/src/main.cpp
|
||||||
|
+++ b/src/main.cpp
|
||||||
|
@@ -370,7 +370,8 @@ static std::optional<struct timespec> get_boottime()
|
||||||
|
kobj = std::get<1>(kdirs);
|
||||||
|
|
||||||
|
if (ksrc != "")
|
||||||
|
- extra_flags = get_kernel_cflags(utsname.machine, ksrc, kobj);
|
||||||
|
+ extra_flags = get_kernel_cflags(
|
||||||
|
+ utsname.machine, ksrc, kobj, bpftrace.kconfig);
|
||||||
|
}
|
||||||
|
extra_flags.push_back("-include");
|
||||||
|
extra_flags.push_back(CLANG_WORKAROUNDS_H);
|
||||||
|
diff --git a/src/utils.cpp b/src/utils.cpp
|
||||||
|
index 54c8f054..c8fd7da1 100644
|
||||||
|
--- a/src/utils.cpp
|
||||||
|
+++ b/src/utils.cpp
|
||||||
|
@@ -227,7 +227,6 @@ KConfig::KConfig()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-
|
||||||
|
bool get_uint64_env_var(const std::string &str, uint64_t &dest)
|
||||||
|
{
|
||||||
|
if (const char* env_p = std::getenv(str.c_str()))
|
||||||
|
@@ -364,10 +363,10 @@ std::vector<int> get_possible_cpus()
|
||||||
|
return read_cpu_range("/sys/devices/system/cpu/possible");
|
||||||
|
}
|
||||||
|
|
||||||
|
-std::vector<std::string> get_kernel_cflags(
|
||||||
|
- const char* uname_machine,
|
||||||
|
- const std::string& ksrc,
|
||||||
|
- const std::string& kobj)
|
||||||
|
+std::vector<std::string> get_kernel_cflags(const char *uname_machine,
|
||||||
|
+ const std::string &ksrc,
|
||||||
|
+ const std::string &kobj,
|
||||||
|
+ const KConfig &kconfig)
|
||||||
|
{
|
||||||
|
std::vector<std::string> cflags;
|
||||||
|
std::string arch = uname_machine;
|
||||||
|
@@ -433,6 +432,20 @@ std::vector<std::string> get_kernel_cflags(
|
||||||
|
cflags.push_back("-D__LINUX_ARM_ARCH__=7");
|
||||||
|
}
|
||||||
|
|
||||||
|
+ if (arch == "arm64")
|
||||||
|
+ {
|
||||||
|
+ // arm64 defines KASAN_SHADOW_SCALE_SHIFT in a Makefile instead of defining
|
||||||
|
+ // it in a header file. Since we're not executing make, we need to set the
|
||||||
|
+ // value manually (values are taken from arch/arm64/Makefile).
|
||||||
|
+ if (kconfig.has_value("CONFIG_KASAN", "y"))
|
||||||
|
+ {
|
||||||
|
+ if (kconfig.has_value("CONFIG_KASAN_SW_TAGS", "y"))
|
||||||
|
+ cflags.push_back("-DKASAN_SHADOW_SCALE_SHIFT=4");
|
||||||
|
+ else
|
||||||
|
+ cflags.push_back("-DKASAN_SHADOW_SCALE_SHIFT=3");
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
return cflags;
|
||||||
|
}
|
||||||
|
|
||||||
|
diff --git a/src/utils.h b/src/utils.h
|
||||||
|
index a76aa161..d4eeac3d 100644
|
||||||
|
--- a/src/utils.h
|
||||||
|
+++ b/src/utils.h
|
||||||
|
@@ -178,7 +178,8 @@ std::tuple<std::string, std::string> get_kernel_dirs(
|
||||||
|
bool unpack_kheaders);
|
||||||
|
std::vector<std::string> get_kernel_cflags(const char *uname_machine,
|
||||||
|
const std::string &ksrc,
|
||||||
|
- const std::string &kobj);
|
||||||
|
+ const std::string &kobj,
|
||||||
|
+ const KConfig &kconfig);
|
||||||
|
std::string get_cgroup_path_in_hierarchy(uint64_t cgroupid,
|
||||||
|
std::string base_path);
|
||||||
|
std::vector<std::pair<std::string, std::string>> get_cgroup_hierarchy_roots();
|
||||||
|
--
|
||||||
|
2.39.2
|
||||||
|
|
@ -0,0 +1,44 @@
|
|||||||
|
From 1632c1fb41d03730a5106696c4fed64cd4a86785 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Khem Raj <raj.khem@gmail.com>
|
||||||
|
Date: Mon, 13 Mar 2023 21:30:27 -0700
|
||||||
|
Subject: [PATCH 1/3] ast: Use std::optional in CodegenLLVM::CodegenLLVM call
|
||||||
|
|
||||||
|
Fixes build with clang-16
|
||||||
|
|
||||||
|
src/ast/passes/codegen_llvm.cpp:63:53: error: use of undeclared identifier 'Optional'; did you mean 'std::optional'?
|
||||||
|
|
||||||
|
Signed-off-by: Khem Raj <raj.khem@gmail.com>
|
||||||
|
---
|
||||||
|
src/ast/passes/codegen_llvm.cpp | 16 +++++++++++-----
|
||||||
|
1 file changed, 11 insertions(+), 5 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/ast/passes/codegen_llvm.cpp b/src/ast/passes/codegen_llvm.cpp
|
||||||
|
index 4e2a18e1..efeb4160 100644
|
||||||
|
--- a/src/ast/passes/codegen_llvm.cpp
|
||||||
|
+++ b/src/ast/passes/codegen_llvm.cpp
|
||||||
|
@@ -56,11 +56,17 @@ CodegenLLVM::CodegenLLVM(Node *root, BPFtrace &bpftrace)
|
||||||
|
throw std::runtime_error(
|
||||||
|
"Could not find bpf llvm target, does your llvm support it?");
|
||||||
|
|
||||||
|
- target_machine_.reset(target->createTargetMachine(LLVMTargetTriple,
|
||||||
|
- "generic",
|
||||||
|
- "",
|
||||||
|
- TargetOptions(),
|
||||||
|
- Optional<Reloc::Model>()));
|
||||||
|
+ target_machine_.reset(
|
||||||
|
+ target->createTargetMachine(LLVMTargetTriple,
|
||||||
|
+ "generic",
|
||||||
|
+ "",
|
||||||
|
+ TargetOptions(),
|
||||||
|
+#if LLVM_VERSION_MAJOR >= 16
|
||||||
|
+ std::optional<Reloc::Model>()
|
||||||
|
+#else
|
||||||
|
+ Optional<Reloc::Model>()
|
||||||
|
+#endif
|
||||||
|
+ ));
|
||||||
|
target_machine_->setOptLevel(llvm::CodeGenOpt::Aggressive);
|
||||||
|
|
||||||
|
module_->setTargetTriple(LLVMTargetTriple);
|
||||||
|
--
|
||||||
|
2.40.1
|
||||||
|
|
@ -0,0 +1,46 @@
|
|||||||
|
From 6a1eb84833fd40e9aa49b610089c6ce11f38ba43 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Viktor Malik <viktor.malik@gmail.com>
|
||||||
|
Date: Wed, 10 May 2023 13:30:59 +0200
|
||||||
|
Subject: [PATCH 1/2] Set cmake policy for CMP0057
|
||||||
|
|
||||||
|
Building with LLVM16 fails with the error:
|
||||||
|
CMake Warning (dev) at /usr/lib/llvm-16/lib/cmake/llvm/LLVM-Config.cmake:230 (if):
|
||||||
|
Policy CMP0057 is not set: Support new IN_LIST if() operator. Run "cmake
|
||||||
|
--help-policy CMP0057" for policy details. Use the cmake_policy command to
|
||||||
|
set the policy and suppress this warning.
|
||||||
|
|
||||||
|
IN_LIST will be interpreted as an operator when the policy is set to NEW.
|
||||||
|
Since the policy is not set the OLD behavior will be used.
|
||||||
|
Call Stack (most recent call first):
|
||||||
|
cmake/clang_libs.cmake:32 (llvm_map_components_to_libnames)
|
||||||
|
src/cc/CMakeLists.txt:126 (include)
|
||||||
|
This warning is for project developers. Use -Wno-dev to suppress it.
|
||||||
|
|
||||||
|
CMake Error at /usr/lib/llvm-16/lib/cmake/llvm/LLVM-Config.cmake:230 (if):
|
||||||
|
if given arguments:
|
||||||
|
|
||||||
|
"engine" "IN_LIST" "link_components"
|
||||||
|
|
||||||
|
Unknown arguments specified
|
||||||
|
|
||||||
|
Set cmake policy for CMP0057 explicitly.
|
||||||
|
---
|
||||||
|
CMakeLists.txt | 2 ++
|
||||||
|
1 file changed, 2 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||||
|
index 0a7914f5..045e9d97 100644
|
||||||
|
--- a/CMakeLists.txt
|
||||||
|
+++ b/CMakeLists.txt
|
||||||
|
@@ -1,6 +1,8 @@
|
||||||
|
cmake_minimum_required(VERSION 3.13.0)
|
||||||
|
project(bpftrace)
|
||||||
|
|
||||||
|
+cmake_policy(SET CMP0057 NEW)
|
||||||
|
+
|
||||||
|
# bpftrace version number components.
|
||||||
|
set(bpftrace_VERSION_MAJOR 0)
|
||||||
|
set(bpftrace_VERSION_MINOR 17)
|
||||||
|
--
|
||||||
|
2.40.1
|
||||||
|
|
@ -0,0 +1,26 @@
|
|||||||
|
From 359a4067c96580cd6d11202ea1ea97a72b4db650 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Khem Raj <raj.khem@gmail.com>
|
||||||
|
Date: Fri, 10 Mar 2023 00:08:27 -0800
|
||||||
|
Subject: [PATCH 2/2] cmake: Raise max llvm major version to 16
|
||||||
|
|
||||||
|
Signed-off-by: Khem Raj <raj.khem@gmail.com>
|
||||||
|
---
|
||||||
|
CMakeLists.txt | 2 +-
|
||||||
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||||
|
index 045e9d97..88867b5b 100644
|
||||||
|
--- a/CMakeLists.txt
|
||||||
|
+++ b/CMakeLists.txt
|
||||||
|
@@ -167,7 +167,7 @@ else()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(MIN_LLVM_MAJOR 6)
|
||||||
|
- set(MAX_LLVM_MAJOR 15)
|
||||||
|
+ set(MAX_LLVM_MAJOR 16)
|
||||||
|
|
||||||
|
if((${LLVM_VERSION_MAJOR} VERSION_LESS ${MIN_LLVM_MAJOR}) OR (${LLVM_VERSION_MAJOR} VERSION_GREATER ${MAX_LLVM_MAJOR}))
|
||||||
|
message(SEND_ERROR "Unsupported LLVM version found via ${LLVM_INCLUDE_DIRS}: ${LLVM_VERSION_MAJOR}")
|
||||||
|
--
|
||||||
|
2.40.1
|
||||||
|
|
Loading…
Reference in new issue