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