ebpf icon indicating copy to clipboard operation
ebpf copied to clipboard

bpf2go: __int128 is converted into invalid uint128 Go type

Open Benjmmi opened this issue 2 years ago • 7 comments

Describe the bug When using c unsigned __int128 saddr; in ebpf, it was escaping golang's uint128 which was obviously incorrect, so added to convert it to [16]byte or [16]uint8 instead .... may be slove this issue

Benjmmi avatar Sep 08 '22 02:09 Benjmmi

There is an open proposal for Go to support types like uint128 in https://github.com/golang/go/issues/9455. But so far native Go doesn't support uint128.

Was an external package used that tries to implement Go support for uint128?

florianl avatar Sep 08 '22 07:09 florianl

i try ...

Benjmmi avatar Sep 09 '22 00:09 Benjmmi

I've tried using "num" and it seems to solve the problem, but should we refer to this code to implement it

Benjmmi avatar Sep 11 '22 13:09 Benjmmi

Not the most ergonomic solution, but I think we should emit [16]byte instead of forcing a specific dependency. Users can add a getter to the generated type that calls a constructor for their favourite package.

lmb avatar Sep 11 '22 15:09 lmb

I think it might be a bit overwhelming to just throw "[16]byte" at the user.

So we should refer to the calculation of "int128" and "uint128". Implement the solution "type uint128 [16]byte". Is that right?

Benjmmi avatar Sep 12 '22 04:09 Benjmmi

Implement the solution "type uint128 [16]byte". Is that right?

That creates complications, because there might be multiple bpf2go generated files in the same package. With the naive approach you end up with multiple type uint128. I'd skip the type, but you can add a comment to the generated output like in https://github.com/cilium/ebpf/blob/2ca994b15145cd3529a39cea90c7db4b3a7c3b89/btf/format.go#L197

Final output:

type foo struct {
    big [16]byte /* uint128 */
}

lmb avatar Sep 15 '22 11:09 lmb

SGTM

Benjmmi avatar Sep 18 '22 14:09 Benjmmi

I think this should be fixed now!

lmb avatar Oct 13 '22 10:10 lmb