On Wed, Jul 24, 2019 at 12:28 PM Andrii Nakryiko <andriin@xxxxxx> wrote: > > Add support for BPF CO-RE offset relocations. Add section/record > iteration macros for .BTF.ext. These macro are useful for iterating over > each .BTF.ext record, either for dumping out contents or later for BPF > CO-RE relocation handling. > > To enable other parts of libbpf to work with .BTF.ext contents, moved > a bunch of type definitions into libbpf_internal.h. > > Signed-off-by: Andrii Nakryiko <andriin@xxxxxx> > --- [...] > + * > + * Example to provide a better feel. > + * > + * struct sample { > + * int a; > + * struct { > + * int b[10]; > + * }; > + * }; > + * > + * struct sample *s = ...; > + * int x = &s->a; // encoded as "0:0" (a is field #0) > + * int y = &s->b[5]; // encoded as "0:1:5" (b is field #1, arr elem #5) This should be "0:1:0:5", actually. Anon struct is field #1 in BTF, b is field #0 inside that anon struct + array index 5. Will update it locally and incorporate into next version once the rest of patch set is reviewed. > + * int z = &s[10]->b; // encoded as "10:1" (ptr is used as an array) > + * > + * type_id for all relocs in this example will capture BTF type id of > + * `struct sample`. > + * > + * [0] https://llvm.org/docs/LangRef.html#getelementptr-instruction > + */ > +struct bpf_offset_reloc { > + __u32 insn_off; > + __u32 type_id; > + __u32 access_str_off; > +}; > + > #endif /* __LIBBPF_LIBBPF_INTERNAL_H */ > -- > 2.17.1 >