workarounds.go 659 B

1234567891011121314151617181920212223242526
  1. package btf
  2. // datasecResolveWorkaround ensures that certain vars in a Datasec are added
  3. // to a Spec before the Datasec. This avoids a bug in kernel BTF validation.
  4. //
  5. // See https://lore.kernel.org/bpf/20230302123440.1193507-1-lmb@isovalent.com/
  6. func datasecResolveWorkaround(b *Builder, ds *Datasec) error {
  7. for _, vsi := range ds.Vars {
  8. v, ok := vsi.Type.(*Var)
  9. if !ok {
  10. continue
  11. }
  12. switch v.Type.(type) {
  13. case *Typedef, *Volatile, *Const, *Restrict, *typeTag:
  14. // NB: We must never call Add on a Datasec, otherwise we risk
  15. // infinite recursion.
  16. _, err := b.Add(v.Type)
  17. if err != nil {
  18. return err
  19. }
  20. }
  21. }
  22. return nil
  23. }