Rebase to bpftrace 0.12.1

Resolves: rhbz#1965383
This commit is contained in:
Jerome Marchand 2021-06-03 13:03:03 +02:00
parent 704d2cae17
commit a139ab5017
8 changed files with 66 additions and 583 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@
/bpftrace-0.9.4.tar.gz /bpftrace-0.9.4.tar.gz
/bpftrace-0.10.0.tar.gz /bpftrace-0.10.0.tar.gz
/bpftrace-0.11.0.tar.gz /bpftrace-0.11.0.tar.gz
/bpftrace-0.12.1.tar.gz

View File

@ -1,150 +0,0 @@
From 62a2d7f199996ef8cb16e08854edb44445db8d67 Mon Sep 17 00:00:00 2001
From: Daniel Xu <dxu@dxuuu.xyz>
Date: Wed, 14 Oct 2020 17:09:46 -0700
Subject: [PATCH 2/2] Detect 7 arg bpf_attach_uprobe() API
The 7th arg allows us to specify the usdt semaphore location.
---
cmake/FindLibBcc.cmake | 11 +++++++++++
src/CMakeLists.txt | 3 +++
src/attached_probe.cpp | 42 ++++++++++++++++++++++++++++++++++--------
src/main.cpp | 6 ++++++
tests/CMakeLists.txt | 3 +++
5 files changed, 57 insertions(+), 8 deletions(-)
diff --git a/cmake/FindLibBcc.cmake b/cmake/FindLibBcc.cmake
index ec21627..76ab3b3 100644
--- a/cmake/FindLibBcc.cmake
+++ b/cmake/FindLibBcc.cmake
@@ -7,6 +7,8 @@
# LIBBCC_DEFINITIONS - Compiler switches required for using libbcc
# LIBBCC_BPF_LIBRARY_STATIC - libbpf static library (for static compilation)
# LIBBCC_LOADER_LIBRARY_STATIC - libbcc helper static library (for static compilation)
+# LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE
+# LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE
#
# Note that the shared libbcc binary has libbpf and bcc_loader already compiled in but
# the static doesn't. So when creating a static build those have to be included too.
@@ -92,5 +94,14 @@ int main(void) {
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_LIBRARIES)
endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 35d2400..b4eee17 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -82,6 +82,9 @@ endif(HAVE_BFD_DISASM)
if(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
target_compile_definitions(bpftrace PRIVATE LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
endif(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
+if(LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
+ target_compile_definitions(bpftrace PRIVATE LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
+endif(LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
if (ALLOW_UNSAFE_PROBE)
target_compile_definitions(bpftrace PRIVATE HAVE_UNSAFE_PROBE)
diff --git a/src/attached_probe.cpp b/src/attached_probe.cpp
index afad9ed..811226a 100644
--- a/src/attached_probe.cpp
+++ b/src/attached_probe.cpp
@@ -790,12 +790,23 @@ void AttachedProbe::attach_uprobe(bool safe_mode)
{
resolve_offset_uprobe(safe_mode);
- int perf_event_fd = bpf_attach_uprobe(progfd_,
- attachtype(probe_.type),
- eventname().c_str(),
- probe_.path.c_str(),
- offset_,
- probe_.pid);
+ int perf_event_fd =
+#ifdef LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE
+ bpf_attach_uprobe(progfd_,
+ attachtype(probe_.type),
+ eventname().c_str(),
+ probe_.path.c_str(),
+ offset_,
+ probe_.pid,
+ 0);
+#else
+ bpf_attach_uprobe(progfd_,
+ attachtype(probe_.type),
+ eventname().c_str(),
+ probe_.path.c_str(),
+ offset_,
+ probe_.pid);
+#endif // LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE
if (perf_event_fd < 0)
throw std::runtime_error("Error attaching probe: " + probe_.name);
@@ -904,8 +915,23 @@ void AttachedProbe::attach_usdt(int pid)
offset_ = resolve_offset(probe_.path, probe_.attach_point, probe_.loc);
- int perf_event_fd = bpf_attach_uprobe(progfd_, attachtype(probe_.type),
- eventname().c_str(), probe_.path.c_str(), offset_, pid == 0 ? -1 : pid);
+ int perf_event_fd =
+#ifdef LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE
+ bpf_attach_uprobe(progfd_,
+ attachtype(probe_.type),
+ eventname().c_str(),
+ probe_.path.c_str(),
+ offset_,
+ pid == 0 ? -1 : pid,
+ 0);
+#else
+ bpf_attach_uprobe(progfd_,
+ attachtype(probe_.type),
+ eventname().c_str(),
+ probe_.path.c_str(),
+ offset_,
+ pid == 0 ? -1 : pid);
+#endif // LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE
if (perf_event_fd < 0)
{
diff --git a/src/main.cpp b/src/main.cpp
index 71a06c1..bf76da8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -155,6 +155,12 @@ static int info()
<< "yes" << std::endl;
#else
<< "no" << std::endl;
+#endif
+ std::cerr << " bcc bpf_attach_uprobe refcount: "
+#ifdef LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE
+ << "yes" << std::endl;
+#else
+ << "no" << std::endl;
#endif
std::cerr << " libbpf: "
#ifdef HAVE_LIBBPF
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index ed0ccf8..d94868a 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -103,6 +103,9 @@ endif(HAVE_BFD_DISASM)
if(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
target_compile_definitions(bpftrace_test PRIVATE LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
endif(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
+if(LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
+ target_compile_definitions(bpftrace_test PRIVATE LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
+endif(LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
target_link_libraries(bpftrace_test arch ast parser resources)
--
2.25.4

View File

@ -1,129 +0,0 @@
From 00687a3538755b60c2b205963c8ae49b4681e642 Mon Sep 17 00:00:00 2001
From: Viktor Malik <viktor.malik@gmail.com>
Date: Wed, 12 Aug 2020 09:45:29 +0200
Subject: [PATCH 1/2] Feature-detect bpf_attach_kprobe signature
The function has 6 parameters in current versions of BCC and 5
parameters in older versions.
This is detected in CMake using CHECK_CXX_SOURCE_COMPILES. For static
compilation, we also need to retrieve and link static libbpf, libelf,
and libz. This may cause libbpf, libelf and libz to be searched for
twice, but it should be fine since CMake caches results.
Fixes iovisor#1027.
---
cmake/FindLibBcc.cmake | 24 ++++++++++++++++++++++++
src/CMakeLists.txt | 3 +++
src/attached_probe.cpp | 31 ++++++++++++++-----------------
tests/CMakeLists.txt | 3 +++
4 files changed, 44 insertions(+), 17 deletions(-)
diff --git a/cmake/FindLibBcc.cmake b/cmake/FindLibBcc.cmake
index 9d30b04..ec21627 100644
--- a/cmake/FindLibBcc.cmake
+++ b/cmake/FindLibBcc.cmake
@@ -70,3 +70,27 @@ include (FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibBcc "Please install the bcc library package, which is required. Depending on your distro, it may be called bpfcclib or bcclib (Ubuntu), bcc-devel (Fedora), or something else. If unavailable, install bcc from source (github.com/iovisor/bcc)."
LIBBCC_LIBRARIES
LIBBCC_INCLUDE_DIRS)
+
+# Check bpf_attach_kprobe signature
+if(${LIBBCC_FOUND})
+if(STATIC_LINKING)
+ # libbcc.a is not statically linked with libbpf.a, libelf.a, and libz.a.
+ # If we do a static bpftrace build, we must link them in.
+ find_package(LibBpf)
+ find_package(LibElf)
+ find_package(LibZ)
+ SET(CMAKE_REQUIRED_LIBRARIES ${LIBBCC_BPF_LIBRARY_STATIC} ${LIBBPF_LIBRARIES} ${LIBELF_LIBRARIES} ${LIBZ_LIBRARIES})
+else()
+ SET(CMAKE_REQUIRED_LIBRARIES ${LIBBCC_LIBRARIES})
+endif()
+INCLUDE(CheckCXXSourceCompiles)
+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)
+SET(CMAKE_REQUIRED_LIBRARIES)
+endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 487fa9b..35d2400 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -79,6 +79,9 @@ if(HAVE_BFD_DISASM)
target_link_libraries(bpftrace ${LIBOPCODES_LIBRARIES})
endif(STATIC_LINKING)
endif(HAVE_BFD_DISASM)
+if(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
+ target_compile_definitions(bpftrace PRIVATE LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
+endif(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
if (ALLOW_UNSAFE_PROBE)
target_compile_definitions(bpftrace PRIVATE HAVE_UNSAFE_PROBE)
diff --git a/src/attached_probe.cpp b/src/attached_probe.cpp
index 587a115..afad9ed 100644
--- a/src/attached_probe.cpp
+++ b/src/attached_probe.cpp
@@ -754,26 +754,23 @@ void AttachedProbe::load_prog()
}
}
-// XXX(mmarchini): bcc changed the signature of bpf_attach_kprobe, adding a new
-// int parameter at the end. Since there's no reliable way to feature-detect
-// this, we create a function pointer with the long signature and cast
-// bpf_attach_kprobe to this function pointer. If we're on an older bcc
-// version, bpf_attach_kprobe call will be augmented with an extra register
-// being used for the last parameter, even though this register won't be used
-// inside the function. Since the register won't be used this is kinda safe,
-// although not ideal.
-typedef int (*attach_probe_wrapper_signature)(int, enum bpf_probe_attach_type, const char*, const char*, uint64_t, int);
-
void AttachedProbe::attach_kprobe(bool safe_mode)
{
resolve_offset_kprobe(safe_mode);
- int perf_event_fd = cast_signature<attach_probe_wrapper_signature>(
- &bpf_attach_kprobe)(progfd_,
- attachtype(probe_.type),
- eventname().c_str(),
- probe_.attach_point.c_str(),
- offset_,
- 0);
+#ifdef LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE
+ int perf_event_fd = bpf_attach_kprobe(progfd_,
+ attachtype(probe_.type),
+ eventname().c_str(),
+ probe_.attach_point.c_str(),
+ offset_,
+ 0);
+#else
+ int perf_event_fd = bpf_attach_kprobe(progfd_,
+ attachtype(probe_.type),
+ eventname().c_str(),
+ probe_.attach_point.c_str(),
+ offset_);
+#endif
if (perf_event_fd < 0) {
if (probe_.orig_name != probe_.name) {
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 4104a57..ed0ccf8 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -100,6 +100,9 @@ if(HAVE_BFD_DISASM)
target_link_libraries(bpftrace_test ${LIBOPCODES_LIBRARIES})
endif(STATIC_LINKING)
endif(HAVE_BFD_DISASM)
+if(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
+ target_compile_definitions(bpftrace_test PRIVATE LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
+endif(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
target_link_libraries(bpftrace_test arch ast parser resources)
--
2.25.4

View File

@ -1,282 +0,0 @@
From d0f1159fafc52a31713d98d336d10e423e7eb5a0 Mon Sep 17 00:00:00 2001
From: Ovidiu Panait <ovidiu.panait@windriver.com>
Date: Thu, 6 Aug 2020 10:34:23 +0300
Subject: [PATCH] irbuilderbpf.cpp, bpforc.h: Fix compilation with LLVM 11
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Fixes: #1384
Fix the following build errors when compiling with LLVM 11:
#1
----
/llvm/include/llvm/ExecutionEngine/Orc/Legacy.h:118:35: error: no match for call to (bpftrace::BpfOrc::BpfOrc(llvm::TargetMachine*)::<lambda(const string&)>) (llvm::StringRef)
118 | if (JITSymbol Sym = FindSymbol(*S)) {
| ~~~~~~~~~~^~~~
/llvm/include/llvm/ExecutionEngine/Orc/Legacy.h:118:35: note: candidate: llvm::JITSymbol (*)(const string&) {aka llvm::JITSymbol (*)(const std::__cxx11::basic_string<char>&)} <conversion>
/llvm/include/llvm/ExecutionEngine/Orc/Legacy.h:118:35: note: candidate expects 2 arguments, 2 provided
In file included from /work/src/github.com/iovisor/bpftrace/src/ast/codegen_llvm.cpp:5:
/work/src/github.com/iovisor/bpftrace/src/bpforc.h:99:13: note: candidate: bpftrace::BpfOrc::BpfOrc(llvm::TargetMachine*)::<lambda(const string&)>
99 | [](const std::string &Name __attribute__((unused))) -> JITSymbol {
| ^
/work/src/github.com/iovisor/bpftrace/src/bpforc.h:99:13: note: no known conversion for argument 1 from llvm::StringRef to const string& {aka const std::__cxx11::basic_string<char>&}
In file included from /llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h:23,
#2
----
| /src/ast/irbuilderbpf.cpp: In member function 'llvm::CallInst* bpftrace::ast::IRBuilderBPF::createMapLookup(int, llvm::AllocaInst*)':
| /src/ast/irbuilderbpf.cpp:230:65: error: no matching function for call to 'bpftrace::ast::IRBuilderBPF::CreateCall(llvm::Constant*&, <brace-enclosed initializer list>, const char [12])'
| 230 | return CreateCall(lookup_func, { map_ptr, key }, "lookup_elem");
| | ^
| In file included from /src/ast/irbuilderbpf.h:9,
| from /src/ast/async_event_types.h:3,
| from /src/ast/irbuilderbpf.cpp:5:
| /usr/include/llvm/IR/IRBuilder.h:2324:13: note: candidate: 'llvm::CallInst* llvm::IRBuilderBase::CreateCall(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, const llvm::Twine&, llvm::MDNode*)'
| 2324 | CallInst *CreateCall(FunctionType *FTy, Value *Callee,
| | ^~~~~~~~~~
| /usr/include/llvm/IR/IRBuilder.h:2324:38: note: no known conversion for argument 1 from 'llvm::Constant*' to 'llvm::FunctionType*'
| 2324 | CallInst *CreateCall(FunctionType *FTy, Value *Callee,
| | ~~~~~~~~~~~~~~^~~
The CreateCall part is based on the llvm 11 fix from bcc:
https://github.com/iovisor/bcc/commit/45e63f2b316cdce2d8cc925f6f14a8726ade9ff6
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
---
src/ast/irbuilderbpf.cpp | 55 ++++++++++++++++++++++++++--------------
src/ast/irbuilderbpf.h | 1 +
src/bpforc.h | 6 +++++
3 files changed, 43 insertions(+), 19 deletions(-)
diff --git a/src/ast/irbuilderbpf.cpp b/src/ast/irbuilderbpf.cpp
index 8ae055e..4498e0f 100644
--- a/src/ast/irbuilderbpf.cpp
+++ b/src/ast/irbuilderbpf.cpp
@@ -201,10 +201,25 @@ llvm::Type *IRBuilderBPF::GetType(const SizedType &stype)
return ty;
}
+CallInst *IRBuilderBPF::createCall(Value *callee,
+ ArrayRef<Value *> args,
+ const Twine &Name)
+{
+#if LLVM_VERSION_MAJOR >= 11
+ auto *calleePtrType = cast<PointerType>(callee->getType());
+ auto *calleeType = cast<FunctionType>(calleePtrType->getElementType());
+ return CreateCall(calleeType, callee, args, Name);
+#else
+ return CreateCall(callee, args, Name);
+#endif
+}
+
CallInst *IRBuilderBPF::CreateBpfPseudoCall(int mapfd)
{
Function *pseudo_func = module_.getFunction("llvm.bpf.pseudo");
- return CreateCall(pseudo_func, {getInt64(BPF_PSEUDO_MAP_FD), getInt64(mapfd)}, "pseudo");
+ return createCall(pseudo_func,
+ { getInt64(BPF_PSEUDO_MAP_FD), getInt64(mapfd) },
+ "pseudo");
}
CallInst *IRBuilderBPF::CreateBpfPseudoCall(Map &map)
@@ -227,7 +242,7 @@ CallInst *IRBuilderBPF::createMapLookup(int mapfd, AllocaInst *key)
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_map_lookup_elem),
lookup_func_ptr_type);
- return CreateCall(lookup_func, { map_ptr, key }, "lookup_elem");
+ return createCall(lookup_func, { map_ptr, key }, "lookup_elem");
}
CallInst *IRBuilderBPF::CreateGetJoinMap(Value *ctx, const location &loc)
@@ -325,7 +340,7 @@ void IRBuilderBPF::CreateMapUpdateElem(Value *ctx,
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_map_update_elem),
update_func_ptr_type);
- CallInst *call = CreateCall(update_func,
+ CallInst *call = createCall(update_func,
{ map_ptr, key, val, flags },
"update_elem");
CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_map_update_elem, loc);
@@ -349,7 +364,7 @@ void IRBuilderBPF::CreateMapDeleteElem(Value *ctx,
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_map_delete_elem),
delete_func_ptr_type);
- CallInst *call = CreateCall(delete_func, { map_ptr, key }, "delete_elem");
+ CallInst *call = createCall(delete_func, { map_ptr, key }, "delete_elem");
CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_map_delete_elem, loc);
}
@@ -378,7 +393,7 @@ void IRBuilderBPF::CreateProbeRead(Value *ctx,
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_probe_read),
proberead_func_ptr_type);
- CallInst *call = CreateCall(proberead_func, { dst, size, src }, "probe_read");
+ CallInst *call = createCall(proberead_func, { dst, size, src }, "probe_read");
CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_probe_read, loc);
}
@@ -413,7 +428,7 @@ CallInst *IRBuilderBPF::CreateProbeReadStr(Value *ctx,
{
assert(ctx && ctx->getType() == getInt8PtrTy());
Constant *fn = createProbeReadStrFn(dst->getType(), src->getType());
- CallInst *call = CreateCall(fn,
+ CallInst *call = createCall(fn,
{ dst, getInt32(size), src },
"probe_read_str");
CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_probe_read_str, loc);
@@ -434,7 +449,7 @@ CallInst *IRBuilderBPF::CreateProbeReadStr(Value *ctx,
auto *size_i32 = CreateIntCast(size, getInt32Ty(), false);
Constant *fn = createProbeReadStrFn(dst->getType(), src->getType());
- CallInst *call = CreateCall(fn, { dst, size_i32, src }, "probe_read_str");
+ CallInst *call = createCall(fn, { dst, size_i32, src }, "probe_read_str");
CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_probe_read_str, loc);
return call;
}
@@ -717,7 +732,7 @@ CallInst *IRBuilderBPF::CreateGetNs()
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_ktime_get_ns),
gettime_func_ptr_type);
- return CreateCall(gettime_func, {}, "get_ns");
+ return createCall(gettime_func, {}, "get_ns");
}
CallInst *IRBuilderBPF::CreateGetPidTgid()
@@ -730,7 +745,7 @@ CallInst *IRBuilderBPF::CreateGetPidTgid()
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_get_current_pid_tgid),
getpidtgid_func_ptr_type);
- return CreateCall(getpidtgid_func, {}, "get_pid_tgid");
+ return createCall(getpidtgid_func, {}, "get_pid_tgid");
}
CallInst *IRBuilderBPF::CreateGetCurrentCgroupId()
@@ -744,7 +759,7 @@ CallInst *IRBuilderBPF::CreateGetCurrentCgroupId()
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_get_current_cgroup_id),
getcgroupid_func_ptr_type);
- return CreateCall(getcgroupid_func, {}, "get_cgroup_id");
+ return createCall(getcgroupid_func, {}, "get_cgroup_id");
}
CallInst *IRBuilderBPF::CreateGetUidGid()
@@ -757,7 +772,7 @@ CallInst *IRBuilderBPF::CreateGetUidGid()
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_get_current_uid_gid),
getuidgid_func_ptr_type);
- return CreateCall(getuidgid_func, {}, "get_uid_gid");
+ return createCall(getuidgid_func, {}, "get_uid_gid");
}
CallInst *IRBuilderBPF::CreateGetCpuId()
@@ -770,7 +785,7 @@ CallInst *IRBuilderBPF::CreateGetCpuId()
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_get_smp_processor_id),
getcpuid_func_ptr_type);
- return CreateCall(getcpuid_func, {}, "get_cpu_id");
+ return createCall(getcpuid_func, {}, "get_cpu_id");
}
CallInst *IRBuilderBPF::CreateGetCurrentTask()
@@ -783,7 +798,7 @@ CallInst *IRBuilderBPF::CreateGetCurrentTask()
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_get_current_task),
getcurtask_func_ptr_type);
- return CreateCall(getcurtask_func, {}, "get_cur_task");
+ return createCall(getcurtask_func, {}, "get_cur_task");
}
CallInst *IRBuilderBPF::CreateGetRandom()
@@ -796,7 +811,7 @@ CallInst *IRBuilderBPF::CreateGetRandom()
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_get_prandom_u32),
getrandom_func_ptr_type);
- return CreateCall(getrandom_func, {}, "get_random");
+ return createCall(getrandom_func, {}, "get_random");
}
CallInst *IRBuilderBPF::CreateGetStackId(Value *ctx,
@@ -826,7 +841,7 @@ CallInst *IRBuilderBPF::CreateGetStackId(Value *ctx,
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_get_stackid),
getstackid_func_ptr_type);
- CallInst *call = CreateCall(getstackid_func,
+ CallInst *call = createCall(getstackid_func,
{ ctx, map_ptr, flags_val },
"get_stackid");
CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_get_stackid, loc);
@@ -852,7 +867,7 @@ void IRBuilderBPF::CreateGetCurrentComm(Value *ctx,
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_get_current_comm),
getcomm_func_ptr_type);
- CallInst *call = CreateCall(getcomm_func,
+ CallInst *call = createCall(getcomm_func,
{ buf, getInt64(size) },
"get_comm");
CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_get_current_comm, loc);
@@ -883,7 +898,9 @@ void IRBuilderBPF::CreatePerfEventOutput(Value *ctx, Value *data, size_t size)
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_perf_event_output),
perfoutput_func_ptr_type);
- CreateCall(perfoutput_func, {ctx, map_ptr, flags_val, data, size_val}, "perf_event_output");
+ createCall(perfoutput_func,
+ { ctx, map_ptr, flags_val, data, size_val },
+ "perf_event_output");
}
void IRBuilderBPF::CreateSignal(Value *ctx, Value *sig, const location &loc)
@@ -899,7 +916,7 @@ void IRBuilderBPF::CreateSignal(Value *ctx, Value *sig, const location &loc)
Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_send_signal),
signal_func_ptr_type);
- CallInst *call = CreateCall(signal_func, { sig }, "signal");
+ CallInst *call = createCall(signal_func, { sig }, "signal");
CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_send_signal, loc);
}
@@ -913,7 +930,7 @@ void IRBuilderBPF::CreateOverrideReturn(Value *ctx, Value *rc)
Constant *override_func = ConstantExpr::getCast(Instruction::IntToPtr,
getInt64(libbpf::BPF_FUNC_override_return),
override_func_ptr_type);
- CreateCall(override_func, { ctx, rc }, "override");
+ createCall(override_func, { ctx, rc }, "override");
}
Value *IRBuilderBPF::CreatKFuncArg(Value *ctx,
diff --git a/src/ast/irbuilderbpf.h b/src/ast/irbuilderbpf.h
index d4361a8..3111507 100644
--- a/src/ast/irbuilderbpf.h
+++ b/src/ast/irbuilderbpf.h
@@ -80,6 +80,7 @@ class IRBuilderBPF : public IRBuilder<>
CallInst *CreateGetRandom();
CallInst *CreateGetStackId(Value *ctx, bool ustack, StackType stack_type, const location& loc);
CallInst *CreateGetJoinMap(Value *ctx, const location& loc);
+ CallInst *createCall(Value *callee, ArrayRef<Value *> args, const Twine &Name);
void CreateGetCurrentComm(Value *ctx, AllocaInst *buf, size_t size, const location& loc);
void CreatePerfEventOutput(Value *ctx, Value *data, size_t size);
void CreateSignal(Value *ctx, Value *sig, const location &loc);
diff --git a/src/bpforc.h b/src/bpforc.h
index a42e031..295f703 100644
--- a/src/bpforc.h
+++ b/src/bpforc.h
@@ -96,9 +96,15 @@ class BpfOrc
: TM(TM_),
Resolver(createLegacyLookupResolver(
ES,
+#if LLVM_VERSION_MAJOR >= 11
+ [](llvm::StringRef Name __attribute__((unused))) -> JITSymbol {
+ return nullptr;
+ },
+#else
[](const std::string &Name __attribute__((unused))) -> JITSymbol {
return nullptr;
},
+#endif
[](Error Err) { cantFail(std::move(Err), "lookup failed"); })),
#if LLVM_VERSION_MAJOR > 8
ObjectLayer(AcknowledgeORCv1Deprecation,
--
2.25.4

View File

@ -0,0 +1,56 @@
From 453e1ea9b9d036cc9cfa0ef2e20c53e926e1b3b8 Mon Sep 17 00:00:00 2001
From: Jerome Marchand <jmarchan@redhat.com>
Date: Tue, 11 Jun 2019 16:41:59 +0200
Subject: [PATCH] RHEL 9 fixes
Fixes the following RHEL 8 specific issues:
- library path in gethostlatency and threadsnoop
---
tools/gethostlatency.bt | 12 ++++++------
tools/threadsnoop.bt | 2 +-
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/tools/gethostlatency.bt b/tools/gethostlatency.bt
index 9f4ec31e..dd389c6f 100755
--- a/tools/gethostlatency.bt
+++ b/tools/gethostlatency.bt
@@ -26,17 +26,17 @@ BEGIN
"HOST");
}
-uprobe:/lib/x86_64-linux-gnu/libc.so.6:getaddrinfo,
-uprobe:/lib/x86_64-linux-gnu/libc.so.6:gethostbyname,
-uprobe:/lib/x86_64-linux-gnu/libc.so.6:gethostbyname2
+uprobe:/lib64/libc.so.6:getaddrinfo,
+uprobe:/lib64/libc.so.6:gethostbyname,
+uprobe:/lib64/libc.so.6:gethostbyname2
{
@start[tid] = nsecs;
@name[tid] = arg0;
}
-uretprobe:/lib/x86_64-linux-gnu/libc.so.6:getaddrinfo,
-uretprobe:/lib/x86_64-linux-gnu/libc.so.6:gethostbyname,
-uretprobe:/lib/x86_64-linux-gnu/libc.so.6:gethostbyname2
+uretprobe:/lib64/libc.so.6:getaddrinfo,
+uretprobe:/lib64/libc.so.6:gethostbyname,
+uretprobe:/lib64/libc.so.6:gethostbyname2
/@start[tid]/
{
$latms = (nsecs - @start[tid]) / 1e6;
diff --git a/tools/threadsnoop.bt b/tools/threadsnoop.bt
index 3824bc6d..bdc6e4df 100755
--- a/tools/threadsnoop.bt
+++ b/tools/threadsnoop.bt
@@ -18,7 +18,7 @@ BEGIN
printf("%-10s %-6s %-16s %s\n", "TIME(ms)", "PID", "COMM", "FUNC");
}
-uprobe:/lib/x86_64-linux-gnu/libpthread.so.0:pthread_create
+uprobe:/usr/lib64/libpthread.so:pthread_create
{
printf("%-10u %-6d %-16s %s\n", elapsed / 1e6, pid, comm,
usym(arg2));
--
2.31.1

View File

@ -1,12 +0,0 @@
diff --git a/src/parser.yy b/src/parser.yy
index 53293c5..3dbbd05 100644
--- a/src/parser.yy
+++ b/src/parser.yy
@@ -18,6 +18,7 @@
%code requires
{
#include <regex>
+#include <limits>
namespace bpftrace {
class Driver;

View File

@ -1,15 +1,12 @@
Name: bpftrace Name: bpftrace
Version: 0.11.0 Version: 0.12.1
Release: 10%{?dist} Release: 1%{?dist}
Summary: High-level tracing language for Linux eBPF Summary: High-level tracing language for Linux eBPF
License: ASL 2.0 License: ASL 2.0
URL: https://github.com/iovisor/bpftrace URL: https://github.com/iovisor/bpftrace
Source0: %{url}/archive/v%{version}/%{name}-%{version}.tar.gz Source0: %{url}/archive/v%{version}/%{name}-%{version}.tar.gz
Patch0: %{name}-%{version}-irbuilderbpf.cpp-bpforc.h-Fix-compilation-with-LLVM-.patch Patch0: %{name}-%{version}-RHEL-9-fixes.patch
Patch1: %{name}-%{version}-Feature-detect-bpf_attach_kprobe-signature.patch
Patch2: %{name}-%{version}-Detect-7-arg-bpf_attach_uprobe-API.patch
Patch3: %{name}-gcc11.patch
# Arches will be included as upstream support is added and dependencies are # Arches will be included as upstream support is added and dependencies are
# satisfied in the respective arches # satisfied in the respective arches
@ -23,7 +20,7 @@ BuildRequires: elfutils-libelf-devel
BuildRequires: zlib-devel BuildRequires: zlib-devel
BuildRequires: llvm-devel BuildRequires: llvm-devel
BuildRequires: clang-devel BuildRequires: clang-devel
BuildRequires: bcc-devel >= 0.11.0-2 BuildRequires: bcc-devel >= 0.19.0-1
BuildRequires: libbpf-devel BuildRequires: libbpf-devel
BuildRequires: libbpf-static BuildRequires: libbpf-static
BuildRequires: binutils-devel BuildRequires: binutils-devel
@ -47,8 +44,7 @@ and predecessor tracers such as DTrace and SystemTap
%cmake . \ %cmake . \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_TESTING:BOOL=OFF \ -DBUILD_TESTING:BOOL=OFF \
-DBUILD_SHARED_LIBS:BOOL=OFF \ -DBUILD_SHARED_LIBS:BOOL=OFF
-DLIBBCC_LIBRARIES:PATH=/usr/lib64/libbcc-no-libbpf.so
%cmake_build %cmake_build
@ -80,6 +76,9 @@ find %{buildroot}%{_datadir}/%{name}/tools -type f -exec \
%changelog %changelog
* Thu May 27 2021 Jerome Marchand <jmarchan@redhat.com> - 0.12.0-1
- Rebase to bpftrace 0.12.1
* Thu Apr 15 2021 Mohan Boddu <mboddu@redhat.com> - 0.11.0-10 * Thu Apr 15 2021 Mohan Boddu <mboddu@redhat.com> - 0.11.0-10
- Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937 - Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937

View File

@ -1 +1 @@
SHA512 (bpftrace-0.11.0.tar.gz) = 32bf0c23a7b0e1a57d0e0b8fc845a9e184e201ac3f6018a3d3cee8c97096093b333578cb898ede02fb3ab8d55ba9bcd2bb67ac70b81a49461c0f6e5c03c2a6f5 SHA512 (bpftrace-0.12.1.tar.gz) = a578499668bd2eb7342689b6c0ef3db6ca263a971d8e6f1b9a68c502c27170d24ede212a0fc2a72263e72aff58924f488a5c80d447397503a08512dc47b63345