yonghong-song wrote:

> @yonghong-song The goal isn't full C++ support in BPF. It's that C++ code 
> which already compiles for BPF doesn't crash the backend, doesn't get 
> silently wrong CO-RE offsets, and produces BTF the kernel accepts. Alexei's 
> C++ example with exceptions is the kind of code I have in mind. Planned 
> steps, in this order:
> 
>     1. The combined [[BPF] Handle C++ record elements in BTF and CO-RE 
> #226717](https://github.com/llvm/llvm-project/pull/226717) + [[BPF] Treat 
> class records as structs in BTF and CO-RE 
> #226723](https://github.com/llvm/llvm-project/pull/226723). Since 22.1.0, any 
> C++ record with a method, base or static member, and any `class`, hits 
> UNREACHABLE in BTFDebug with `-g`. CO-RE on such records was wrong even 
> before: for `struct S : Base { int x, y; }`, `&s->y` got `x`'s offset (4 
> instead of 8) since at least clang 19, and `class` got offset 0. With this, 
> BTF for these records loads on 6.12, where clang 19's was rejected.

This is related to CO-RE and we should handle this first. This is the followup 
for #226790.

> 
>     2. sret and by-reference args in BTF FUNC_PROTO. A global function 
> returning a record over 16 bytes has an sret pointer as its first arg, but 
> BTF shows the source signature, so the verifier rejects it. The PR names the 
> sret param `__sret` and marks by-reference records with `arg:nonnull`; kfunc 
> externs keep the source prototype.

Such a case should be really rare. Currently bpf does not support it. I 
remembered I did some accounting for kernel functions. The kernel functions 
roughtly ~65000 functions, and the number of functions having either return 
value or argument value is less than 100. So it should be rare. This can be a 
separate discussion in llvm and kernel side.

> 
>     3. Escaping invalid characters in BTF names (template names like 
> `Box<int>`, `_vptr$X`), which the kernel rejects today, using bpf-linker's 
> scheme.

>From user's perspective, the name should be the same as in the source...

> 
>     4. ABI: passing and returning C++ records over 16 bytes and non-trivial 
> records by reference, as the C++ ABI requires. With the current ABI, a 
> non-trivial argument gets destroyed twice and a returned record with a 
> self-pointer breaks; the verifier can't see either. `-fclang-abi-compat=23` 
> keeps the old behavior. This builds on your bpf-next changes for struct args 
> and returns up to 16 bytes.

Since this is for bpf programs, the ABI should follow bpf calling convention. I 
am not sure whether we need to expand bpf calling convention for c++.

> 
> 
> Steps 2 and 3 are ready, and step 4 depends on 2. I've tested them on 6.12 
> and bpf-next 7.3-rc2. For the ABI change, would you prefer a PR or an RFC on 
> Discourse first? Once you're fine with the plan, I'll combine #226717 and 
> #226723 into a new PR.

We should finish item 1 first. The rest of them about names and '> 16' 
arguments or return values can be next.

https://github.com/llvm/llvm-project/pull/226790
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to