Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid LLVM IR in join builtin #2296

Merged

Conversation

lenticularis39
Copy link
Contributor

@lenticularis39 lenticularis39 commented Jul 12, 2022

Add pointer casts to store instruction where required and use GEP
instructions to do pointer arithmetic instead of incorrect use of
add instruction.

Fixes #2222

Checklist
  • Language changes are updated in man/adoc/bpftrace.adoc and if needed in docs/reference_guide.md
  • User-visible and non-trivial changes updated in CHANGELOG.md
  • The new behaviour is covered by tests

@lenticularis39 lenticularis39 force-pushed the fix-join-invalid-llvm-ir branch from 447b36c to a5870b7 Compare July 12, 2022 08:21
Copy link
Contributor

@viktormalik viktormalik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! CI now has tests for LLVM 14 where the join tests (and one other test) are disabled. Could you please enable them and make sure that they pass?

@lenticularis39
Copy link
Contributor Author

I see, didn't know that, I'll add that to the commit to test that properly :)

@lenticularis39 lenticularis39 changed the title Fix invalid LLVM IR in join helper Fix invalid LLVM IR in join builtin Jul 12, 2022
@lenticularis39 lenticularis39 force-pushed the fix-join-invalid-llvm-ir branch from a5870b7 to a020b15 Compare July 12, 2022 08:24
@@ -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,intptrcast.Casting ints,json-output.join_delim,variable.32-bit tracepoint arg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also intptrcast.Casting ints,json-output.join_delim,variable.32-bit tracepoint arg are newly failing on LLVM 14.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll try to remove these, too, to see if they work now.

@lenticularis39 lenticularis39 force-pushed the fix-join-invalid-llvm-ir branch from a020b15 to a633f84 Compare July 12, 2022 08:33
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
@lenticularis39 lenticularis39 force-pushed the fix-join-invalid-llvm-ir branch from a633f84 to 21eb463 Compare July 12, 2022 08:58
@lenticularis39
Copy link
Contributor Author

Unrelated tests (intptrcast.Casting ints,variable.32-bit tracepoint arg) still failing, I put them back into the disable list.

@viktormalik
Copy link
Contributor

Unrelated tests (intptrcast.Casting ints,variable.32-bit tracepoint arg) still failing, I put them back into the disable list.

Could these be caused by an issue similar to this one?

@lenticularis39
Copy link
Contributor Author

It's highly probable, opt reports an invalid cast for the first one and an invalid store for the second one.

@viktormalik
Copy link
Contributor

It's highly probable, opt reports an invalid cast for the first one and an invalid store for the second one.

Any chance you'd be able to fix it as a part of this PR?

Copy link
Member

@fbs fbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@fbs
Copy link
Member

fbs commented Jul 12, 2022

Lets get this merged asap.

For future work it would be nice to:

have a codegen test that covers this, that way the llvm-as check will find issues like these. ALthough if we managed to just validate everything the codegen test becomes useless anyway.

I wonder if the code becomes better if we convert the current monster into a AsyncEvent::Join.

int value_size = 8 + 8 + bpftrace.join_argnum_ * bpftrace.join_argsize_;
auto map = std::make_unique<T>(
    "join", BPF_MAP_TYPE_PERCPU_ARRAY, 4, value_size, 1, 0);

If instead we had:

struct Watchpoint
{
  uint64_t action_id;
  uint64_t join_id;
  uint8_t data;

  std::vector<llvm::Type*> asLLVMType(ast::IRBuilderBPF& b);
} __attribute__((packed));

we could just use geps in a logical way to access elements instead of all the inline pointer casts.

But thats all for future work :)

Copy link
Contributor

@viktormalik viktormalik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, let's merge this.

@viktormalik viktormalik merged commit 15624fe into bpftrace:master Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Join broken by LLVM 14
3 participants