Rebased to version 0.15.0
Resolves: bz#2090050 Signed-off-by: Augusto Caringi <acaringi@redhat.com>
This commit is contained in:
parent
afe0ddded6
commit
e201737cef
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,3 +14,4 @@
|
||||
/bpftrace-0.13.0.tar.gz
|
||||
/bpftrace-0.14.0.tar.gz
|
||||
/bpftrace-0.14.1.tar.gz
|
||||
/bpftrace-0.15.0.tar.gz
|
||||
|
@ -1,819 +0,0 @@
|
||||
From 19ce68dc707ff2d2c662fcec03435bd436336ebf Mon Sep 17 00:00:00 2001
|
||||
From: Viktor Malik <viktor.malik@gmail.com>
|
||||
Date: Mon, 10 Jan 2022 16:41:05 +0100
|
||||
Subject: [PATCH] Fix LLVM 13 warnings
|
||||
|
||||
Since LLVM 13, CreateGEP and CreateLoad require explicit types.
|
||||
---
|
||||
src/ast/irbuilderbpf.cpp | 63 +++++---
|
||||
src/ast/passes/codegen_llvm.cpp | 256 ++++++++++++++++++++------------
|
||||
2 files changed, 200 insertions(+), 119 deletions(-)
|
||||
|
||||
diff --git a/src/ast/irbuilderbpf.cpp b/src/ast/irbuilderbpf.cpp
|
||||
index d3528dee..976d70da 100644
|
||||
--- a/src/ast/irbuilderbpf.cpp
|
||||
+++ b/src/ast/irbuilderbpf.cpp
|
||||
@@ -94,8 +94,8 @@ AllocaInst *IRBuilderBPF::CreateUSym(llvm::Value *val)
|
||||
Value *pid = CreateLShr(CreateGetPidTgid(), 32);
|
||||
|
||||
// The extra 0 here ensures the type of addr_offset will be int64
|
||||
- Value *addr_offset = CreateGEP(buf, { getInt64(0), getInt32(0) });
|
||||
- Value *pid_offset = CreateGEP(buf, { getInt64(0), getInt32(1) });
|
||||
+ Value *addr_offset = CreateGEP(usym_t, buf, { getInt64(0), getInt32(0) });
|
||||
+ Value *pid_offset = CreateGEP(usym_t, buf, { getInt64(0), getInt32(1) });
|
||||
|
||||
CreateStore(val, addr_offset);
|
||||
CreateStore(pid, pid_offset);
|
||||
@@ -401,7 +401,8 @@ Value *IRBuilderBPF::CreateMapLookupElem(Value *ctx,
|
||||
if (needMemcpy(type))
|
||||
return value;
|
||||
|
||||
- Value *ret = CreateLoad(value);
|
||||
+ // value is a pointer to i64
|
||||
+ Value *ret = CreateLoad(getInt64Ty(), value);
|
||||
CreateLifetimeEnd(value);
|
||||
return ret;
|
||||
}
|
||||
@@ -621,7 +622,10 @@ Value *IRBuilderBPF::CreateUSDTReadArgument(Value *ctx,
|
||||
// bpftrace's args are internally represented as 64 bit integers. However,
|
||||
// the underlying argument (of the target program) may be less than 64
|
||||
// bits. So we must be careful to zero out unused bits.
|
||||
- Value* reg = CreateGEP(ctx, getInt64(offset * sizeof(uintptr_t)), "load_register");
|
||||
+ Value *reg = CreateGEP(getInt8Ty(),
|
||||
+ ctx,
|
||||
+ getInt64(offset * sizeof(uintptr_t)),
|
||||
+ "load_register");
|
||||
AllocaInst *dst = CreateAllocaBPF(builtin.type, builtin.ident);
|
||||
Value *index_offset = nullptr;
|
||||
if (argument->valid & BCC_USDT_ARGUMENT_INDEX_REGISTER_NAME)
|
||||
@@ -632,7 +636,8 @@ Value *IRBuilderBPF::CreateUSDTReadArgument(Value *ctx,
|
||||
LOG(FATAL) << "offset for register " << argument->index_register_name
|
||||
<< " not known";
|
||||
}
|
||||
- index_offset = CreateGEP(ctx,
|
||||
+ index_offset = CreateGEP(getInt8Ty(),
|
||||
+ ctx,
|
||||
getInt64(ioffset * sizeof(uintptr_t)),
|
||||
"load_register");
|
||||
index_offset = CreateLoad(getInt64Ty(), index_offset);
|
||||
@@ -756,17 +761,18 @@ Value *IRBuilderBPF::CreateStrncmp(Value *val1,
|
||||
else
|
||||
literal2 = std::nullopt;
|
||||
|
||||
+ auto *val1p = dyn_cast<PointerType>(val1->getType());
|
||||
+ auto *val2p = dyn_cast<PointerType>(val2->getType());
|
||||
#ifndef NDEBUG
|
||||
if (!literal1)
|
||||
{
|
||||
- PointerType *val1p = cast<PointerType>(val1->getType());
|
||||
+ assert(val1p);
|
||||
assert(val1p->getElementType()->isArrayTy() &&
|
||||
val1p->getElementType()->getArrayElementType() == getInt8Ty());
|
||||
}
|
||||
if (!literal2)
|
||||
{
|
||||
- PointerType *val2p = cast<PointerType>(val2->getType());
|
||||
-
|
||||
+ assert(val2p);
|
||||
assert(val2p->getElementType()->isArrayTy() &&
|
||||
val2p->getElementType()->getArrayElementType() == getInt8Ty());
|
||||
}
|
||||
@@ -798,7 +804,9 @@ Value *IRBuilderBPF::CreateStrncmp(Value *val1,
|
||||
l = getInt8(literal1->c_str()[i]);
|
||||
else
|
||||
{
|
||||
- auto *ptr_l = CreateGEP(val1, { getInt32(0), getInt32(i) });
|
||||
+ auto *ptr_l = CreateGEP(val1p->getElementType(),
|
||||
+ val1,
|
||||
+ { getInt32(0), getInt32(i) });
|
||||
l = CreateLoad(getInt8Ty(), ptr_l);
|
||||
}
|
||||
|
||||
@@ -807,7 +815,9 @@ Value *IRBuilderBPF::CreateStrncmp(Value *val1,
|
||||
r = getInt8(literal2->c_str()[i]);
|
||||
else
|
||||
{
|
||||
- auto *ptr_r = CreateGEP(val2, { getInt32(0), getInt32(i) });
|
||||
+ auto *ptr_r = CreateGEP(val2p->getElementType(),
|
||||
+ val2,
|
||||
+ { getInt32(0), getInt32(i) });
|
||||
r = CreateLoad(getInt8Ty(), ptr_r);
|
||||
}
|
||||
|
||||
@@ -829,7 +839,8 @@ Value *IRBuilderBPF::CreateStrncmp(Value *val1,
|
||||
CreateBr(str_ne);
|
||||
SetInsertPoint(str_ne);
|
||||
|
||||
- Value *result = CreateLoad(store);
|
||||
+ // store is a pointer to bool (i1 *)
|
||||
+ Value *result = CreateLoad(getInt1Ty(), store);
|
||||
CreateLifetimeEnd(store);
|
||||
result = CreateIntCast(result, getInt64Ty(), false);
|
||||
|
||||
@@ -1056,9 +1067,10 @@ Value *IRBuilderBPF::CreatKFuncArg(Value *ctx,
|
||||
{
|
||||
assert(type.IsIntTy() || type.IsPtrTy());
|
||||
ctx = CreatePointerCast(ctx, getInt64Ty()->getPointerTo());
|
||||
- Value *expr = CreateLoad(GetType(type),
|
||||
- CreateGEP(ctx, getInt64(type.funcarg_idx)),
|
||||
- name);
|
||||
+ Value *expr = CreateLoad(
|
||||
+ GetType(type),
|
||||
+ CreateGEP(getInt64Ty(), ctx, getInt64(type.funcarg_idx)),
|
||||
+ name);
|
||||
|
||||
// LLVM 7.0 <= does not have CreateLoad(*Ty, *Ptr, isVolatile, Name),
|
||||
// so call setVolatile() manually
|
||||
@@ -1081,7 +1093,7 @@ Value *IRBuilderBPF::CreateRegisterRead(Value *ctx, const std::string &builtin)
|
||||
// `(uint8*)ctx`, but sometimes this causes invalid context access.
|
||||
// Mark every context access to suppress any LLVM optimization.
|
||||
Value *result = CreateLoad(getInt64Ty(),
|
||||
- CreateGEP(ctx_ptr, getInt64(offset)),
|
||||
+ CreateGEP(getInt64Ty(), ctx_ptr, getInt64(offset)),
|
||||
builtin);
|
||||
// LLVM 7.0 <= does not have CreateLoad(*Ty, *Ptr, isVolatile, Name),
|
||||
// so call setVolatile() manually
|
||||
@@ -1134,12 +1146,15 @@ void IRBuilderBPF::CreateHelperError(Value *ctx,
|
||||
elements,
|
||||
true);
|
||||
AllocaInst *buf = CreateAllocaBPF(helper_error_struct, "helper_error_t");
|
||||
- CreateStore(GetIntSameSize(asyncactionint(AsyncAction::helper_error),
|
||||
- elements.at(0)),
|
||||
- CreateGEP(buf, { getInt64(0), getInt32(0) }));
|
||||
- CreateStore(GetIntSameSize(error_id, elements.at(1)),
|
||||
- CreateGEP(buf, { getInt64(0), getInt32(1) }));
|
||||
- CreateStore(return_value, CreateGEP(buf, { getInt64(0), getInt32(2) }));
|
||||
+ CreateStore(
|
||||
+ GetIntSameSize(asyncactionint(AsyncAction::helper_error), elements.at(0)),
|
||||
+ CreateGEP(helper_error_struct, buf, { getInt64(0), getInt32(0) }));
|
||||
+ CreateStore(
|
||||
+ GetIntSameSize(error_id, elements.at(1)),
|
||||
+ CreateGEP(helper_error_struct, buf, { getInt64(0), getInt32(1) }));
|
||||
+ CreateStore(
|
||||
+ return_value,
|
||||
+ CreateGEP(helper_error_struct, buf, { getInt64(0), getInt32(2) }));
|
||||
|
||||
auto &layout = module_.getDataLayout();
|
||||
auto struct_size = layout.getTypeAllocSize(helper_error_struct);
|
||||
@@ -1229,11 +1244,13 @@ void IRBuilderBPF::CreateSeqPrintf(Value *ctx,
|
||||
|
||||
ctx = CreatePointerCast(ctx, getInt8Ty()->getPointerTo());
|
||||
Value *meta = CreateLoad(getInt64Ty()->getPointerTo(),
|
||||
- CreateGEP(ctx, getInt64(0)),
|
||||
+ CreateGEP(getInt8Ty(), ctx, getInt64(0)),
|
||||
"meta");
|
||||
dyn_cast<LoadInst>(meta)->setVolatile(true);
|
||||
|
||||
- Value *seq = CreateLoad(getInt64Ty(), CreateGEP(meta, getInt64(0)), "seq");
|
||||
+ Value *seq = CreateLoad(getInt64Ty(),
|
||||
+ CreateGEP(getInt64Ty(), meta, getInt64(0)),
|
||||
+ "seq");
|
||||
|
||||
CallInst *call = createCall(seq_printf_func,
|
||||
{ seq, fmt, fmt_size, data, data_len },
|
||||
diff --git a/src/ast/passes/codegen_llvm.cpp b/src/ast/passes/codegen_llvm.cpp
|
||||
index aaa1ca14..302446cd 100644
|
||||
--- a/src/ast/passes/codegen_llvm.cpp
|
||||
+++ b/src/ast/passes/codegen_llvm.cpp
|
||||
@@ -233,16 +233,17 @@ void CodegenLLVM::visit(Builtin &builtin)
|
||||
|
||||
int arg_num = atoi(builtin.ident.substr(4).c_str());
|
||||
Value *ctx = b_.CreatePointerCast(ctx_, b_.getInt64Ty()->getPointerTo());
|
||||
- Value *sp = b_.CreateLoad(b_.getInt64Ty(),
|
||||
- b_.CreateGEP(ctx, b_.getInt64(sp_offset)),
|
||||
- "reg_sp");
|
||||
+ Value *sp = b_.CreateLoad(
|
||||
+ b_.getInt64Ty(),
|
||||
+ b_.CreateGEP(b_.getInt64Ty(), ctx, b_.getInt64(sp_offset)),
|
||||
+ "reg_sp");
|
||||
dyn_cast<LoadInst>(sp)->setVolatile(true);
|
||||
AllocaInst *dst = b_.CreateAllocaBPF(builtin.type, builtin.ident);
|
||||
Value *src = b_.CreateAdd(sp,
|
||||
b_.getInt64((arg_num + arch::arg_stack_offset()) *
|
||||
sizeof(uintptr_t)));
|
||||
b_.CreateProbeRead(ctx_, dst, 8, src, builtin.type.GetAS(), builtin.loc);
|
||||
- expr_ = b_.CreateLoad(dst);
|
||||
+ expr_ = b_.CreateLoad(b_.GetType(builtin.type), dst);
|
||||
b_.CreateLifetimeEnd(dst);
|
||||
}
|
||||
else if (builtin.ident == "probe")
|
||||
@@ -510,8 +511,12 @@ void CodegenLLVM::visit(Call &call)
|
||||
b_.CREATE_MEMSET(buf, b_.getInt8(0), bpftrace_.strlen_, 1);
|
||||
auto arg0 = call.vargs->front();
|
||||
auto scoped_del = accept(call.vargs->front());
|
||||
- b_.CreateProbeReadStr(
|
||||
- ctx_, buf, b_.CreateLoad(strlen), expr_, arg0->type.GetAS(), call.loc);
|
||||
+ b_.CreateProbeReadStr(ctx_,
|
||||
+ buf,
|
||||
+ b_.CreateLoad(b_.getInt64Ty(), strlen),
|
||||
+ expr_,
|
||||
+ arg0->type.GetAS(),
|
||||
+ call.loc);
|
||||
b_.CreateLifetimeEnd(strlen);
|
||||
|
||||
expr_ = buf;
|
||||
@@ -553,12 +558,14 @@ void CodegenLLVM::visit(Call &call)
|
||||
false);
|
||||
AllocaInst *buf = b_.CreateAllocaBPF(buf_struct, "buffer");
|
||||
|
||||
- Value *buf_len_offset = b_.CreateGEP(buf,
|
||||
+ Value *buf_len_offset = b_.CreateGEP(buf_struct,
|
||||
+ buf,
|
||||
{ b_.getInt32(0), b_.getInt32(0) });
|
||||
length = b_.CreateIntCast(length, buf_struct->getElementType(0), false);
|
||||
b_.CreateStore(length, buf_len_offset);
|
||||
|
||||
- Value *buf_data_offset = b_.CreateGEP(buf,
|
||||
+ Value *buf_data_offset = b_.CreateGEP(buf_struct,
|
||||
+ buf,
|
||||
{ b_.getInt32(0), b_.getInt32(1) });
|
||||
b_.CREATE_MEMSET(buf_data_offset,
|
||||
b_.GetIntSameSize(0, elements.at(0)),
|
||||
@@ -648,14 +655,14 @@ void CodegenLLVM::visit(Call &call)
|
||||
b_.SetInsertPoint(notzero);
|
||||
b_.CreateStore(b_.getInt64(asyncactionint(AsyncAction::join)), perfdata);
|
||||
b_.CreateStore(b_.getInt64(join_id_),
|
||||
- b_.CreateGEP(perfdata, b_.getInt64(8)));
|
||||
+ b_.CreateGEP(b_.getInt8Ty(), perfdata, b_.getInt64(8)));
|
||||
join_id_++;
|
||||
AllocaInst *arr = b_.CreateAllocaBPF(b_.getInt64Ty(), call.func + "_r0");
|
||||
b_.CreateProbeRead(ctx_, arr, 8, expr_, addrspace, call.loc);
|
||||
b_.CreateProbeReadStr(ctx_,
|
||||
b_.CreateAdd(perfdata, b_.getInt64(8 + 8)),
|
||||
bpftrace_.join_argsize_,
|
||||
- b_.CreateLoad(arr),
|
||||
+ b_.CreateLoad(b_.getInt64Ty(), arr),
|
||||
addrspace,
|
||||
call.loc);
|
||||
|
||||
@@ -663,14 +670,18 @@ void CodegenLLVM::visit(Call &call)
|
||||
{
|
||||
// argi
|
||||
b_.CreateStore(b_.CreateAdd(expr_, b_.getInt64(8 * i)), first);
|
||||
- b_.CreateProbeRead(
|
||||
- ctx_, second, 8, b_.CreateLoad(first), addrspace, call.loc);
|
||||
+ b_.CreateProbeRead(ctx_,
|
||||
+ second,
|
||||
+ 8,
|
||||
+ b_.CreateLoad(b_.getInt64Ty(), first),
|
||||
+ addrspace,
|
||||
+ call.loc);
|
||||
b_.CreateProbeReadStr(
|
||||
ctx_,
|
||||
b_.CreateAdd(perfdata,
|
||||
b_.getInt64(8 + 8 + i * bpftrace_.join_argsize_)),
|
||||
bpftrace_.join_argsize_,
|
||||
- b_.CreateLoad(second),
|
||||
+ b_.CreateLoad(b_.getInt64Ty(), second),
|
||||
addrspace,
|
||||
call.loc);
|
||||
}
|
||||
@@ -713,7 +724,9 @@ void CodegenLLVM::visit(Call &call)
|
||||
|
||||
AllocaInst *buf = b_.CreateAllocaBPF(inet_struct, "inet");
|
||||
|
||||
- Value *af_offset = b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(0) });
|
||||
+ Value *af_offset = b_.CreateGEP(inet_struct,
|
||||
+ buf,
|
||||
+ { b_.getInt64(0), b_.getInt32(0) });
|
||||
Value *af_type;
|
||||
|
||||
auto inet = call.vargs->at(0);
|
||||
@@ -736,7 +749,9 @@ void CodegenLLVM::visit(Call &call)
|
||||
}
|
||||
b_.CreateStore(af_type, af_offset);
|
||||
|
||||
- Value *inet_offset = b_.CreateGEP(buf, {b_.getInt32(0), b_.getInt32(1)});
|
||||
+ Value *inet_offset = b_.CreateGEP(inet_struct,
|
||||
+ buf,
|
||||
+ { b_.getInt32(0), b_.getInt32(1) });
|
||||
b_.CREATE_MEMSET(inet_offset, b_.getInt8(0), 16, 1);
|
||||
|
||||
auto scoped_del = accept(inet);
|
||||
@@ -769,9 +784,10 @@ void CodegenLLVM::visit(Call &call)
|
||||
}
|
||||
|
||||
Value *ctx = b_.CreatePointerCast(ctx_, b_.getInt64Ty()->getPointerTo());
|
||||
- expr_ = b_.CreateLoad(b_.getInt64Ty(),
|
||||
- b_.CreateGEP(ctx, b_.getInt64(offset)),
|
||||
- call.func + "_" + reg_name);
|
||||
+ expr_ = b_.CreateLoad(
|
||||
+ b_.getInt64Ty(),
|
||||
+ b_.CreateGEP(b_.getInt64Ty(), ctx, b_.getInt64(offset)),
|
||||
+ call.func + "_" + reg_name);
|
||||
dyn_cast<LoadInst>(expr_)->setVolatile(true);
|
||||
}
|
||||
else if (call.func == "printf")
|
||||
@@ -796,8 +812,10 @@ void CodegenLLVM::visit(Call &call)
|
||||
auto scoped_del = accept(&arg);
|
||||
|
||||
// and store it to data area
|
||||
- Value *offset = b_.CreateGEP(
|
||||
- data, { b_.getInt64(0), b_.getInt64((i - 1) * ptr_size) });
|
||||
+ Value *offset = b_.CreateGEP(b_.GetType(data_type),
|
||||
+ data,
|
||||
+ { b_.getInt64(0),
|
||||
+ b_.getInt64((i - 1) * ptr_size) });
|
||||
b_.CreateStore(expr_, offset);
|
||||
|
||||
// keep the expression alive, so it's still there
|
||||
@@ -885,7 +903,9 @@ void CodegenLLVM::visit(Call &call)
|
||||
AllocaInst *buf = b_.CreateAllocaBPF(event_struct,
|
||||
call.func + "_" + map.ident);
|
||||
|
||||
- auto aa_ptr = b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(0) });
|
||||
+ auto aa_ptr = b_.CreateGEP(event_struct,
|
||||
+ buf,
|
||||
+ { b_.getInt64(0), b_.getInt32(0) });
|
||||
if (call.func == "clear")
|
||||
b_.CreateStore(b_.GetIntSameSize(asyncactionint(AsyncAction::clear),
|
||||
elements.at(0)),
|
||||
@@ -896,7 +916,9 @@ void CodegenLLVM::visit(Call &call)
|
||||
aa_ptr);
|
||||
|
||||
auto id = bpftrace_.maps[map.ident].value()->id;
|
||||
- auto *ident_ptr = b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(1) });
|
||||
+ auto *ident_ptr = b_.CreateGEP(event_struct,
|
||||
+ buf,
|
||||
+ { b_.getInt64(0), b_.getInt32(1) });
|
||||
b_.CreateStore(b_.GetIntSameSize(id, elements.at(1)), ident_ptr);
|
||||
|
||||
b_.CreatePerfEventOutput(ctx_, buf, getStructSize(event_struct));
|
||||
@@ -912,12 +934,13 @@ void CodegenLLVM::visit(Call &call)
|
||||
|
||||
AllocaInst *buf = b_.CreateAllocaBPF(time_struct, call.func + "_t");
|
||||
|
||||
- b_.CreateStore(b_.GetIntSameSize(asyncactionint(AsyncAction::time),
|
||||
- elements.at(0)),
|
||||
- b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(0) }));
|
||||
+ b_.CreateStore(
|
||||
+ b_.GetIntSameSize(asyncactionint(AsyncAction::time), elements.at(0)),
|
||||
+ b_.CreateGEP(time_struct, buf, { b_.getInt64(0), b_.getInt32(0) }));
|
||||
|
||||
- b_.CreateStore(b_.GetIntSameSize(time_id_, elements.at(1)),
|
||||
- b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(1) }));
|
||||
+ b_.CreateStore(
|
||||
+ b_.GetIntSameSize(time_id_, elements.at(1)),
|
||||
+ b_.CreateGEP(time_struct, buf, { b_.getInt64(0), b_.getInt32(1) }));
|
||||
|
||||
time_id_++;
|
||||
b_.CreatePerfEventOutput(ctx_, buf, getStructSize(time_struct));
|
||||
@@ -932,13 +955,15 @@ void CodegenLLVM::visit(Call &call)
|
||||
true);
|
||||
|
||||
AllocaInst *buf = b_.CreateAllocaBPF(strftime_struct, call.func + "_args");
|
||||
- b_.CreateStore(b_.GetIntSameSize(strftime_id_, elements.at(0)),
|
||||
- b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(0) }));
|
||||
+ b_.CreateStore(
|
||||
+ b_.GetIntSameSize(strftime_id_, elements.at(0)),
|
||||
+ b_.CreateGEP(strftime_struct, buf, { b_.getInt64(0), b_.getInt32(0) }));
|
||||
strftime_id_++;
|
||||
Expression *arg = call.vargs->at(1);
|
||||
auto scoped_del = accept(arg);
|
||||
- b_.CreateStore(expr_,
|
||||
- b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(1) }));
|
||||
+ b_.CreateStore(
|
||||
+ expr_,
|
||||
+ b_.CreateGEP(strftime_struct, buf, { b_.getInt64(0), b_.getInt32(1) }));
|
||||
expr_ = buf;
|
||||
}
|
||||
else if (call.func == "kstack" || call.func == "ustack")
|
||||
@@ -1022,11 +1047,12 @@ void CodegenLLVM::visit(Call &call)
|
||||
AllocaInst *buf = b_.CreateAllocaBPF(unwatch_struct, "unwatch");
|
||||
size_t struct_size = datalayout().getTypeAllocSize(unwatch_struct);
|
||||
|
||||
- b_.CreateStore(b_.getInt64(asyncactionint(AsyncAction::watchpoint_detach)),
|
||||
- b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(0) }));
|
||||
+ b_.CreateStore(
|
||||
+ b_.getInt64(asyncactionint(AsyncAction::watchpoint_detach)),
|
||||
+ b_.CreateGEP(unwatch_struct, buf, { b_.getInt64(0), b_.getInt32(0) }));
|
||||
b_.CreateStore(
|
||||
b_.CreateIntCast(expr_, b_.getInt64Ty(), false /* unsigned */),
|
||||
- b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(1) }));
|
||||
+ b_.CreateGEP(unwatch_struct, buf, { b_.getInt64(0), b_.getInt32(1) }));
|
||||
b_.CreatePerfEventOutput(ctx_, buf, struct_size);
|
||||
b_.CreateLifetimeEnd(buf);
|
||||
expr_ = nullptr;
|
||||
@@ -1056,7 +1082,8 @@ void CodegenLLVM::visit(Variable &var)
|
||||
}
|
||||
else
|
||||
{
|
||||
- expr_ = b_.CreateLoad(variables_[var.ident]);
|
||||
+ auto *var_alloca = variables_[var.ident];
|
||||
+ expr_ = b_.CreateLoad(var_alloca->getType()->getElementType(), var_alloca);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1379,9 +1406,10 @@ void CodegenLLVM::unop_int(Unop &unop)
|
||||
int size = type.GetSize();
|
||||
auto as = type.GetAS();
|
||||
|
||||
- AllocaInst *dst = b_.CreateAllocaBPF(SizedType(type.type, size), "deref");
|
||||
+ auto dst_type = SizedType(type.type, size);
|
||||
+ AllocaInst *dst = b_.CreateAllocaBPF(dst_type, "deref");
|
||||
b_.CreateProbeRead(ctx_, dst, size, expr_, as, unop.loc);
|
||||
- expr_ = b_.CreateIntCast(b_.CreateLoad(dst),
|
||||
+ expr_ = b_.CreateIntCast(b_.CreateLoad(b_.GetType(dst_type), dst),
|
||||
b_.getInt64Ty(),
|
||||
type.IsSigned());
|
||||
b_.CreateLifetimeEnd(dst);
|
||||
@@ -1405,7 +1433,7 @@ void CodegenLLVM::unop_ptr(Unop &unop)
|
||||
int size = unop.type.IsIntegerTy() ? et->GetIntBitWidth() / 8 : 8;
|
||||
AllocaInst *dst = b_.CreateAllocaBPF(*et, "deref");
|
||||
b_.CreateProbeRead(ctx_, dst, size, expr_, type.GetAS(), unop.loc);
|
||||
- expr_ = b_.CreateIntCast(b_.CreateLoad(dst),
|
||||
+ expr_ = b_.CreateIntCast(b_.CreateLoad(b_.GetType(*et), dst),
|
||||
b_.getInt64Ty(),
|
||||
unop.type.IsSigned());
|
||||
b_.CreateLifetimeEnd(dst);
|
||||
@@ -1484,7 +1512,7 @@ void CodegenLLVM::visit(Ternary &ternary)
|
||||
b_.CreateBr(done);
|
||||
|
||||
b_.SetInsertPoint(done);
|
||||
- expr_ = b_.CreateLoad(result);
|
||||
+ expr_ = b_.CreateLoad(b_.GetType(ternary.type), result);
|
||||
}
|
||||
else if (ternary.type.IsStringTy())
|
||||
{
|
||||
@@ -1547,7 +1575,8 @@ void CodegenLLVM::visit(FieldAccess &acc)
|
||||
}
|
||||
else if (type.IsTupleTy())
|
||||
{
|
||||
- Value *src = b_.CreateGEP(expr_,
|
||||
+ Value *src = b_.CreateGEP(b_.GetType(type),
|
||||
+ expr_,
|
||||
{ b_.getInt32(0), b_.getInt32(acc.index) });
|
||||
SizedType &elem_type = type.GetFields()[acc.index].type;
|
||||
|
||||
@@ -1594,10 +1623,12 @@ void CodegenLLVM::visit(FieldAccess &acc)
|
||||
if (field.is_bitfield)
|
||||
{
|
||||
Value *raw;
|
||||
+ auto field_type = b_.GetType(field.type);
|
||||
if (type.IsCtxAccess())
|
||||
- raw = b_.CreateLoad(
|
||||
- b_.CreateIntToPtr(src, b_.GetType(field.type)->getPointerTo()),
|
||||
- true);
|
||||
+ raw = b_.CreateLoad(field_type,
|
||||
+ b_.CreateIntToPtr(src,
|
||||
+ field_type->getPointerTo()),
|
||||
+ true);
|
||||
else
|
||||
{
|
||||
AllocaInst *dst = b_.CreateAllocaBPF(field.type,
|
||||
@@ -1608,7 +1639,7 @@ void CodegenLLVM::visit(FieldAccess &acc)
|
||||
b_.CREATE_MEMSET(dst, b_.getInt8(0), field.type.GetSize(), 1);
|
||||
b_.CreateProbeRead(
|
||||
ctx_, dst, field.bitfield.read_bytes, src, type.GetAS(), acc.loc);
|
||||
- raw = b_.CreateLoad(dst);
|
||||
+ raw = b_.CreateLoad(field_type, dst);
|
||||
b_.CreateLifetimeEnd(dst);
|
||||
}
|
||||
size_t rshiftbits;
|
||||
@@ -1636,7 +1667,8 @@ void CodegenLLVM::visit(FieldAccess &acc)
|
||||
// offset which we add to the start of the tracepoint struct.
|
||||
expr_ = b_.CreateLoad(
|
||||
b_.getInt32Ty(),
|
||||
- b_.CreateGEP(b_.CreatePointerCast(ctx_,
|
||||
+ b_.CreateGEP(b_.getInt32Ty(),
|
||||
+ b_.CreatePointerCast(ctx_,
|
||||
b_.getInt32Ty()->getPointerTo()),
|
||||
b_.getInt64(field.offset / 4)));
|
||||
expr_ = b_.CreateIntCast(expr_, b_.getInt64Ty(), false);
|
||||
@@ -1755,7 +1787,9 @@ void CodegenLLVM::visit(Tuple &tuple)
|
||||
Expression *elem = tuple.elems->at(i);
|
||||
auto scoped_del = accept(elem);
|
||||
|
||||
- Value *dst = b_.CreateGEP(buf, { b_.getInt32(0), b_.getInt32(i) });
|
||||
+ Value *dst = b_.CreateGEP(tuple_ty,
|
||||
+ buf,
|
||||
+ { b_.getInt32(0), b_.getInt32(i) });
|
||||
|
||||
if (onStack(elem->type))
|
||||
b_.CREATE_MEMCPY(dst, expr_, elem->type.GetSize(), 1);
|
||||
@@ -2384,6 +2418,7 @@ AllocaInst *CodegenLLVM::getMultiMapKey(Map &map,
|
||||
size += expr->type.GetSize();
|
||||
}
|
||||
AllocaInst *key = b_.CreateAllocaBPF(size, map.ident + "_key");
|
||||
+ auto *key_type = ArrayType::get(b_.getInt8Ty(), size);
|
||||
|
||||
int offset = 0;
|
||||
bool aligned = true;
|
||||
@@ -2391,7 +2426,8 @@ AllocaInst *CodegenLLVM::getMultiMapKey(Map &map,
|
||||
for (Expression *expr : *map.vargs)
|
||||
{
|
||||
auto scoped_del = accept(expr);
|
||||
- Value *offset_val = b_.CreateGEP(key,
|
||||
+ Value *offset_val = b_.CreateGEP(key_type,
|
||||
+ key,
|
||||
{ b_.getInt64(0), b_.getInt64(offset) });
|
||||
|
||||
if (onStack(expr->type))
|
||||
@@ -2433,7 +2469,8 @@ AllocaInst *CodegenLLVM::getMultiMapKey(Map &map,
|
||||
|
||||
for (auto *extra_key : extra_keys)
|
||||
{
|
||||
- Value *offset_val = b_.CreateGEP(key,
|
||||
+ Value *offset_val = b_.CreateGEP(key_type,
|
||||
+ key,
|
||||
{ b_.getInt64(0), b_.getInt64(offset) });
|
||||
if (aligned)
|
||||
b_.CreateStore(extra_key, offset_val);
|
||||
@@ -2490,7 +2527,7 @@ Value *CodegenLLVM::createLogicalAnd(Binop &binop)
|
||||
b_.CreateBr(merge_block);
|
||||
|
||||
b_.SetInsertPoint(merge_block);
|
||||
- return b_.CreateLoad(result);
|
||||
+ return b_.CreateLoad(b_.getInt64Ty(), result);
|
||||
}
|
||||
|
||||
Value *CodegenLLVM::createLogicalOr(Binop &binop)
|
||||
@@ -2529,7 +2566,7 @@ Value *CodegenLLVM::createLogicalOr(Binop &binop)
|
||||
b_.CreateBr(merge_block);
|
||||
|
||||
b_.SetInsertPoint(merge_block);
|
||||
- return b_.CreateLoad(result);
|
||||
+ return b_.CreateLoad(b_.getInt64Ty(), result);
|
||||
}
|
||||
|
||||
Function *CodegenLLVM::createLog2Function()
|
||||
@@ -2573,34 +2610,37 @@ Function *CodegenLLVM::createLog2Function()
|
||||
// test for less than zero
|
||||
BasicBlock *is_less_than_zero = BasicBlock::Create(module_->getContext(), "hist.is_less_than_zero", log2_func);
|
||||
BasicBlock *is_not_less_than_zero = BasicBlock::Create(module_->getContext(), "hist.is_not_less_than_zero", log2_func);
|
||||
- b_.CreateCondBr(b_.CreateICmpSLT(b_.CreateLoad(n_alloc), b_.getInt64(0)),
|
||||
+ b_.CreateCondBr(b_.CreateICmpSLT(b_.CreateLoad(b_.getInt64Ty(), n_alloc),
|
||||
+ b_.getInt64(0)),
|
||||
is_less_than_zero,
|
||||
is_not_less_than_zero);
|
||||
b_.SetInsertPoint(is_less_than_zero);
|
||||
- createRet(b_.CreateLoad(result));
|
||||
+ createRet(b_.CreateLoad(b_.getInt64Ty(), result));
|
||||
b_.SetInsertPoint(is_not_less_than_zero);
|
||||
|
||||
// test for equal to zero
|
||||
BasicBlock *is_zero = BasicBlock::Create(module_->getContext(), "hist.is_zero", log2_func);
|
||||
BasicBlock *is_not_zero = BasicBlock::Create(module_->getContext(), "hist.is_not_zero", log2_func);
|
||||
- b_.CreateCondBr(b_.CreateICmpEQ(b_.CreateLoad(n_alloc), b_.getInt64(0)),
|
||||
+ b_.CreateCondBr(b_.CreateICmpEQ(b_.CreateLoad(b_.getInt64Ty(), n_alloc),
|
||||
+ b_.getInt64(0)),
|
||||
is_zero,
|
||||
is_not_zero);
|
||||
b_.SetInsertPoint(is_zero);
|
||||
b_.CreateStore(b_.getInt64(1), result);
|
||||
- createRet(b_.CreateLoad(result));
|
||||
+ createRet(b_.CreateLoad(b_.getInt64Ty(), result));
|
||||
b_.SetInsertPoint(is_not_zero);
|
||||
|
||||
// power-of-2 index, offset by +2
|
||||
b_.CreateStore(b_.getInt64(2), result);
|
||||
for (int i = 4; i >= 0; i--)
|
||||
{
|
||||
- Value *n = b_.CreateLoad(n_alloc);
|
||||
+ Value *n = b_.CreateLoad(b_.getInt64Ty(), n_alloc);
|
||||
Value *shift = b_.CreateShl(b_.CreateIntCast(b_.CreateICmpSGE(b_.CreateIntCast(n, b_.getInt64Ty(), false), b_.getInt64(1 << (1<<i))), b_.getInt64Ty(), false), i);
|
||||
b_.CreateStore(b_.CreateLShr(n, shift), n_alloc);
|
||||
- b_.CreateStore(b_.CreateAdd(b_.CreateLoad(result), shift), result);
|
||||
+ b_.CreateStore(b_.CreateAdd(b_.CreateLoad(b_.getInt64Ty(), result), shift),
|
||||
+ result);
|
||||
}
|
||||
- createRet(b_.CreateLoad(result));
|
||||
+ createRet(b_.CreateLoad(b_.getInt64Ty(), result));
|
||||
b_.restoreIP(ip);
|
||||
return module_->getFunction("log2");
|
||||
}
|
||||
@@ -2650,8 +2690,8 @@ Function *CodegenLLVM::createLinearFunction()
|
||||
|
||||
// algorithm
|
||||
{
|
||||
- Value *min = b_.CreateLoad(min_alloc);
|
||||
- Value *val = b_.CreateLoad(value_alloc);
|
||||
+ Value *min = b_.CreateLoad(b_.getInt64Ty(), min_alloc);
|
||||
+ Value *val = b_.CreateLoad(b_.getInt64Ty(), value_alloc);
|
||||
cmp = b_.CreateICmpSLT(val, min);
|
||||
}
|
||||
BasicBlock *lt_min = BasicBlock::Create(module_->getContext(), "lhist.lt_min", linear_func);
|
||||
@@ -2663,8 +2703,8 @@ Function *CodegenLLVM::createLinearFunction()
|
||||
|
||||
b_.SetInsertPoint(ge_min);
|
||||
{
|
||||
- Value *max = b_.CreateLoad(max_alloc);
|
||||
- Value *val = b_.CreateLoad(value_alloc);
|
||||
+ Value *max = b_.CreateLoad(b_.getInt64Ty(), max_alloc);
|
||||
+ Value *val = b_.CreateLoad(b_.getInt64Ty(), value_alloc);
|
||||
cmp = b_.CreateICmpSGT(val, max);
|
||||
}
|
||||
BasicBlock *le_max = BasicBlock::Create(module_->getContext(), "lhist.le_max", linear_func);
|
||||
@@ -2673,22 +2713,22 @@ Function *CodegenLLVM::createLinearFunction()
|
||||
|
||||
b_.SetInsertPoint(gt_max);
|
||||
{
|
||||
- Value *step = b_.CreateLoad(step_alloc);
|
||||
- Value *min = b_.CreateLoad(min_alloc);
|
||||
- Value *max = b_.CreateLoad(max_alloc);
|
||||
+ Value *step = b_.CreateLoad(b_.getInt64Ty(), step_alloc);
|
||||
+ Value *min = b_.CreateLoad(b_.getInt64Ty(), min_alloc);
|
||||
+ Value *max = b_.CreateLoad(b_.getInt64Ty(), max_alloc);
|
||||
Value *div = b_.CreateUDiv(b_.CreateSub(max, min), step);
|
||||
b_.CreateStore(b_.CreateAdd(div, b_.getInt64(1)), result_alloc);
|
||||
- createRet(b_.CreateLoad(result_alloc));
|
||||
+ createRet(b_.CreateLoad(b_.getInt64Ty(), result_alloc));
|
||||
}
|
||||
|
||||
b_.SetInsertPoint(le_max);
|
||||
{
|
||||
- Value *step = b_.CreateLoad(step_alloc);
|
||||
- Value *min = b_.CreateLoad(min_alloc);
|
||||
- Value *val = b_.CreateLoad(value_alloc);
|
||||
+ Value *step = b_.CreateLoad(b_.getInt64Ty(), step_alloc);
|
||||
+ Value *min = b_.CreateLoad(b_.getInt64Ty(), min_alloc);
|
||||
+ Value *val = b_.CreateLoad(b_.getInt64Ty(), value_alloc);
|
||||
Value *div3 = b_.CreateUDiv(b_.CreateSub(val, min), step);
|
||||
b_.CreateStore(b_.CreateAdd(div3, b_.getInt64(1)), result_alloc);
|
||||
- createRet(b_.CreateLoad(result_alloc));
|
||||
+ createRet(b_.CreateLoad(b_.getInt64Ty(), result_alloc));
|
||||
}
|
||||
|
||||
b_.restoreIP(ip);
|
||||
@@ -2742,14 +2782,18 @@ void CodegenLLVM::createFormatStringCall(Call &call, int &id, CallArgs &call_arg
|
||||
// as the struct is not packed we need to memset it.
|
||||
b_.CREATE_MEMSET(fmt_args, b_.getInt8(0), struct_size, 1);
|
||||
|
||||
- Value *id_offset = b_.CreateGEP(fmt_args, {b_.getInt32(0), b_.getInt32(0)});
|
||||
+ Value *id_offset = b_.CreateGEP(fmt_struct,
|
||||
+ fmt_args,
|
||||
+ { b_.getInt32(0), b_.getInt32(0) });
|
||||
b_.CreateStore(b_.getInt64(id + asyncactionint(async_action)), id_offset);
|
||||
|
||||
for (size_t i=1; i<call.vargs->size(); i++)
|
||||
{
|
||||
Expression &arg = *call.vargs->at(i);
|
||||
auto scoped_del = accept(&arg);
|
||||
- Value *offset = b_.CreateGEP(fmt_args, {b_.getInt32(0), b_.getInt32(i)});
|
||||
+ Value *offset = b_.CreateGEP(fmt_struct,
|
||||
+ fmt_args,
|
||||
+ { b_.getInt32(0), b_.getInt32(i) });
|
||||
if (needMemcpy(arg.type))
|
||||
b_.CREATE_MEMCPY(offset, expr_, arg.type.GetSize(), 1);
|
||||
else if (arg.type.IsIntegerTy() && arg.type.GetSize() < 8)
|
||||
@@ -2789,10 +2833,12 @@ void CodegenLLVM::generateWatchpointSetupProbe(
|
||||
// Pull out function argument
|
||||
Value *ctx = func->arg_begin();
|
||||
int offset = arch::arg_offset(arg_num);
|
||||
- Value *addr = b_.CreateLoad(
|
||||
- b_.getInt64Ty(),
|
||||
- b_.CreateGEP(ctx, b_.getInt64(offset * sizeof(uintptr_t))),
|
||||
- "arg" + std::to_string(arg_num));
|
||||
+ Value *arg = b_.CreateGEP(b_.getInt8Ty(),
|
||||
+ ctx,
|
||||
+ b_.getInt64(offset * sizeof(uintptr_t)));
|
||||
+ Value *addr = b_.CreateLoad(b_.getInt64Ty(),
|
||||
+ arg,
|
||||
+ "arg" + std::to_string(arg_num));
|
||||
|
||||
// Tell userspace to setup the real watchpoint
|
||||
auto elements = AsyncEvent::Watchpoint().asLLVMType(b_);
|
||||
@@ -2803,12 +2849,16 @@ void CodegenLLVM::generateWatchpointSetupProbe(
|
||||
size_t struct_size = datalayout().getTypeAllocSize(watchpoint_struct);
|
||||
|
||||
// Fill in perf event struct
|
||||
- b_.CreateStore(b_.getInt64(asyncactionint(AsyncAction::watchpoint_attach)),
|
||||
- b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(0) }));
|
||||
- b_.CreateStore(b_.getInt64(watchpoint_id_),
|
||||
- b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(1) }));
|
||||
+ b_.CreateStore(
|
||||
+ b_.getInt64(asyncactionint(AsyncAction::watchpoint_attach)),
|
||||
+ b_.CreateGEP(watchpoint_struct, buf, { b_.getInt64(0), b_.getInt32(0) }));
|
||||
+ b_.CreateStore(
|
||||
+ b_.getInt64(watchpoint_id_),
|
||||
+ b_.CreateGEP(watchpoint_struct, buf, { b_.getInt64(0), b_.getInt32(1) }));
|
||||
watchpoint_id_++;
|
||||
- b_.CreateStore(addr, b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(2) }));
|
||||
+ b_.CreateStore(
|
||||
+ addr,
|
||||
+ b_.CreateGEP(watchpoint_struct, buf, { b_.getInt64(0), b_.getInt32(2) }));
|
||||
b_.CreatePerfEventOutput(ctx, buf, struct_size);
|
||||
b_.CreateLifetimeEnd(buf);
|
||||
|
||||
@@ -2827,11 +2877,14 @@ void CodegenLLVM::createPrintMapCall(Call &call)
|
||||
call.func + "_" + map.ident);
|
||||
|
||||
// store asyncactionid:
|
||||
- b_.CreateStore(b_.getInt64(asyncactionint(AsyncAction::print)),
|
||||
- b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(0) }));
|
||||
+ b_.CreateStore(
|
||||
+ b_.getInt64(asyncactionint(AsyncAction::print)),
|
||||
+ b_.CreateGEP(print_struct, buf, { b_.getInt64(0), b_.getInt32(0) }));
|
||||
|
||||
auto id = bpftrace_.maps[map.ident].value()->id;
|
||||
- auto *ident_ptr = b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(1) });
|
||||
+ auto *ident_ptr = b_.CreateGEP(print_struct,
|
||||
+ buf,
|
||||
+ { b_.getInt64(0), b_.getInt32(1) });
|
||||
b_.CreateStore(b_.GetIntSameSize(id, elements.at(1)), ident_ptr);
|
||||
|
||||
// top, div
|
||||
@@ -2843,14 +2896,16 @@ void CodegenLLVM::createPrintMapCall(Call &call)
|
||||
auto scoped_del = accept(call.vargs->at(arg_idx));
|
||||
|
||||
b_.CreateStore(b_.CreateIntCast(expr_, elements.at(arg_idx), false),
|
||||
- b_.CreateGEP(buf,
|
||||
+ b_.CreateGEP(print_struct,
|
||||
+ buf,
|
||||
{ b_.getInt64(0), b_.getInt32(arg_idx + 1) }));
|
||||
}
|
||||
|
||||
for (; arg_idx < 3; arg_idx++)
|
||||
{
|
||||
b_.CreateStore(b_.GetIntSameSize(0, elements.at(arg_idx)),
|
||||
- b_.CreateGEP(buf,
|
||||
+ b_.CreateGEP(print_struct,
|
||||
+ buf,
|
||||
{ b_.getInt64(0), b_.getInt32(arg_idx + 1) }));
|
||||
}
|
||||
|
||||
@@ -2875,15 +2930,19 @@ void CodegenLLVM::createPrintNonMapCall(Call &call, int &id)
|
||||
size_t struct_size = datalayout().getTypeAllocSize(print_struct);
|
||||
|
||||
// Store asyncactionid:
|
||||
- b_.CreateStore(b_.getInt64(asyncactionint(AsyncAction::print_non_map)),
|
||||
- b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(0) }));
|
||||
+ b_.CreateStore(
|
||||
+ b_.getInt64(asyncactionint(AsyncAction::print_non_map)),
|
||||
+ b_.CreateGEP(print_struct, buf, { b_.getInt64(0), b_.getInt32(0) }));
|
||||
|
||||
// Store print id
|
||||
- b_.CreateStore(b_.getInt64(id),
|
||||
- b_.CreateGEP(buf, { b_.getInt64(0), b_.getInt32(1) }));
|
||||
+ b_.CreateStore(
|
||||
+ b_.getInt64(id),
|
||||
+ b_.CreateGEP(print_struct, buf, { b_.getInt64(0), b_.getInt32(1) }));
|
||||
|
||||
// Store content
|
||||
- Value *content_offset = b_.CreateGEP(buf, { b_.getInt32(0), b_.getInt32(2) });
|
||||
+ Value *content_offset = b_.CreateGEP(print_struct,
|
||||
+ buf,
|
||||
+ { b_.getInt32(0), b_.getInt32(2) });
|
||||
b_.CREATE_MEMSET(content_offset, b_.getInt8(0), arg.type.GetSize(), 1);
|
||||
if (needMemcpy(arg.type))
|
||||
{
|
||||
@@ -3054,7 +3113,9 @@ void CodegenLLVM::readDatastructElemFromStack(Value *src_data,
|
||||
src_data = b_.CreateIntToPtr(src_data,
|
||||
b_.GetType(data_type)->getPointerTo());
|
||||
|
||||
- Value *src = b_.CreateGEP(src_data, { b_.getInt32(0), index });
|
||||
+ Value *src = b_.CreateGEP(b_.GetType(data_type),
|
||||
+ src_data,
|
||||
+ { b_.getInt32(0), index });
|
||||
|
||||
// It may happen that the result pointer type is not correct, in such case
|
||||
// do a typecast
|
||||
@@ -3065,7 +3126,7 @@ void CodegenLLVM::readDatastructElemFromStack(Value *src_data,
|
||||
if (elem_type.IsIntegerTy() || elem_type.IsPtrTy())
|
||||
{
|
||||
// Load the correct type from src
|
||||
- expr_ = b_.CreateLoad(src, true);
|
||||
+ expr_ = b_.CreateLoad(b_.GetType(elem_type), src, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3119,7 +3180,8 @@ void CodegenLLVM::probereadDatastructElem(Value *src_data,
|
||||
// Read data onto stack
|
||||
if (data_type.IsCtxAccess())
|
||||
{
|
||||
- expr_ = b_.CreateLoad(b_.CreateIntToPtr(src, dst_type->getPointerTo()),
|
||||
+ expr_ = b_.CreateLoad(dst_type,
|
||||
+ b_.CreateIntToPtr(src, dst_type->getPointerTo()),
|
||||
true);
|
||||
expr_ = b_.CreateIntCast(expr_, b_.getInt64Ty(), elem_type.IsSigned());
|
||||
|
||||
@@ -3150,7 +3212,7 @@ void CodegenLLVM::probereadDatastructElem(Value *src_data,
|
||||
AllocaInst *dst = b_.CreateAllocaBPF(elem_type, temp_name);
|
||||
b_.CreateProbeRead(
|
||||
ctx_, dst, elem_type.GetSize(), src, data_type.GetAS(), loc);
|
||||
- expr_ = b_.CreateIntCast(b_.CreateLoad(dst),
|
||||
+ expr_ = b_.CreateIntCast(b_.CreateLoad(b_.GetType(elem_type), dst),
|
||||
b_.getInt64Ty(),
|
||||
elem_type.IsSigned());
|
||||
b_.CreateLifetimeEnd(dst);
|
||||
@@ -3181,13 +3243,15 @@ void CodegenLLVM::createIncDec(Unop &unop)
|
||||
if (unop.is_post_op)
|
||||
expr_ = oldval;
|
||||
else
|
||||
- expr_ = b_.CreateLoad(newval);
|
||||
+ expr_ = b_.CreateLoad(b_.GetType(map.type), newval);
|
||||
b_.CreateLifetimeEnd(newval);
|
||||
}
|
||||
else if (unop.expr->is_variable)
|
||||
{
|
||||
Variable &var = static_cast<Variable &>(*unop.expr);
|
||||
- Value *oldval = b_.CreateLoad(variables_[var.ident]);
|
||||
+ Value *oldval = b_.CreateLoad(
|
||||
+ variables_[var.ident]->getType()->getElementType(),
|
||||
+ variables_[var.ident]);
|
||||
Value *newval;
|
||||
if (is_increment)
|
||||
newval = b_.CreateAdd(oldval, b_.GetIntSameSize(step, oldval));
|
||||
--
|
||||
2.35.1
|
||||
|
@ -1,39 +0,0 @@
|
||||
From fa6aae141fd95205b0b375b48364b1aa0050ebcd Mon Sep 17 00:00:00 2001
|
||||
From: Jerome Marchand <jmarchan@redhat.com>
|
||||
Date: Wed, 23 Mar 2022 09:47:25 +0100
|
||||
Subject: [PATCH] Fix libbtf 0.6.0 build
|
||||
|
||||
Libbtf 0.6.0 introduced a new version of btf_dump__new(). The new
|
||||
version is btf_dump__new_v0_6_0() while the old version was renamed
|
||||
btf_dump__new_deprecated(). btf_dump__new() is now overloaded,
|
||||
unfortunately the macro doesn't work on cpp, at least with LLVM 12.
|
||||
Let's call btf_dump__new_deprecated() explicitely when it's defined.
|
||||
|
||||
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
|
||||
---
|
||||
src/btf.cpp | 9 +++++++++
|
||||
1 file changed, 9 insertions(+)
|
||||
|
||||
diff --git a/src/btf.cpp b/src/btf.cpp
|
||||
index 7d83cf68..83bc6e90 100644
|
||||
--- a/src/btf.cpp
|
||||
+++ b/src/btf.cpp
|
||||
@@ -24,6 +24,15 @@
|
||||
#pragma GCC diagnostic pop
|
||||
#include <bpf/libbpf.h>
|
||||
|
||||
+/*
|
||||
+ * Since libbtf 0.6, btf_dump__new() has been overloaded and now can design
|
||||
+ * either btf_dump__new_v0_6_0() or btf_dump__new_deprecated(), which is the
|
||||
+ * same as btf_dump__new() for libbtf < 0.6, and the one we still use.
|
||||
+ */
|
||||
+#if LIBBPF_MAJOR_VERSION == 0 && LIBBPF_MINOR_VERSION >= 6
|
||||
+#define btf_dump__new(a1, a2, a3, a4) btf_dump__new_deprecated(a1, a2, a3, a4)
|
||||
+#endif
|
||||
+
|
||||
#include "bpftrace.h"
|
||||
|
||||
namespace bpftrace {
|
||||
--
|
||||
2.35.1
|
||||
|
@ -1,78 +0,0 @@
|
||||
From 80cd4a0fb0612249519001280a7913e026499e64 Mon Sep 17 00:00:00 2001
|
||||
From: Viktor Malik <viktor.malik@gmail.com>
|
||||
Date: Mon, 17 Jan 2022 11:15:26 +0100
|
||||
Subject: [PATCH] Update bio* tools to work on kernel 5.16+
|
||||
|
||||
Kernel 5.16 contains commit:
|
||||
|
||||
https://github.com/torvalds/linux/commit/be6bfe36db1795babe9d92178a47b2e02193cb0f
|
||||
|
||||
which renamed some of the functions that the bio* tools attach to.
|
||||
---
|
||||
tools/biolatency.bt | 6 ++++--
|
||||
tools/biosnoop.bt | 6 ++++--
|
||||
tools/biostacks.bt | 3 ++-
|
||||
3 files changed, 10 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/tools/biolatency.bt b/tools/biolatency.bt
|
||||
index 4ea910b4..d5af1f29 100755
|
||||
--- a/tools/biolatency.bt
|
||||
+++ b/tools/biolatency.bt
|
||||
@@ -16,12 +16,14 @@ BEGIN
|
||||
printf("Tracing block device I/O... Hit Ctrl-C to end.\n");
|
||||
}
|
||||
|
||||
-kprobe:blk_account_io_start
|
||||
+kprobe:blk_account_io_start,
|
||||
+kprobe:__blk_account_io_start
|
||||
{
|
||||
@start[arg0] = nsecs;
|
||||
}
|
||||
|
||||
-kprobe:blk_account_io_done
|
||||
+kprobe:blk_account_io_done,
|
||||
+kprobe:__blk_account_io_done
|
||||
/@start[arg0]/
|
||||
{
|
||||
@usecs = hist((nsecs - @start[arg0]) / 1000);
|
||||
diff --git a/tools/biosnoop.bt b/tools/biosnoop.bt
|
||||
index 38ffeb52..aa88f4ba 100755
|
||||
--- a/tools/biosnoop.bt
|
||||
+++ b/tools/biosnoop.bt
|
||||
@@ -16,7 +16,8 @@ BEGIN
|
||||
printf("%-12s %-7s %-16s %-6s %7s\n", "TIME(ms)", "DISK", "COMM", "PID", "LAT(ms)");
|
||||
}
|
||||
|
||||
-kprobe:blk_account_io_start
|
||||
+kprobe:blk_account_io_start,
|
||||
+kprobe:__blk_account_io_start
|
||||
{
|
||||
@start[arg0] = nsecs;
|
||||
@iopid[arg0] = pid;
|
||||
@@ -24,7 +25,8 @@ kprobe:blk_account_io_start
|
||||
@disk[arg0] = ((struct request *)arg0)->rq_disk->disk_name;
|
||||
}
|
||||
|
||||
-kprobe:blk_account_io_done
|
||||
+kprobe:blk_account_io_done,
|
||||
+kprobe:__blk_account_io_done
|
||||
/@start[arg0] != 0 && @iopid[arg0] != 0 && @iocomm[arg0] != ""/
|
||||
|
||||
{
|
||||
diff --git a/tools/biostacks.bt b/tools/biostacks.bt
|
||||
index 58201cdf..1bc9f819 100755
|
||||
--- a/tools/biostacks.bt
|
||||
+++ b/tools/biostacks.bt
|
||||
@@ -18,7 +18,8 @@ BEGIN
|
||||
printf("Tracing block I/O with init stacks. Hit Ctrl-C to end.\n");
|
||||
}
|
||||
|
||||
-kprobe:blk_account_io_start
|
||||
+kprobe:blk_account_io_start,
|
||||
+kprobe:__blk_account_io_start
|
||||
{
|
||||
@reqstack[arg0] = kstack;
|
||||
@reqts[arg0] = nsecs;
|
||||
--
|
||||
2.35.1
|
||||
|
@ -1,14 +1,11 @@
|
||||
Name: bpftrace
|
||||
Version: 0.14.1
|
||||
Version: 0.15.0
|
||||
Release: 1%{?dist}
|
||||
Summary: High-level tracing language for Linux eBPF
|
||||
License: ASL 2.0
|
||||
|
||||
URL: https://github.com/iovisor/bpftrace
|
||||
Source0: %{url}/archive/v%{version}/%{name}-%{version}.tar.gz
|
||||
Patch0: Fix-libbtf-0.6.0-build.patch
|
||||
Patch1: Fix-LLVM-13-warnings.patch
|
||||
Patch2: Update-bio-tools-to-work-on-kernel-5.16.patch
|
||||
|
||||
# Arches will be included as upstream support is added and dependencies are
|
||||
# satisfied in the respective arches
|
||||
@ -73,14 +70,19 @@ find %{buildroot}%{_datadir}/%{name}/tools -type f -exec \
|
||||
%dir %{_datadir}/%{name}
|
||||
%dir %{_datadir}/%{name}/tools
|
||||
%dir %{_datadir}/%{name}/tools/doc
|
||||
%dir %{_datadir}/%{name}/tools/old
|
||||
%{_bindir}/%{name}
|
||||
%{_bindir}/%{name}-aotrt
|
||||
%{_mandir}/man8/*
|
||||
%attr(0755,-,-) %{_datadir}/%{name}/tools/*.bt
|
||||
%attr(0755,-,-) %{_datadir}/%{name}/tools/old/*.bt
|
||||
%{_datadir}/%{name}/tools/doc/*.txt
|
||||
|
||||
|
||||
%changelog
|
||||
* Tue Jul 05 2022 Augusto Caringi <acaringi@redhat.com> - 0.15.0-1
|
||||
- Rebased to version 0.15.0
|
||||
|
||||
* Tue Apr 19 2022 Jerome Marchand <jmarchan@redhat.com> - 0.14.1-1
|
||||
- Rebased to version 0.14.1
|
||||
- Fix cmake build
|
||||
|
2
sources
2
sources
@ -1 +1 @@
|
||||
SHA512 (bpftrace-0.14.1.tar.gz) = 0be06c209ba12f70a0d1140b168dac94945c1b034dbd0c7dae5460fca43eec10bb436e28c122ec37b259256bf6b9bb23a3c5e7f8435feb67eae1b9277debaf73
|
||||
SHA512 (bpftrace-0.15.0.tar.gz) = 916e9afeab301e62472e570ef77a3b9b27b43251880b64f1c5f151583c59a6c61e9ede50f3607044b27c5a6ce1a654f290153bf3f9237ebc0a823b5e6356187a
|
||||
|
Loading…
Reference in New Issue
Block a user