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

bpf: Remove builtin global functions #698

Closed
wants to merge 1 commit into from
Closed

Conversation

tamird
Copy link
Member

@tamird tamird commented Jul 27, 2023

This commit removes memset and memcpy, relying instead on
implementations provided by std/compiler-builtins.

This commit adds #![no_builtins] to all the BPF programs written in
Rust, and the same should be propagated to aya-template and all examples
in the book and elsewhere before this commit is merged.

It turns out that without the #![no_builtins] annotation rustc
generates LLVM IR that calls LLVM intrinsics rather than libcalls. These
may end up as libcalls after lowering, but not before emitting errors in
BPF lowering[0].

This works thanks to rust-lang/rust#113716 which
causes #![no_builtins] to behave similarly to -fno-builtin in clang,
which was added in https://reviews.llvm.org/D68028 with similar
motivation.

This commit implies that we now require rustc nightly >= 2023-07-20.

[0] https://github.com/llvm/llvm-project/blob/7b2745b/llvm/lib/Target/BPF/BPFISelLowering.cpp#L472-L474

@netlify
Copy link

netlify bot commented Jul 27, 2023

Deploy Preview for aya-rs-docs ready!

Name Link
🔨 Latest commit e9a099f
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/654a582c176e6c000814e4e4
😎 Deploy Preview https://deploy-preview-698--aya-rs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@tamird tamird force-pushed the remove-compiler-builtins branch from 8234717 to 08bced8 Compare July 27, 2023 23:01
tamird added a commit to aya-rs/bpf-linker that referenced this pull request Jul 27, 2023
Add #![no_builtins] to all test programs; see
aya-rs/aya#698 for rationale.
tamird added a commit to aya-rs/bpf-linker that referenced this pull request Jul 27, 2023
Add #![no_builtins] to all test programs; see
aya-rs/aya#698 for rationale.
tamird added a commit to aya-rs/book that referenced this pull request Jul 27, 2023
tamird added a commit to aya-rs/aya-template that referenced this pull request Jul 27, 2023
@alessandrod
Copy link
Collaborator

The compiler-builtins fallbacks don't pass the verifier, which is why we provide our own

@tamird
Copy link
Member Author

tamird commented Jul 28, 2023

I don't think that's correct; if it were, the integration tests would fail here.

tamird added a commit to aya-rs/bpf-linker that referenced this pull request Jul 28, 2023
Ignore errors emitted on calls to builtins which are spurious. These
builtins end up being lowered to libcalls to hidden functions, which are
totally OK. See https://reviews.llvm.org/D155894 and
aya-rs/aya#698 for some additional discussion.

There doesn't seem to be a silver bullet here; BPF is fundamentally
adversarial to these memory intrinsics. We can revisit this once we have
DI and can more easily locate the source location that results in their
inclusion.
tamird added a commit to davibe/bpf-linker that referenced this pull request Jul 28, 2023
Add #![no_builtins] to all test programs; see
aya-rs/aya#698 for rationale.
tamird added a commit to davibe/bpf-linker that referenced this pull request Jul 28, 2023
Add #![no_builtins] to all test programs; see
aya-rs/aya#698 for rationale.
@alessandrod
Copy link
Collaborator

We've discussed this on discord, the tests are passing because of inlining. Can we close?

@tamird
Copy link
Member Author

tamird commented Jul 29, 2023

I'd still like to write better tests, marking as draft if that's ok.

@tamird tamird marked this pull request as draft July 29, 2023 02:44
tamird added a commit to aya-rs/book that referenced this pull request Aug 1, 2023
tamird added a commit to aya-rs/aya-template that referenced this pull request Aug 1, 2023
@mergify mergify bot added aya-bpf This is about aya-bpf (kernel) test A PR that improves test cases or CI labels Sep 14, 2023
@mergify
Copy link

mergify bot commented Sep 27, 2023

@tamird, this pull request is now in conflict and requires a rebase.

@mergify mergify bot added the needs-rebase label Sep 27, 2023
This commit removes memset and memcpy, relying instead on
implementations provided by std/compiler-builtins.

This commit adds `#![no_builtins]` to all the BPF programs written in
Rust, and the same should be propagated to aya-template and all examples
in the book and elsewhere before this commit is merged.

It turns out that without the `#![no_builtins]` annotation rustc
generates LLVM IR that calls LLVM intrinsics rather than libcalls. These
may end up as libcalls after lowering, but not before emitting errors in
BPF lowering[0].

This works thanks to rust-lang/rust#113716 which
causes `#![no_builtins]` to behave similarly to `-fno-builtin` in clang,
which was added in https://reviews.llvm.org/D68028 with similar
motivation.

This commit implies that we now require rustc nightly >= 2023-07-20.

[0] https://github.com/llvm/llvm-project/blob/7b2745b/llvm/lib/Target/BPF/BPFISelLowering.cpp#L472-L474
@tamird tamird force-pushed the remove-compiler-builtins branch from 08bced8 to e9a099f Compare November 7, 2023 15:30
tamird added a commit to aya-rs/aya-template that referenced this pull request Nov 7, 2023
@mergify mergify bot removed the needs-rebase label Nov 7, 2023
tamird added a commit to aya-rs/book that referenced this pull request Nov 7, 2023
@tamird tamird closed this Jan 8, 2024
@tamird tamird deleted the remove-compiler-builtins branch January 8, 2024 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aya-bpf This is about aya-bpf (kernel) test A PR that improves test cases or CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants