[PATCH] D155894: [BPF] allow external calls

Alessandro Decina via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 2 09:53:04 PDT 2023


alessandrod added a comment.

In D155894#4545019 <https://reviews.llvm.org/D155894#4545019>, @ast wrote:

> In D155894#4544080 <https://reviews.llvm.org/D155894#4544080>, @alessandrod wrote:
>
>> We're ignoring the error because the error is in fact not an error, the target is doing the right thing, and aya (well, rustc) always provides memory builtins so memset gets linked correctly and a valid program is produced.
>
> Could you point to memset implementation that gets linked eventually?

Normally in rust programs, memory builtins are provided by the compiler-builtins crate, which is the equivalent of compiler-rt in LLVM. It's automatically linked in by the compiler to provide libcalls used by LLVM. This is the code https://github.com/rust-lang/compiler-builtins/blob/efd227f9c2ac220a8699188e937eb8be810df317/src/mem/mod.rs#L46. As you see it returns the dst pointer, which breaks the verifier if it's used on stack pointers (which is something rustc sometimes does when initializing stack values). So we have an override in aya that is pretty much the same but returns void.

> Is it a global function or static ? Asking because they're verified differently by the kernel.
> I have a hard time imagining a generic implementation that can pass the verifier.

I am aware - it's a static so it works. And also the bounds for the inputs are statically known in all the cases where rustc uses memset internally (eg to zero initialize values with a fixed known type layout). The usual bound checks are required when calling something like https://doc.rust-lang.org/stable/std/primitive.slice.html#method.copy_from_slice.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155894/new/

https://reviews.llvm.org/D155894



More information about the llvm-commits mailing list