Skip to content

Commit

Permalink
Fix invalid LLVM IR in join builtin
Browse files Browse the repository at this point in the history
Add pointer casts to store instruction where required and use GEP
instructions to do pointer arithmetic instead of incorrect use of
add instruction.

Fixes bpftrace#2222
  • Loading branch information
lenticularis39 committed Jul 12, 2022
1 parent dc01a88 commit a633f84
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
TYPE: Release
LLVM_VERSION: 14
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: probe.kprobe_offset_fail_size,call.join,call.join_delim,intptrcast.Casting ints,json-output.join_delim,variable.32-bit tracepoint arg
RUNTIME_TEST_DISABLE: probe.kprobe_offset_fail_size
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: focal
VENDOR_GTEST: ON
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ and this project adheres to
- [#2236](https://github.com/iovisor/bpftrace/pull/2236)
- Fix compound assignments with non-unary expr
- [#2291](https://github.com/iovisor/bpftrace/pull/2293)
- Fix invalid LLVM IR in join builtin
- [#2296](https://github.com/iovisor/bpftrace/pull/2296)

#### Added
#### Docs
Expand Down
24 changes: 15 additions & 9 deletions src/ast/passes/codegen_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,18 +669,23 @@ void CodegenLLVM::visit(Call &call)

// arg0
b_.SetInsertPoint(notzero);
b_.CreateStore(b_.getInt64(asyncactionint(AsyncAction::join)), perfdata);
b_.CreateStore(b_.getInt64(asyncactionint(AsyncAction::join)),
b_.CreatePointerCast(perfdata,
b_.getInt64Ty()->getPointerTo()));
b_.CreateStore(b_.getInt64(join_id_),
b_.CreateGEP(b_.getInt8Ty(), perfdata, b_.getInt64(8)));
b_.CreatePointerCast(
b_.CreateGEP(b_.getInt8Ty(), perfdata, b_.getInt64(8)),
b_.getInt64Ty()->getPointerTo()));
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(b_.getInt64Ty(), arr),
addrspace,
call.loc);
b_.CreateProbeReadStr(
ctx_,
b_.CreateGEP(b_.getInt8Ty(), perfdata, b_.getInt64(8 + 8)),
bpftrace_.join_argsize_,
b_.CreateLoad(b_.getInt64Ty(), arr),
addrspace,
call.loc);

for (unsigned int i = 1; i < bpftrace_.join_argnum_; i++)
{
Expand All @@ -694,7 +699,8 @@ void CodegenLLVM::visit(Call &call)
call.loc);
b_.CreateProbeReadStr(
ctx_,
b_.CreateAdd(perfdata,
b_.CreateGEP(b_.getInt8Ty(),
perfdata,
b_.getInt64(8 + 8 + i * bpftrace_.join_argsize_)),
bpftrace_.join_argsize_,
b_.CreateLoad(b_.getInt64Ty(), second),
Expand Down

0 comments on commit a633f84

Please sign in to comment.